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 parameters to CfnInclude #4994

Closed
2 tasks
cmckni3 opened this issue Nov 13, 2019 · 9 comments · Fixed by #9543
Closed
2 tasks

Pass parameters to CfnInclude #4994

cmckni3 opened this issue Nov 13, 2019 · 9 comments · Fixed by #9543
Assignees
Labels
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on.

Comments

@cmckni3
Copy link
Contributor

cmckni3 commented Nov 13, 2019

Allow passing parameters to template included via CfnInclude.

Use Case

It would be nice to be able to reuse existing templates (from quickstarts for example) that rely on parameters being passed to them.

Proposed Solution

Not really sure but my workaround is to remove the parameters and hardcode them.

Perhaps CfnInclude could have a prop for CfnParameters?

Other

Reference example of importing an existing template. Imagine the template has parameters. The drupal quickstart is an example of a quickstart with many parameters.

import cdk = require("@aws-cdk/core");
import fs = require("fs");

new cdk.CfnInclude(this, "ExistingInfrastructure", {
  template: JSON.parse(fs.readFileSync("my-template.json").toString())
});
  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change

This is a 🚀 Feature Request

@cmckni3 cmckni3 added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Nov 13, 2019
@cmckni3
Copy link
Contributor Author

cmckni3 commented Nov 13, 2019

I wonder if it would be possible for CfnInclude to return a Stack with the constructs inside of it.

@SomayaB SomayaB added the @aws-cdk/core Related to core CDK functionality label Nov 13, 2019
@joekiller
Copy link

When using CfInclude nothing is stopping you from using parameters in that stack. You can even use cdk parameters and then import. As long as the ID is aligned it'll work. I did something similar here:

https://gist.github.com/joekiller/36f28eeffeeb50d3c0f4373c3d372d9e

Note to parse and then include the stack I had to make the yaml "clean" ie no bang (!Ref) functions. Use Fn::Ref instead. Your yaml module may vary (YYMMV)

@joekiller
Copy link

joekiller commented Nov 26, 2019

Typically you can do,

app=core.App()
core.stack(app)
CfnInclude(app, mystack)
app.synth()

And it's there.

@joekiller
Copy link

If I wasn't clear enough. Parameters import fine. If you want to replace those you can do something like my gist where you set the default of the parameter to what you want.

@cmckni3
Copy link
Contributor Author

cmckni3 commented Dec 6, 2019

I have been reading about making use of context to provide defaults to when using cdk deploy as well.

Reading in existing templates parsing them as JSON/YAML and modifying them as necessary is a great first step and works for now.

Thanks @joekiller!

@cmckni3
Copy link
Contributor Author

cmckni3 commented Dec 6, 2019

cdk-dasm is helpful as well

@flyingImer
Copy link
Contributor

flyingImer commented Dec 11, 2019

When using CfInclude nothing is stopping you from using parameters in that stack. You can even use cdk parameters and then import. As long as the ID is aligned it'll work. I did something similar here:

https://gist.github.com/joekiller/36f28eeffeeb50d3c0f4373c3d372d9e

Note to parse and then include the stack I had to make the yaml "clean" ie no bang (!Ref) functions. Use Fn::Ref instead. Your yaml module may vary (YYMMV)

I'm interested in putting a resource value into a parameter 'Default' of an included CFN, for example, an S3 bucket name, the bucket is defined in another CDK stack. Is it feasible for your experience?

I know, by default, CDK does 'Fn::ImportValue' and stack 'Outputs::Export' for you. Since parameters are a little bit tricky here, they don't take intrinsic functions (and I don't think it makes any sense), any clue how to orchestrate this? is this another anti-pattern thing? (maybe this should leave to the CDK team...)

@eladb eladb added the effort/medium Medium work item – several days of effort label Jan 23, 2020
@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Mar 4, 2020
@logemann
Copy link

logemann commented May 12, 2020

would love to see something implemented right into CfnInclude. Something like a attribute in the struct like params where you can supply a structure of key/values.

Of course one can do this manually like @joekiller did, but life is too short ;-)

Context: i am going to import the InstanceSheduler template which has tons of params.

@joekiller
Copy link

@logemann there is a --parameter switch now but you cannot set it any way other than via CLI. I'd like it if I could provide a map of parameters to a cloudformation context.

I ended up having to double down on some CLI switches. See #7576 (comment)

@skinny85 skinny85 assigned comcalvi and unassigned eladb Aug 5, 2020
@SomayaB SomayaB added the in-progress This issue is being actively worked on. label Aug 10, 2020
@mergify mergify bot closed this as completed in #9543 Aug 13, 2020
mergify bot pushed a commit that referenced this issue Aug 13, 2020
…9543)

----
Closes #4994

Cfn-Include can now be passed a mapping of parameters and their values. Specified parameters will have all references to them replaced with the passed value at build time, and their definitions will be removed from the template. Unspecified parameters and references to them will not be modified. 

*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
@aws-cdk/core Related to core CDK functionality effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. in-progress This issue is being actively worked on.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants