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

userdata - interpolate stack variables into file #677

Closed
brettswift opened this issue Mar 10, 2017 · 6 comments
Closed

userdata - interpolate stack variables into file #677

brettswift opened this issue Mar 10, 2017 · 6 comments

Comments

@brettswift
Copy link

It'd be great if we could interpolate variables within an external userdata file.

Problem statement:

given this:
UserData=userdata.from_file('./templates/userdata/userdata.sh'),

and a requirement to drop in a cfn-signal that contains parameters at the end of the script:

    "cfn-signal -e 0",
        "    --resource AutoscalingGroup",
        "    --stack ", Ref("AWS::StackName"),
        "    --region ", Ref("AWS::Region"), "\n"

I'd like to have a way to drop params and have them replaced within the external file. :)

Maybe there's a magical way I haven't come across?

@phobologic
Copy link
Member

@brettswift In stacker we have the file lookup, which handles loading a file and replacing certain patterns with Ref statements. You can see that here:

https://github.com/remind101/stacker/blob/master/stacker/lookups/handlers/file.py

@markpeek
Copy link
Member

I haven't looked at the code but could there be a variant that does dictionary based string formatting against the file being imported?

@brettswift
Copy link
Author

@phobologic cool - I'm pretty new to trop but stacker is on the radar as well. I'm more familiar with ruby but I'm sure there's a robust templating language on the python side that would be a good candidate. At risk of bloating the code for a fringe case.

The simple one would be along the lines of @markpeek - pass a dict into the function and find / replace. Likely not a massively hard PR to throw in. Even for a ruby guy :)

@brettswift
Copy link
Author

Another use case:
This would need to be a generic function for other files not just userdata.

For instance putting environment variables into a buildspec file for codebuild.

It's nicer to have a buildspec as a .yml file a opposed to inline with \n carriage returns all over :)

I haven't done the work around yet. I'm guessing someone has?

@jaekunchoi
Copy link

#724 should address this issue. I have tested it. It would be great if we can merge this one in @markpeek

@brettswift
Copy link
Author

@hybmg57 that will still result in a Base64 string though?

#683 is another ticket I created that might solve this one, if we can bring files in that aren't base64 encoded, then you can wrap the result in a Sub() function and use template variables directly in the files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants