1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package ssm
4
5import (
6	"context"
7	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
8	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
9	"github.com/aws/aws-sdk-go-v2/service/ssm/types"
10	"github.com/aws/smithy-go/middleware"
11	smithyhttp "github.com/aws/smithy-go/transport/http"
12)
13
14// A State Manager association defines the state that you want to maintain on your
15// instances. For example, an association can specify that anti-virus software must
16// be installed and running on your instances, or that certain ports must be
17// closed. For static targets, the association specifies a schedule for when the
18// configuration is reapplied. For dynamic targets, such as an Amazon Web Services
19// resource group or an Amazon Web Services autoscaling group, State Manager, a
20// capability of Amazon Web Services Systems Manager applies the configuration when
21// new instances are added to the group. The association also specifies actions to
22// take when applying the configuration. For example, an association for anti-virus
23// software might run once a day. If the software isn't installed, then State
24// Manager installs it. If the software is installed, but the service isn't
25// running, then the association might instruct State Manager to start the service.
26func (c *Client) CreateAssociation(ctx context.Context, params *CreateAssociationInput, optFns ...func(*Options)) (*CreateAssociationOutput, error) {
27	if params == nil {
28		params = &CreateAssociationInput{}
29	}
30
31	result, metadata, err := c.invokeOperation(ctx, "CreateAssociation", params, optFns, c.addOperationCreateAssociationMiddlewares)
32	if err != nil {
33		return nil, err
34	}
35
36	out := result.(*CreateAssociationOutput)
37	out.ResultMetadata = metadata
38	return out, nil
39}
40
41type CreateAssociationInput struct {
42
43	// The name of the SSM Command document or Automation runbook that contains the
44	// configuration information for the instance. You can specify Amazon Web
45	// Services-predefined documents, documents you created, or a document that is
46	// shared with you from another account. For Systems Manager documents (SSM
47	// documents) that are shared with you from other Amazon Web Services accounts, you
48	// must specify the complete SSM document ARN, in the following format:
49	// arn:partition:ssm:region:account-id:document/document-name  For example:
50	// arn:aws:ssm:us-east-2:12345678912:document/My-Shared-Document For Amazon Web
51	// Services-predefined documents and SSM documents you created in your account, you
52	// only need to specify the document name. For example, AWS-ApplyPatchBaseline or
53	// My-Document.
54	//
55	// This member is required.
56	Name *string
57
58	// By default, when you create a new association, the system runs it immediately
59	// after it is created and then according to the schedule you specified. Specify
60	// this option if you don't want an association to run immediately after you create
61	// it. This parameter isn't supported for rate expressions.
62	ApplyOnlyAtCronInterval bool
63
64	// Specify a descriptive name for the association.
65	AssociationName *string
66
67	// Specify the target for the association. This target is required for associations
68	// that use an Automation runbook and target resources by using rate controls.
69	// Automation is a capability of Amazon Web Services Systems Manager.
70	AutomationTargetParameterName *string
71
72	// The names or Amazon Resource Names (ARNs) of the Change Calendar type documents
73	// you want to gate your associations under. The associations only run when that
74	// change calendar is open. For more information, see Amazon Web Services Systems
75	// Manager Change Calendar
76	// (https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-change-calendar).
77	CalendarNames []string
78
79	// The severity level to assign to the association.
80	ComplianceSeverity types.AssociationComplianceSeverity
81
82	// The document version you want to associate with the target(s). Can be a specific
83	// version or the default version.
84	DocumentVersion *string
85
86	// The instance ID. InstanceId has been deprecated. To specify an instance ID for
87	// an association, use the Targets parameter. Requests that include the parameter
88	// InstanceID with Systems Manager documents (SSM documents) that use schema
89	// version 2.0 or later will fail. In addition, if you use the parameter
90	// InstanceId, you can't use the parameters AssociationName, DocumentVersion,
91	// MaxErrors, MaxConcurrency, OutputLocation, or ScheduleExpression. To use these
92	// parameters, you must use the Targets parameter.
93	InstanceId *string
94
95	// The maximum number of targets allowed to run the association at the same time.
96	// You can specify a number, for example 10, or a percentage of the target set, for
97	// example 10%. The default value is 100%, which means all targets run the
98	// association at the same time. If a new instance starts and attempts to run an
99	// association while Systems Manager is running MaxConcurrency associations, the
100	// association is allowed to run. During the next association interval, the new
101	// instance will process its association within the limit specified for
102	// MaxConcurrency.
103	MaxConcurrency *string
104
105	// The number of errors that are allowed before the system stops sending requests
106	// to run the association on additional targets. You can specify either an absolute
107	// number of errors, for example 10, or a percentage of the target set, for example
108	// 10%. If you specify 3, for example, the system stops sending requests when the
109	// fourth error is received. If you specify 0, then the system stops sending
110	// requests after the first error is returned. If you run an association on 50
111	// instances and set MaxError to 10%, then the system stops sending the request
112	// when the sixth error is received. Executions that are already running an
113	// association when MaxErrors is reached are allowed to complete, but some of these
114	// executions may fail as well. If you need to ensure that there won't be more than
115	// max-errors failed executions, set MaxConcurrency to 1 so that executions proceed
116	// one at a time.
117	MaxErrors *string
118
119	// An Amazon Simple Storage Service (Amazon S3) bucket where you want to store the
120	// output details of the request.
121	OutputLocation *types.InstanceAssociationOutputLocation
122
123	// The parameters for the runtime configuration of the document.
124	Parameters map[string][]string
125
126	// A cron expression when the association will be applied to the target(s).
127	ScheduleExpression *string
128
129	// The mode for generating association compliance. You can specify AUTO or MANUAL.
130	// In AUTO mode, the system uses the status of the association execution to
131	// determine the compliance status. If the association execution runs successfully,
132	// then the association is COMPLIANT. If the association execution doesn't run
133	// successfully, the association is NON-COMPLIANT. In MANUAL mode, you must specify
134	// the AssociationId as a parameter for the PutComplianceItems API operation. In
135	// this case, compliance data isn't managed by State Manager. It is managed by your
136	// direct call to the PutComplianceItems API operation. By default, all
137	// associations use AUTO mode.
138	SyncCompliance types.AssociationSyncCompliance
139
140	// A location is a combination of Amazon Web Services Regions and Amazon Web
141	// Services accounts where you want to run the association. Use this action to
142	// create an association in multiple Regions and multiple accounts.
143	TargetLocations []types.TargetLocation
144
145	// The targets for the association. You can target instances by using tags, Amazon
146	// Web Services resource groups, all instances in an Amazon Web Services account,
147	// or individual instance IDs. For more information about choosing targets for an
148	// association, see Using targets and rate controls with State Manager associations
149	// (https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-state-manager-targets-and-rate-controls.html)
150	// in the Amazon Web Services Systems Manager User Guide.
151	Targets []types.Target
152
153	noSmithyDocumentSerde
154}
155
156type CreateAssociationOutput struct {
157
158	// Information about the association.
159	AssociationDescription *types.AssociationDescription
160
161	// Metadata pertaining to the operation's result.
162	ResultMetadata middleware.Metadata
163
164	noSmithyDocumentSerde
165}
166
167func (c *Client) addOperationCreateAssociationMiddlewares(stack *middleware.Stack, options Options) (err error) {
168	err = stack.Serialize.Add(&awsAwsjson11_serializeOpCreateAssociation{}, middleware.After)
169	if err != nil {
170		return err
171	}
172	err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpCreateAssociation{}, middleware.After)
173	if err != nil {
174		return err
175	}
176	if err = addSetLoggerMiddleware(stack, options); err != nil {
177		return err
178	}
179	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
180		return err
181	}
182	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
183		return err
184	}
185	if err = addResolveEndpointMiddleware(stack, options); err != nil {
186		return err
187	}
188	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
189		return err
190	}
191	if err = addRetryMiddlewares(stack, options); err != nil {
192		return err
193	}
194	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
195		return err
196	}
197	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
198		return err
199	}
200	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
201		return err
202	}
203	if err = addClientUserAgent(stack); err != nil {
204		return err
205	}
206	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
207		return err
208	}
209	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
210		return err
211	}
212	if err = addOpCreateAssociationValidationMiddleware(stack); err != nil {
213		return err
214	}
215	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCreateAssociation(options.Region), middleware.Before); err != nil {
216		return err
217	}
218	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
219		return err
220	}
221	if err = addResponseErrorMiddleware(stack); err != nil {
222		return err
223	}
224	if err = addRequestResponseLogging(stack, options); err != nil {
225		return err
226	}
227	return nil
228}
229
230func newServiceMetadataMiddleware_opCreateAssociation(region string) *awsmiddleware.RegisterServiceMetadata {
231	return &awsmiddleware.RegisterServiceMetadata{
232		Region:        region,
233		ServiceID:     ServiceID,
234		SigningName:   "ssm",
235		OperationName: "CreateAssociation",
236	}
237}
238