Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for CloudFormation actions, continued #525

Merged
merged 9 commits into from
Aug 8, 2018

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Aug 8, 2018

Address review comments, fix input/output artifacts issue, expand README

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.

mindstorms6 and others added 2 commits August 5, 2018 14:53
---
Author's note: This work mostly belongs to Max Hall (@hallmaxw)
It was at some point commented out during a refactor - this is just adding it back.
Most of the credit should go to him.
---

Anywho - this adds the ability for customers to use CloudForamtion actions in CodePipeline.
This follows the same pattern as previous CodePipeline actions by making it it's own package.
@rix0rrr rix0rrr requested review from eladb and RomainMuller August 8, 2018 13:19
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Aug 8, 2018

Because you're probably wondering, this is the inheritance diagram of actions, and what each shared class adds to the mix.

                  ┌─────────────────────────┐                                                
                  │                         │   stackname                                    
                  │  CloudFormationAction   │   outputartifact                               
                  │                         │                                                
                  └─────────────────────────┘                                                
                               ▲                                                             
                               │                                                             
             ┌─────────────────┴────────────────────────┐                                    
             │                                          │                                    
             │                                          │                                    
┌─────────────────────────┐             ┌──────────────────────────────┐                     
│                         │             │                              │                     
│    ExecuteChangeSet     │             │  CloudFormationDeployAction  │ permissions         
│                         │             │                              │                     
└─────────────────────────┘             └──────────────────────────────┘                     
                                                        ▲                                    
                                                        │                                    
                                ┌───────────────────────┼────────────────────────┐           
                                │                       │                        │           
                                │                       │                        │           
                     ┌────────────────────┐  ┌────────────────────┐   ┌─────────────────────┐
                     │                    │  │                    │   │                     │
                     │  PrepareChangeSet  │  │ CreateUpdateStack  │   │   DeleteStackOnly   │
                     │                    │  │                    │   │                     │
                     └────────────────────┘  └────────────────────┘   └─────────────────────┘

@@ -0,0 +1 @@
export * from './pipeline-action';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<style> There's multiple actions in the file, so I'd pluralize the name.

import iam = require('@aws-cdk/aws-iam');
import cdk = require('@aws-cdk/cdk');

// tslint:disable:max-line-length
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the long URL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disable only around that comment block?

/**
* The name of the output artifact to generate
*
* Only applied if `outputFileName` is set as well.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be tempted to have

output?: {
    fileName: string;
    artifactName?: string;
}

So you cannot specify outputArtifactName if it makes no sense.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmmyeah. But in general we keep the property namespace flat.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's why I only say tempted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Rico.Optimize for the common case which is to just specify the file name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally artifact names exist only to allow references in the Pipeline model which are achieved much better with object references in the CDK.

Copy: @skinny89

});

if (props.outputFileName) {
this.artifact = this.addOutputArtifact(props.outputArtifactName || (this.parent!.name + this.name + 'Artifact'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use this.parent! when you have the guaranteed non-null parent available?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the constructor parent is not optional, so therefore it must be assigned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean why can't you use parent instead of this.parent!?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Well. I guess I could :)


constructor(parent: codepipeline.Stage, id: string, props: CloudFormationDeploymentActionCommonProps, configuration: any) {
super(parent, id, props, {
Capabilities: props.trustTemplate ? [CloudFormationCapabilities.NamedIAM] : props.capabilities,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if you trust the template, you cannot add other capabilities than NamedIAM?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, good point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, what other capabilities are there :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, none, but nothing says it'll remain like this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn’t future proof this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's risky... very likely to be overlooked if/when new capabilities get added. And the fix is not horribly expensive either...

ParameterOverrides: props.parameterOverrides,
TemplateConfiguration: props.templateConfiguration,
StackName: props.stackName,
...configuration,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd move ...configuration up-front, because otherwise it can override the values you specified before...

});

if (props.role) {
this.role = props.role;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you specify your own role, and say you trust the template, the policy doesn't get amended to extend any action on all resources. This seems to contradict the documentation of trustTemplate.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not contradict the documentation of role, and it was intended this way (similar to default of capabilities). This is a shortcut if you can't be bothered to specify anything. If you can, then you should just spell it out all the way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah no, the docs say it adds to the "default role", which is only the role that gets created if you don't specify anything.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels to me like a warning probably should be emitted...

"jsx": "react",
"jsxFactory": "jsx.create"
},
"_generated_by_jsii_": "generated by jsii - you can delete, and ideally add to your .gitignore"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do what the tool says!

*
* @default false
*/
trustTemplate?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like fullTrust or adminPrivileges or root. Something that has to do with "admin"

/**
* Whether the deployed templates are trusted.
*
* If `true`, the default `role` will have full permissions and the default
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be more explicit in the docs about the IAM policy that this implies

const changeSetName = "ChangeSetIntegTest";
const stackName = "IntegTest-TestActionStack";

const role = new Role(stack, 'CfnChangeSetRole', {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the default role

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is, now we're integ-testing both variants :).

"artifactId": "cloudformation-codepipeline"
}
},
"dotnet": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd need to remove this target from here and "re-add" it into #524 ideally.

import cdk = require('@aws-cdk/cdk');
import { PolicyStatement, ServicePrincipal } from '@aws-cdk/cdk';
import { Test } from 'nodeunit';
import { CreateReplaceChangeSet, CreateUpdateStack, ExecuteChangeSet } from '../lib/pipeline-action';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing 's'

@rix0rrr rix0rrr merged commit c618614 into master Aug 8, 2018
@rix0rrr rix0rrr deleted the mindstorms6/cloudformation-actions branch August 8, 2018 14:45
@RomainMuller RomainMuller mentioned this pull request Aug 8, 2018
@NGL321 NGL321 added the contribution/core This is a PR that came from AWS. label Sep 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants