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

Pass CloudFormation Parameters to "cdk deploy" #1237

Closed
gmiano opened this issue Nov 22, 2018 · 23 comments · Fixed by #6385
Closed

Pass CloudFormation Parameters to "cdk deploy" #1237

gmiano opened this issue Nov 22, 2018 · 23 comments · Fixed by #6385
Assignees
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p0 package/tools Related to AWS CDK Tools or CLI

Comments

@gmiano
Copy link

gmiano commented Nov 22, 2018

Hi,
I already use aws-cdk to create a CloudFormation that represents my infrastructure.

I would like to use CDK Toolkit for Continuous Integration in order to Deploy stack updates.
Unfortunately the stack I am working with contains CloudFormation Parameters and I have not found a way to pass Parameters values yet?

Is there a way, not documented, to achieve this purpose? Are you to integrate this feature in the near future?

Best regards,
Giuseppe.

@RomainMuller
Copy link
Contributor

Hey @gmiano we don't currently provide a way to pass parameter values during the deployment. It is something e have considered, but generally speaking we'd advise to make your templates as concrete as possibly by using context instead of parameters.

If that's something you can share with us here, I'd like to know more of what you're using parameters for, and what your Continuous Integration solution is. That would help us determine the best way forward.

@RomainMuller RomainMuller added the feature-request A feature should be added or improved. label Nov 23, 2018
@gmiano
Copy link
Author

gmiano commented Nov 23, 2018

Hi @RomainMuller,
In my case we use CF Parameter variables to inject configuration within cloudformation on deploy time rather than during build time using context variables.

During a release canvas a specific version of the CloudFormation is built and deployed within an artifactory server.
We also have an Ansible playbook that downloads these artifacts and deploy the CF and related assets and passes customizable parameters.

@john-shaskin
Copy link
Contributor

We've got kind of a similar process we're trying to implement. Currently, we're using troposphere-based tools to generate a CloudFormation artifact to pass into CodePipeline, and deploy with a CloudFormation action. This artifact contains:

  1. A single set of CloudFormation templates to represent each independently deployable stack needed by a service.
  2. For each deployment environment, a set of JSON configuration files containing CloudFormation parameter values and tags, to use when deploying each stack to that environment.

We're liking the concept of reusable constructs in CDK as well as the option to use other languages for managing CloudFormation, but are not sure if its possible to use it to synthesize the same kind of deployment artifact. It seems like we would need to:

  1. Instantiate all the environment-specific stacks with their appropriate configuration at the root app level.
  2. Use a CodeBuild step or a Lambda that would execute the CDK deploy command(s) in the pipeline, passing in the set of stacks to deploy for a given environment.

Am I correct, or is there a way that we could continue to produce the same kind of artifact we currently are?

@john-shaskin
Copy link
Contributor

@RomainMuller, saw your stackoverflow reply to a very similar question. We will look at trying that approach.

@brettswift
Copy link

brettswift commented Jan 16, 2019

My use case is similar to those above, but I can add a couple of points.

The main difference I see by not being allowed this at deployment time is split into some pros/cons:

Pros of forcing params at build time:

  • Your code can output a more concise template. Include resources or omit them, or change them.
    • Essentially less need (or no need) for the painful cloudformation conditionals.

Cons:

  • in a CD workflow, you have to run a build step as well now, and then a deploy. This isn't so aweful.
  • because you have to run a build at deploy time, you lose the capability of comparing templates in prod and nonprod.
  • If you find something is broken in prod, but works in dev.. now you have a slightly bigger radius to search for your issue. You also have another scenario to test (possibly) in non prod.

All in all - I kind of agree with the 'build time only' parameters because of the simplicity, and because I can still mitigate the Cons I listed. However, I can think of (and can read on this post) a few use cases where I'd want deploy time params.

The biggest use case as pointed out here: (#169 (comment)), is helping to increase adoption rates of CDK.

I don't know if allowing for deployment parameters would weaken CDK. And if not, maybe it should support deploy time parameters. Let the user decide which approach is best (with the advice of a well written best practices document to guide them :) )

Just my 2 bit ($CAD)

@fulghum fulghum added the effort/medium Medium work item – several days of effort label Feb 18, 2019
@fulghum fulghum added the p0 label Apr 17, 2019
@SomayaB SomayaB added needs-triage This issue or PR still needs to be triaged. package/tools Related to AWS CDK Tools or CLI labels Sep 10, 2019
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Sep 11, 2019
@SomayaB
Copy link
Contributor

SomayaB commented Oct 1, 2019

@fulghum Is this still relevant/should this still be p0?

@jderose9
Copy link

jderose9 commented Oct 2, 2019

This certainly seems relevant to me. It is a necessity to be able to generate a single cdk synth output during my application build phase that can be deployed to as many environments as needed.

@john-tipper
Copy link

I'd second @jderose9's requirement. I want to be able to define a stack of resources that will be created for a tenant on a SaaS I'm working on. I want to apply this stack for each tenant, so that all tenants have an identical set of resources. I would prefer to supply parameters to a known-good version of cdk synth, rather than re-build for each tenant.

@SomayaB SomayaB assigned skinny85 and unassigned rix0rrr Oct 16, 2019
@SomayaB SomayaB added management/ci-cd Related to CI/CD and removed package/tools Related to AWS CDK Tools or CLI labels Oct 16, 2019
@SomayaB SomayaB assigned shivlaks and unassigned skinny85 Oct 16, 2019
@SomayaB SomayaB added package/tools Related to AWS CDK Tools or CLI and removed management/ci-cd Related to CI/CD labels Oct 16, 2019
@geekybaiyi
Copy link

this is still very relevant.
anyone has any alternative until this get implemented?
thx

@geekybaiyi
Copy link

Hey @gmiano we don't currently provide a way to pass parameter values during the deployment. It is something e have considered, but generally speaking we'd advise to make your templates as concrete as possibly by using context instead of parameters.

just would like to make sure that using context is the preferred approach ?

@gmiano
Copy link
Author

gmiano commented Oct 28, 2019

Hi @geekybaiyi that solution is not compliant with corporate requirements of reproducibility of deploy in different environments. We moved to terraform that allows us to apply the behaviour we expect.

@manast
Copy link

manast commented Nov 4, 2019

I am a bit confused about how the codepipeline can be used to deploy fargate services if we cannot pass parameters from the pipeline to the template at deploy time.
For instance, in the build step I am building a docker image, that image is uploaded to a ECR repository and tagged. In the deploy step I want to use that particular image, however I have no means to pass that value to the template.
I thought that a workaround would be to use "latest" as tag, however this does not work, because cloudformation does not update a stack if the template itself has not changed (or any of its input paramters have changed).
Any suggestions on what is AWS recommended approach for solving an scenario like this?

@manast
Copy link

manast commented Nov 4, 2019

@RomainMuller sorry for tagging you, but you requested some information to the poster and it seems that you forgot to give any feedback.

@skinny85
Copy link
Contributor

skinny85 commented Nov 4, 2019

@manast I'm not sure where you got "we cannot pass parameters from the pipeline to the template at deploy time.", but that is not true. The parameterOverrides property of the CloudFormation deployment CodePipeline actions allows you to do that. We have an example using it for Lambda deployments here: https://docs.aws.amazon.com/cdk/latest/guide/codepipeline_example.html

Thanks,
Adam

@skinny85
Copy link
Contributor

skinny85 commented Nov 6, 2019

@manast can you look at this example? It uses an older version of the CDK (0.31.0), but it does what you're looking for: it builds a Docker image in a CodeBuild project, pushes it to an ECR repository, and then deploys the image with CloudFormation, all within a CodePipeline.

Now, there is one important element in that example that is missing from the main library: this special ecs.ContainerImage implementation that allows you to "late-bind" the image used for an ECS service (with a CloudFormation parameter). If you confirm that this does what you're looking for, I'll open a PR adding it to our main Construct Library.

@SomayaB SomayaB added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Nov 6, 2019
@manast
Copy link

manast commented Nov 7, 2019

@skinny85 yes, this is exactly what I was looking for. And actually the implementation of the PipelineContainerImage is precisely the part of the code that I find more difficult to understand. I am used to use parametersOverride in CF and just pass to standard parameters, but in this case it seems it is using SSM which confuses me a bit.

@skinny85
Copy link
Contributor

skinny85 commented Nov 7, 2019

I'm not sure where you got the idea that PipelineContainerImage uses SSM... I can assure you it uses CloudFormation parameters.

@manast
Copy link

manast commented Nov 8, 2019

@SomayaB SomayaB removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Nov 8, 2019
@skinny85
Copy link
Contributor

OK. There is more than one class called CfnParameter :).

The one you linked to is an auto-generated class for the SSM Parameter resource - our convention for the auto-generated classes is to prefix them with Cfn (for example, CfnBucket is the auto-generated class for the S3 bucket resource). SSM has a resource called Parameter, hence CfnParameter. That class resides in the @aws-cdk/aws-ssm package.

The CfnParameter class used in PipelineContainerImage is from the @aws-cdk/core package (you can see it by the import: import cdk = require('@aws-cdk/cdk');, which is what the core package used to be called in version 0.31.0, and the usage: private parameter?: cdk.CfnParameter;). This is a link to its documentation: https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_core.CfnParameter.html

Does this clear things up?

@SomayaB SomayaB added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Nov 21, 2019
@SomayaB SomayaB added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Dec 2, 2019
@skinny85
Copy link
Contributor

skinny85 commented Dec 8, 2019

@manast do you want me to add the PipelineContainerImage from above to the CDK library - will it fix your problem?

@manast
Copy link

manast commented Dec 8, 2019

@skinny85 I would need to revisit that code again since it has passed some weeks now and i do not remember all the details anymore.

@ghost
Copy link

ghost commented Feb 20, 2020

We have had the same issues, where we would like to be able to pass parameters to CloudFormation with cdk deploy. So I have made a pull request with something that we have found to work for us. Please let me know if this could work.

@mergify mergify bot closed this as completed in #6385 Mar 4, 2020
mergify bot added a commit that referenced this issue Mar 4, 2020
* feat(aws-cdk): pass cloudformation parameters to "cdk deploy"

This commit closes #1237

I have added the command line option --parameters, -P which allows for
adding CloudFormation parameters at deploy time.

The functionality for deploying with parameters was already present,
but I have just added a way for the command line to pass it to the
deployment code.

The motivation for adding this functionality has been that we have
a setup where we share an account with access to CloudFormation, which
is why we do not want to have some fields in plain text, while they do
not have access to other services, which did not support secrets within
the fields we want to keep secret. This allows us to have parameters
that can be kept secret from the templates, while also having parameters
with NoEcho.

I have verified this functionality by both deploying a cdk project
with a CfnParameter from @aws-cdk/core, and an original CloudFormation
template with parameters.

* feat(cli): pass cloudformation parameter to "cdk deploy"

This changes the syntax of the --parameter parameter, so that it is now
possible to specify which stack a parameter is meant for, i.e. of you
want a parameter to apply to `MyStack`, then you would pass it as
--parameters MyStack:key=value
While still being able to pass parameters to all stacks by omitting the
stack name, i.e. --paramters key=value

This is being added to support wild card deployments, and deployments
with multiple stacks that do not neccessary contain the same parameters.

I have verified these changes by deploying a multistack cdk project,
where the stacks contains different parameters, and some shared
parameters.

* feat(cli): pass cloudformation parameters to "cdk deploy"

I have added some integration tests of both wildcard and single
deployments with parameters. While also fixing a bug found while
testing.

* feat(cli): pass cloudformation parameters to "cdk deploy"

Adding integration test for nested stacks.

Adding section in README.

* feat(cli): pass cloudformation parameters to "cdk deploy"

Adding an example of using parameters to the README.md

* update README

* more README cleanup

Co-authored-by: Elad Ben-Israel <benisrae@amazon.com>
Co-authored-by: Shiv Lakshminarayan <shivlaks@amazon.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
eladb pushed a commit that referenced this issue Mar 9, 2020
* feat(aws-cdk): pass cloudformation parameters to "cdk deploy"

This commit closes #1237

I have added the command line option --parameters, -P which allows for
adding CloudFormation parameters at deploy time.

The functionality for deploying with parameters was already present,
but I have just added a way for the command line to pass it to the
deployment code.

The motivation for adding this functionality has been that we have
a setup where we share an account with access to CloudFormation, which
is why we do not want to have some fields in plain text, while they do
not have access to other services, which did not support secrets within
the fields we want to keep secret. This allows us to have parameters
that can be kept secret from the templates, while also having parameters
with NoEcho.

I have verified this functionality by both deploying a cdk project
with a CfnParameter from @aws-cdk/core, and an original CloudFormation
template with parameters.

* feat(cli): pass cloudformation parameter to "cdk deploy"

This changes the syntax of the --parameter parameter, so that it is now
possible to specify which stack a parameter is meant for, i.e. of you
want a parameter to apply to `MyStack`, then you would pass it as
--parameters MyStack:key=value
While still being able to pass parameters to all stacks by omitting the
stack name, i.e. --paramters key=value

This is being added to support wild card deployments, and deployments
with multiple stacks that do not neccessary contain the same parameters.

I have verified these changes by deploying a multistack cdk project,
where the stacks contains different parameters, and some shared
parameters.

* feat(cli): pass cloudformation parameters to "cdk deploy"

I have added some integration tests of both wildcard and single
deployments with parameters. While also fixing a bug found while
testing.

* feat(cli): pass cloudformation parameters to "cdk deploy"

Adding integration test for nested stacks.

Adding section in README.

* feat(cli): pass cloudformation parameters to "cdk deploy"

Adding an example of using parameters to the README.md

* update README

* more README cleanup

Co-authored-by: Elad Ben-Israel <benisrae@amazon.com>
Co-authored-by: Shiv Lakshminarayan <shivlaks@amazon.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
horsmand pushed a commit to horsmand/aws-cdk that referenced this issue Mar 9, 2020
* feat(aws-cdk): pass cloudformation parameters to "cdk deploy"

This commit closes aws#1237

I have added the command line option --parameters, -P which allows for
adding CloudFormation parameters at deploy time.

The functionality for deploying with parameters was already present,
but I have just added a way for the command line to pass it to the
deployment code.

The motivation for adding this functionality has been that we have
a setup where we share an account with access to CloudFormation, which
is why we do not want to have some fields in plain text, while they do
not have access to other services, which did not support secrets within
the fields we want to keep secret. This allows us to have parameters
that can be kept secret from the templates, while also having parameters
with NoEcho.

I have verified this functionality by both deploying a cdk project
with a CfnParameter from @aws-cdk/core, and an original CloudFormation
template with parameters.

* feat(cli): pass cloudformation parameter to "cdk deploy"

This changes the syntax of the --parameter parameter, so that it is now
possible to specify which stack a parameter is meant for, i.e. of you
want a parameter to apply to `MyStack`, then you would pass it as
--parameters MyStack:key=value
While still being able to pass parameters to all stacks by omitting the
stack name, i.e. --paramters key=value

This is being added to support wild card deployments, and deployments
with multiple stacks that do not neccessary contain the same parameters.

I have verified these changes by deploying a multistack cdk project,
where the stacks contains different parameters, and some shared
parameters.

* feat(cli): pass cloudformation parameters to "cdk deploy"

I have added some integration tests of both wildcard and single
deployments with parameters. While also fixing a bug found while
testing.

* feat(cli): pass cloudformation parameters to "cdk deploy"

Adding integration test for nested stacks.

Adding section in README.

* feat(cli): pass cloudformation parameters to "cdk deploy"

Adding an example of using parameters to the README.md

* update README

* more README cleanup

Co-authored-by: Elad Ben-Israel <benisrae@amazon.com>
Co-authored-by: Shiv Lakshminarayan <shivlaks@amazon.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Nov 30, 2020
…ant to be used in CodePipeline

While CDK Pipelines is the idiomatic way of deploying ECS applications in CDK,
it does not handle the case where the application's source code is kept in a separate source code repository from the CDK infrastructure code.
This adds a new class to the ECS module,
`TagParameterContainerImage`, that allows deploying a service managed that way through CodePipeline.

Related to aws#1237
Related to aws#7746
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Dec 1, 2020
…ant to be used in CodePipeline

While CDK Pipelines is the idiomatic way of deploying ECS applications in CDK,
it does not handle the case where the application's source code is kept in a separate source code repository from the CDK infrastructure code.
This adds a new class to the ECS module,
`TagParameterContainerImage`, that allows deploying a service managed that way through CodePipeline.

Related to aws#1237
Related to aws#7746
skinny85 added a commit to skinny85/aws-cdk that referenced this issue Dec 7, 2020
…ant to be used in CodePipeline

While CDK Pipelines is the idiomatic way of deploying ECS applications in CDK,
it does not handle the case where the application's source code is kept in a separate source code repository from the CDK infrastructure code.
This adds a new class to the ECS module,
`TagParameterContainerImage`, that allows deploying a service managed that way through CodePipeline.

Related to aws#1237
Related to aws#7746
mergify bot pushed a commit that referenced this issue Dec 7, 2020
… be used in CodePipeline (#11795)

While CDK Pipelines is the idiomatic way of deploying ECS applications in CDK,
it does not handle the case where the application's source code is kept in a separate source code repository from the CDK infrastructure code.
This adds a new class to the ECS module,
`TagParameterContainerImage`, that allows deploying a service managed that way through CodePipeline.

Related to #1237
Related to #7746

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
flochaz pushed a commit to flochaz/aws-cdk that referenced this issue Jan 5, 2021
… be used in CodePipeline (aws#11795)

While CDK Pipelines is the idiomatic way of deploying ECS applications in CDK,
it does not handle the case where the application's source code is kept in a separate source code repository from the CDK infrastructure code.
This adds a new class to the ECS module,
`TagParameterContainerImage`, that allows deploying a service managed that way through CodePipeline.

Related to aws#1237
Related to aws#7746

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p0 package/tools Related to AWS CDK Tools or CLI
Projects
None yet