/
appdelivery.go
410 lines (388 loc) · 15.4 KB
/
appdelivery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
package appdelivery
import (
_init_ "github.com/aws/aws-cdk-go/awscdk/jsii"
_jsii_ "github.com/aws/jsii-runtime-go/runtime"
"github.com/aws/aws-cdk-go/awscdk"
"github.com/aws/aws-cdk-go/awscdk/appdelivery/internal"
"github.com/aws/aws-cdk-go/awscdk/awscloudformation"
"github.com/aws/aws-cdk-go/awscdk/awscodepipeline"
"github.com/aws/aws-cdk-go/awscdk/awsevents"
"github.com/aws/aws-cdk-go/awscdk/awsiam"
)
// A class to deploy a stack that is part of a CDK App, using CodePipeline.
//
// This composite Action takes care of preparing and executing a CloudFormation ChangeSet.
//
// It currently does *not* support stacks that make use of ``Asset``s, and
// requires the deployed stack is in the same account and region where the
// CodePipeline is hosted.
//
// Example:
// // Example automatically generated from non-compiling source. May contain errors.
// import codebuild "github.com/aws/aws-cdk-go/awscdk"
// import codepipeline "github.com/aws/aws-cdk-go/awscdk"
// import codepipeline_actions "github.com/aws/aws-cdk-go/awscdk"
// import cdk "github.com/aws/aws-cdk-go/awscdk"
// import cicd "github.com/aws/aws-cdk-go/awscdk"
// import iam "github.com/aws/aws-cdk-go/awscdk"
//
//
// type myServiceStackA struct {
// stack
// }
// type myServiceStackB struct {
// stack
// }
//
// app := cdk.NewApp()
//
// // We define a stack that contains the CodePipeline
// pipelineStack := cdk.NewStack(app, jsii.String("PipelineStack"))
// pipeline := codepipeline.NewPipeline(pipelineStack, jsii.String("CodePipeline"), &pipelineProps{
// // Mutating a CodePipeline can cause the currently propagating state to be
// // "lost". Ensure we re-run the latest change through the pipeline after it's
// // been mutated so we're sure the latest state is fully deployed through.
// restartExecutionOnUpdate: jsii.Boolean(true),
// })
//
// // Configure the CodePipeline source - where your CDK App's source code is hosted
// sourceOutput := codepipeline.NewArtifact()
// source := codepipeline_actions.NewGitHubSourceAction(&gitHubSourceActionProps{
// actionName: jsii.String("GitHub"),
// output: sourceOutput,
// owner: jsii.String("myName"),
// repo: jsii.String("myRepo"),
// oauthToken: cdk.secretValue.unsafePlainText(jsii.String("secret")),
// })
// pipeline.addStage(&stageOptions{
// stageName: jsii.String("source"),
// actions: []iAction{
// source,
// },
// })
//
// project := codebuild.NewPipelineProject(pipelineStack, jsii.String("CodeBuild"), &pipelineProjectProps{
// })
// synthesizedApp := codepipeline.NewArtifact()
// buildAction := codepipeline_actions.NewCodeBuildAction(&codeBuildActionProps{
// actionName: jsii.String("CodeBuild"),
// project: project,
// input: sourceOutput,
// outputs: []artifact{
// synthesizedApp,
// },
// })
// pipeline.addStage(&stageOptions{
// stageName: jsii.String("build"),
// actions: []*iAction{
// buildAction,
// },
// })
//
// // Optionally, self-update the pipeline stack
// selfUpdateStage := pipeline.addStage(&stageOptions{
// stageName: jsii.String("SelfUpdate"),
// })
// selfUpdateStage.addAction(cicd.NewPipelineDeployStackAction(&pipelineDeployStackActionProps{
// stack: pipelineStack,
// input: synthesizedApp,
// adminPermissions: jsii.Boolean(true),
// }))
//
// // Now add our service stacks
// deployStage := pipeline.addStage(&stageOptions{
// stageName: jsii.String("Deploy"),
// })
// serviceStackA := NewMyServiceStackA(app, jsii.String("ServiceStackA"), &stackProps{
// })
// // Add actions to deploy the stacks in the deploy stage:
// deployServiceAAction := cicd.NewPipelineDeployStackAction(&pipelineDeployStackActionProps{
// stack: serviceStackA,
// input: synthesizedApp,
// // See the note below for details about this option.
// adminPermissions: jsii.Boolean(false),
// })
// deployStage.addAction(deployServiceAAction)
// // Add the necessary permissions for you service deploy action. This role is
// // is passed to CloudFormation and needs the permissions necessary to deploy
// // stack. Alternatively you can enable [Administrator](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_job-functions.html#jf_administrator) permissions above,
// // users should understand the privileged nature of this role.
// myResourceArn := "arn:partition:service:region:account-id:resource-id"
// deployServiceAAction.addToDeploymentRolePolicy(iam.NewPolicyStatement(&policyStatementProps{
// actions: []*string{
// jsii.String("service:SomeAction"),
// },
// resources: []*string{
// myResourceArn,
// },
// }))
//
// serviceStackB := NewMyServiceStackB(app, jsii.String("ServiceStackB"), &stackProps{
// })
// deployStage.addAction(cicd.NewPipelineDeployStackAction(&pipelineDeployStackActionProps{
// stack: serviceStackB,
// input: synthesizedApp,
// createChangeSetRunOrder: jsii.Number(998),
// adminPermissions: jsii.Boolean(true),
// }))
//
// Experimental.
type PipelineDeployStackAction interface {
awscodepipeline.IAction
// The simple properties of the Action, like its Owner, name, etc.
//
// Note that this accessor will be called before the {@link bind} callback.
// Experimental.
ActionProperties() *awscodepipeline.ActionProperties
// Experimental.
DeploymentRole() awsiam.IRole
// Add policy statements to the role deploying the stack.
//
// This role is passed to CloudFormation and must have the IAM permissions
// necessary to deploy the stack or you can grant this role `adminPermissions`
// by using that option during creation. If you do not grant
// `adminPermissions` you need to identify the proper statements to add to
// this role based on the CloudFormation Resources in your stack.
// Experimental.
AddToDeploymentRolePolicy(statement awsiam.PolicyStatement)
// The callback invoked when this Action is added to a Pipeline.
// Experimental.
Bind(scope awscdk.Construct, stage awscodepipeline.IStage, options *awscodepipeline.ActionBindOptions) *awscodepipeline.ActionConfig
// Creates an Event that will be triggered whenever the state of this Action changes.
// Experimental.
OnStateChange(name *string, target awsevents.IRuleTarget, options *awsevents.RuleProps) awsevents.Rule
}
// The jsii proxy struct for PipelineDeployStackAction
type jsiiProxy_PipelineDeployStackAction struct {
internal.Type__awscodepipelineIAction
}
func (j *jsiiProxy_PipelineDeployStackAction) ActionProperties() *awscodepipeline.ActionProperties {
var returns *awscodepipeline.ActionProperties
_jsii_.Get(
j,
"actionProperties",
&returns,
)
return returns
}
func (j *jsiiProxy_PipelineDeployStackAction) DeploymentRole() awsiam.IRole {
var returns awsiam.IRole
_jsii_.Get(
j,
"deploymentRole",
&returns,
)
return returns
}
// Experimental.
func NewPipelineDeployStackAction(props *PipelineDeployStackActionProps) PipelineDeployStackAction {
_init_.Initialize()
j := jsiiProxy_PipelineDeployStackAction{}
_jsii_.Create(
"monocdk.app_delivery.PipelineDeployStackAction",
[]interface{}{props},
&j,
)
return &j
}
// Experimental.
func NewPipelineDeployStackAction_Override(p PipelineDeployStackAction, props *PipelineDeployStackActionProps) {
_init_.Initialize()
_jsii_.Create(
"monocdk.app_delivery.PipelineDeployStackAction",
[]interface{}{props},
p,
)
}
func (p *jsiiProxy_PipelineDeployStackAction) AddToDeploymentRolePolicy(statement awsiam.PolicyStatement) {
_jsii_.InvokeVoid(
p,
"addToDeploymentRolePolicy",
[]interface{}{statement},
)
}
func (p *jsiiProxy_PipelineDeployStackAction) Bind(scope awscdk.Construct, stage awscodepipeline.IStage, options *awscodepipeline.ActionBindOptions) *awscodepipeline.ActionConfig {
var returns *awscodepipeline.ActionConfig
_jsii_.Invoke(
p,
"bind",
[]interface{}{scope, stage, options},
&returns,
)
return returns
}
func (p *jsiiProxy_PipelineDeployStackAction) OnStateChange(name *string, target awsevents.IRuleTarget, options *awsevents.RuleProps) awsevents.Rule {
var returns awsevents.Rule
_jsii_.Invoke(
p,
"onStateChange",
[]interface{}{name, target, options},
&returns,
)
return returns
}
// Example:
// // Example automatically generated from non-compiling source. May contain errors.
// import codebuild "github.com/aws/aws-cdk-go/awscdk"
// import codepipeline "github.com/aws/aws-cdk-go/awscdk"
// import codepipeline_actions "github.com/aws/aws-cdk-go/awscdk"
// import cdk "github.com/aws/aws-cdk-go/awscdk"
// import cicd "github.com/aws/aws-cdk-go/awscdk"
// import iam "github.com/aws/aws-cdk-go/awscdk"
//
//
// type myServiceStackA struct {
// stack
// }
// type myServiceStackB struct {
// stack
// }
//
// app := cdk.NewApp()
//
// // We define a stack that contains the CodePipeline
// pipelineStack := cdk.NewStack(app, jsii.String("PipelineStack"))
// pipeline := codepipeline.NewPipeline(pipelineStack, jsii.String("CodePipeline"), &pipelineProps{
// // Mutating a CodePipeline can cause the currently propagating state to be
// // "lost". Ensure we re-run the latest change through the pipeline after it's
// // been mutated so we're sure the latest state is fully deployed through.
// restartExecutionOnUpdate: jsii.Boolean(true),
// })
//
// // Configure the CodePipeline source - where your CDK App's source code is hosted
// sourceOutput := codepipeline.NewArtifact()
// source := codepipeline_actions.NewGitHubSourceAction(&gitHubSourceActionProps{
// actionName: jsii.String("GitHub"),
// output: sourceOutput,
// owner: jsii.String("myName"),
// repo: jsii.String("myRepo"),
// oauthToken: cdk.secretValue.unsafePlainText(jsii.String("secret")),
// })
// pipeline.addStage(&stageOptions{
// stageName: jsii.String("source"),
// actions: []iAction{
// source,
// },
// })
//
// project := codebuild.NewPipelineProject(pipelineStack, jsii.String("CodeBuild"), &pipelineProjectProps{
// })
// synthesizedApp := codepipeline.NewArtifact()
// buildAction := codepipeline_actions.NewCodeBuildAction(&codeBuildActionProps{
// actionName: jsii.String("CodeBuild"),
// project: project,
// input: sourceOutput,
// outputs: []artifact{
// synthesizedApp,
// },
// })
// pipeline.addStage(&stageOptions{
// stageName: jsii.String("build"),
// actions: []*iAction{
// buildAction,
// },
// })
//
// // Optionally, self-update the pipeline stack
// selfUpdateStage := pipeline.addStage(&stageOptions{
// stageName: jsii.String("SelfUpdate"),
// })
// selfUpdateStage.addAction(cicd.NewPipelineDeployStackAction(&pipelineDeployStackActionProps{
// stack: pipelineStack,
// input: synthesizedApp,
// adminPermissions: jsii.Boolean(true),
// }))
//
// // Now add our service stacks
// deployStage := pipeline.addStage(&stageOptions{
// stageName: jsii.String("Deploy"),
// })
// serviceStackA := NewMyServiceStackA(app, jsii.String("ServiceStackA"), &stackProps{
// })
// // Add actions to deploy the stacks in the deploy stage:
// deployServiceAAction := cicd.NewPipelineDeployStackAction(&pipelineDeployStackActionProps{
// stack: serviceStackA,
// input: synthesizedApp,
// // See the note below for details about this option.
// adminPermissions: jsii.Boolean(false),
// })
// deployStage.addAction(deployServiceAAction)
// // Add the necessary permissions for you service deploy action. This role is
// // is passed to CloudFormation and needs the permissions necessary to deploy
// // stack. Alternatively you can enable [Administrator](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_job-functions.html#jf_administrator) permissions above,
// // users should understand the privileged nature of this role.
// myResourceArn := "arn:partition:service:region:account-id:resource-id"
// deployServiceAAction.addToDeploymentRolePolicy(iam.NewPolicyStatement(&policyStatementProps{
// actions: []*string{
// jsii.String("service:SomeAction"),
// },
// resources: []*string{
// myResourceArn,
// },
// }))
//
// serviceStackB := NewMyServiceStackB(app, jsii.String("ServiceStackB"), &stackProps{
// })
// deployStage.addAction(cicd.NewPipelineDeployStackAction(&pipelineDeployStackActionProps{
// stack: serviceStackB,
// input: synthesizedApp,
// createChangeSetRunOrder: jsii.Number(998),
// adminPermissions: jsii.Boolean(true),
// }))
//
// Experimental.
type PipelineDeployStackActionProps struct {
// Whether to grant admin permissions to CloudFormation while deploying this template.
//
// Setting this to `true` affects the defaults for `role` and `capabilities`, if you
// don't specify any alternatives.
//
// The default role that will be created for you will have admin (i.e., `*`)
// permissions on all resources, and the deployment will have named IAM
// capabilities (i.e., able to create all IAM resources).
//
// This is a shorthand that you can use if you fully trust the templates that
// are deployed in this pipeline. If you want more fine-grained permissions,
// use `addToRolePolicy` and `capabilities` to control what the CloudFormation
// deployment is allowed to do.
// Experimental.
AdminPermissions *bool `field:"required" json:"adminPermissions" yaml:"adminPermissions"`
// The CodePipeline artifact that holds the synthesized app, which is the contents of the ``<directory>`` when running ``cdk synth -o <directory>``.
// Experimental.
Input awscodepipeline.Artifact `field:"required" json:"input" yaml:"input"`
// The CDK stack to be deployed.
// Experimental.
Stack awscdk.Stack `field:"required" json:"stack" yaml:"stack"`
// Acknowledge certain changes made as part of deployment.
//
// For stacks that contain certain resources, explicit acknowledgement that AWS CloudFormation
// might create or update those resources. For example, you must specify AnonymousIAM if your
// stack template contains AWS Identity and Access Management (IAM) resources. For more
// information.
// See: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-iam-template.html#using-iam-capabilities
//
// Experimental.
Capabilities *[]awscloudformation.CloudFormationCapabilities `field:"optional" json:"capabilities" yaml:"capabilities"`
// The name to use when creating a ChangeSet for the stack.
// Experimental.
ChangeSetName *string `field:"optional" json:"changeSetName" yaml:"changeSetName"`
// The name of the CodePipeline action creating the ChangeSet.
// Experimental.
CreateChangeSetActionName *string `field:"optional" json:"createChangeSetActionName" yaml:"createChangeSetActionName"`
// The runOrder for the CodePipeline action creating the ChangeSet.
// Experimental.
CreateChangeSetRunOrder *float64 `field:"optional" json:"createChangeSetRunOrder" yaml:"createChangeSetRunOrder"`
// The name of the CodePipeline action creating the ChangeSet.
// Experimental.
ExecuteChangeSetActionName *string `field:"optional" json:"executeChangeSetActionName" yaml:"executeChangeSetActionName"`
// The runOrder for the CodePipeline action executing the ChangeSet.
// Experimental.
ExecuteChangeSetRunOrder *float64 `field:"optional" json:"executeChangeSetRunOrder" yaml:"executeChangeSetRunOrder"`
// IAM role to assume when deploying changes.
//
// If not specified, a fresh role is created. The role is created with zero
// permissions unless `adminPermissions` is true, in which case the role will have
// admin permissions.
// Experimental.
Role awsiam.IRole `field:"optional" json:"role" yaml:"role"`
}