-
Notifications
You must be signed in to change notification settings - Fork 53
[Feature] - Pass tags through a tfvars vs cli #431
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #431 +/- ##
==========================================
- Coverage 82.44% 81.78% -0.67%
==========================================
Files 54 54
Lines 1487 1499 +12
Branches 316 319 +3
==========================================
Hits 1226 1226
- Misses 115 126 +11
- Partials 146 147 +1
Continue to review full report at Codecov.
|
f5c5658 to
9adceda
Compare
|
@kmanning Let us know if the pr need to be updated. |
docs/TagPlugin.md
Outdated
| .build() | ||
| ``` | ||
|
|
||
| If you want to simplify the cli command you can pass the tags using `-var-file` instaed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type: 'instaed'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be clarified?
If you want to simplify the cli command, you can use the .writeToFile() method to write tags out to a file and pass them using -var-file instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type: 'instaed'
corrected
docs/TagPlugin.md
Outdated
| def validate = new TerraformValidateStage() | ||
| // Tag variables will be passsed via `-var-file` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo passsed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected
| String value = convertMapToCliString(values) | ||
| Jenkinsfile.writeFile(fileName, "${key}=${value}") | ||
| return withVariableFile(fileName) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future refactoring of this feature, I could imagine pushing the writing of the file up to the TagPlugin. That could reduce duplication a bit.
| String value = convertMapToCliString(values) | ||
| Jenkinsfile.writeFile(fileName, "${key}=${value}") | ||
| return withVariableFile(fileName) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future refactoring of this feature, I could imagine pushing the writing of the file up into TagPlugin. It would reduce duplication a bit.
| public static writeToFile() { | ||
| writeToFile = true | ||
| return this | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a future refactoring of this feature, I could imagine writeToFile accepting an option string, to overwrite the file name that is written. The default value of the optional string parameter could be the filename that you're currently using <environment>-tags.tfvars
test/TagPluginTest.groovy
Outdated
|
|
||
| verify(command, times(1)).withVariable(anyString(), anyMap()) | ||
| verifyNoMoreInteractions(command) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine as it is, but in this test, you're actually testing apply and not writeToFile. You could optionally group this under ApplyForApplyCommand.
I would also consider that this specific test case is already covered by
| public void addsTheTagArgument() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. I guess I was just verifying the behavior is changed between "normally" and "writesToFile". I will just remove this one.
| verify(command, times(1)).withVariableFile(anyString(), anyMap()) | ||
| verifyNoMoreInteractions(command) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine as it is, but in this test, you're actually testing apply and not writeToFile. You could optionally group this under ApplyForApplyCommand.
Further, you're testing a specific condition of apply - the condition = when writeToFile is used. I might consider nesting that, similar to what is happening with WithVariableName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. I'll move it
| verify(original).writeFile(file: filename.toString(), text: content.toString()) | ||
| verifyNoMoreInteractions(original) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but I think this test case wouldn't exist, if writing-the-file behavior lived in TagPlugin.
| def content = "${myKey}={expectedKey=\"${expectedValue}\"}" | ||
| verify(original).writeFile(file: filename.toString(), text: content.toString()) | ||
| verifyNoMoreInteractions(original) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is fine, but I think this test case wouldn't exist as-is, if writing-the-file behavior lived in TagPlugin.
| verifyNoMoreInteractions(command) | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've tested TagPlugin with TerraformApplyCommand, but not TerraformPlanCommand? Gross, that's because the interface for apply is not very clean... Disregard this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
![]()
|
Please squash and merge this request when ready. |
This PR will support the ability to pass tags through a generated tfvars file instead. This simplifies the cli command.
This is beneficial for custom plugins that might need wrap the full terraform commands with some other commands for example
su ec2-user -c "{generate terraform}"without worrying about all the escaping of multiple quotesFixes #432
Merge Checklist
./gradlew check --info?