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 AWS::CloudFormation::Stackset resource to the cloudformation package command #5590

Open
ConnorKirk opened this issue Sep 30, 2020 · 6 comments · May be fixed by #5591
Open

Add AWS::CloudFormation::Stackset resource to the cloudformation package command #5590

ConnorKirk opened this issue Sep 30, 2020 · 6 comments · May be fixed by #5591
Labels
cloudformation package-deploy customization Issues related to CLI customizations (located in /awscli/customizations) feature-request A feature should be added or improved. has-pr This issue has a PR associated with it. p2 This is a standard priority issue

Comments

@ConnorKirk
Copy link
Contributor

ConnorKirk commented Sep 30, 2020

Is your feature request related to a problem? Please describe.
I would like to be able to use the aws cloudformation package command to package the AWS::CloudFormation::Stackset resource TemplateURL property. Currently it is not supported.

Describe the solution you'd like
See above

Describe alternatives you've considered
N/A

Additional context
I have started a PR for this - #5591

@ConnorKirk ConnorKirk added feature-request A feature should be added or improved. needs-triage This issue or PR still needs to be triaged. labels Sep 30, 2020
@ConnorKirk ConnorKirk changed the title Add AWS::CloudFormation::Stackset resource to the cloudformation package command Add AWS::CloudFormation::Stackset resource to the cloudformation package command Sep 30, 2020
@kdaily kdaily added cloudformation package-deploy and removed needs-triage This issue or PR still needs to be triaged. labels Oct 2, 2020
@kdaily kdaily added the customization Issues related to CLI customizations (located in /awscli/customizations) label Nov 12, 2020
@iainelder
Copy link

iainelder commented Jul 4, 2021

It would be great to see this included.

In the meantime you can use cfn-flip and jq to preprocess and postprocess the result for the package command.

cfn-flip template.yaml \
| jq '
.Resources |= with_entries(
    (.value.Type == "AWS::CloudFormation::StackSet") as $is_stackset
    | .key |= (if $is_stackset then "__STACKSET__" + . else . end)
    | .value.Type |= (if $is_stackset then "AWS::CloudFormation::Stack" else . end)
)' \
| cfn-flip > preprocessed.yaml

aws cloudformation package \
--template-file preprocessed.yaml \
--s3-bucket ... \
--output-template-file packaged.yaml

cfn-flip packaged.yaml \
| jq '
.Resources |= with_entries(
    (.key | startswith("__STACKSET__")) as $is_stackset
    | .key |= (if $is_stackset then split("__STACKSET__")[1] else . end)
    | .value.Type |= (if $is_stackset then "AWS::CloudFormation::StackSet" else . end)
)' \
| cfn-flip > postprocessed.yaml

cfn-flip converts YAML CloudFormation templates to JSON and vice versa.

The first jq program modifies each stack set resource so that the package command will process them. It replaces the StackSet type declaration with a Stack type declaration. It prepends a __STACKSET__ flag to the logical resource name so that the process can be reversed.

The preprocessed.yaml is an invalid CloudFormation template because the StackSet properties don't make sense for the Stack type.

The package command ignores this and does its job. The packaged.yaml is still an invalid CloudFormation template, but it contains the S3 URLs we were hoping for.

The second jq program reverses the changes of the first program.

The postprocessed.yaml is once more a valid CloudFormation template and more or less the result you would hope for. Comments in the original template.yaml are lost, but the resource graph is equivalent.

All the files are written to the same directory as the template.yaml to ensure that relative paths are still correct. After deploying the template you will probably want to delete preprocessed.yaml, packaged.yaml, and postprocessed.yaml to keep your source files clean.

@andrewlytle
Copy link

Any chance this is going to get added soon?

@tim-finnigan tim-finnigan added has-pr This issue has a PR associated with it. p2 This is a standard priority issue labels Nov 4, 2022
@nandubatchu
Copy link

Thanks for the PR - I made it work with your dev branch. Hope this gets merged soon!

@iainelder
Copy link

Another workaround is to use CloudFormation Rain CLI.

Its !Rain::S3Http is a more powerful version of the package command. that works with any property.

The rain deploy and rain package commands upload a file or directory to S3 and inserts the HTTPS URL into the template as a string.

Resources:
  Example:
    Type: AWS::CloudFormation::StackSet
    Properties:
      StackSetName: example
      TemplateURL: !Rain::S3Http instance-template.yaml

@jhonkan
Copy link

jhonkan commented Aug 30, 2024

Any change to merge the pull request #5591? SAM CLI does not support packaging stacksets as suggested in some of the comments here/in the PR, and Rain CLI does not look like something I would like to adopt at the moment.

One alternative approach to the suggested script I can think of is to package the file the AWS::CloudFormation::Stackset's TemplateURL property points to, upload it to S3 and change the local path to the upload's URL.

@gataka
Copy link

gataka commented Sep 16, 2024

Hi. I hope this feature will come soon.

One real workaround is this:

Transform:
  - AWS::LanguageExtensions
  
...

      TemplateBody:
        Fn::ToJsonString:
             'Fn::Transform':
                Name: 'AWS::Include'
                Parameters:
                  Location:  template-without-shorthand-functions.yaml

By this solution you need to know, that the executions of functions in the template-without-shorthand-functions.yaml will be executed by the ToJsonString. So you have to set the Stack-Set-Parameters with the Stack-Set-Owning-Template-Parameters. So it might be that you have to Nest the StackSet inside a new nested Stack. Complicated, but it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloudformation package-deploy customization Issues related to CLI customizations (located in /awscli/customizations) feature-request A feature should be added or improved. has-pr This issue has a PR associated with it. p2 This is a standard priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants