CDConfig: Add cd_content for file templating#61
Merged
azr merged 3 commits intohashicorp:mainfrom May 26, 2021
saleemrashid:cd-content
Merged
CDConfig: Add cd_content for file templating#61azr merged 3 commits intohashicorp:mainfrom saleemrashid:cd-content
azr merged 3 commits intohashicorp:mainfrom
saleemrashid:cd-content
Conversation
azr
reviewed
May 4, 2021
Comment on lines
+68
to
+83
| // Key/Values to add to the CD. The keys represent the paths, and the values | ||
| // contents. It can be used alongside `cd_files`, which is useful to add large | ||
| // files without loading them into memory. If any paths are specified by both, | ||
| // the contents in `cd_content` will take precedence. | ||
| // | ||
| // Usage example (HCL): | ||
| // | ||
| // ```hcl | ||
| // cd_files = ["vendor-data"] | ||
| // cd_content = { | ||
| // "meta-data" = jsonencode(local.instance_data) | ||
| // "user-data" = templatefile("user-data", { packages = ["nginx"] }) | ||
| // } | ||
| // cd_label = "cidata" | ||
| // ``` | ||
| CDContent map[string]string `mapstructure:"cd_content"` |
Contributor
|
Hi there @saleemrashi, #62 got merged, do you have the time to rebase & test this ? Thanks ! |
Contributor
Author
|
@azr Rebased and added tests 🙏 (and caught the missing |
Contributor
Author
|
(Sorry, pressed the button by accident 😄) |
up AddContent
azr
reviewed
May 26, 2021
|
|
||
| func (s *StepCreateCD) AddContent(dst, path, content string) error { | ||
| // Join Cleans the path so we can join it without path traversal issues. | ||
| dstPath := filepath.Join(dst, path) |
Contributor
There was a problem hiding this comment.
I removed the filepath.Clean call as Join already does that ! :)
Contributor
Author
There was a problem hiding this comment.
@azr From testing, doing filepath.Join("/folder", "../hello") would result in /hello which I don't think would be intended behaviour. Doing filepath.Clean on an absolute path would turn ../hello into /hello so it joins to /folder/hello.
azr
approved these changes
May 26, 2021
Contributor
azr
left a comment
There was a problem hiding this comment.
Tested this a little; this looks great to me ! Thanks !
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement
cd_contentfrom hashicorp/packer#10859, allowing file templating similar tohttp_content.There currently aren't any tests for this feature. I'd like to first make the
cd_filestests more robust (at the moment they only test that there are the expected number of keys infilesAdded), and then add tests forcd_content(including when used alongsidecd_files).