-
Notifications
You must be signed in to change notification settings - Fork 44
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
Feat: allow using terratag as a validation tool - add dryrun #179
Conversation
@@ -59,6 +59,19 @@ func HasResourceTagFn(resourceType string) bool { | |||
return resourceTypeToFnMap[resourceType] != nil | |||
} | |||
|
|||
func HasTags(args TagBlockArgs) (bool, error) { |
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.
Setting to beta because this function may need to handle more use-cases.
Basically just checks that the resource has tags.
} | ||
|
||
func validate(args Args) error { | ||
if args.Tags == "" { | ||
if args.Tags == "" && !args.DryRun { |
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.
adding tags is irrelevant for a dryrun.
taggedResources uint32 | ||
totalFiles uint32 | ||
taggedFiles uint32 | ||
untaggedResources uint32 // For dryrun. |
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.
counts the number of untagged resources (if after dryrun there are still untagged resources - exit 1 is returned).
} | ||
|
||
counters := tagDirectoryResources(taggingArgs) | ||
log.Print("[INFO] Summary:") | ||
log.Print("[INFO] Tagged ", counters.taggedResources, " resource/s (out of ", counters.totalResources, " resource/s processed)") | ||
log.Print("[INFO] In ", counters.taggedFiles, " file/s (out of ", counters.totalFiles, " file/s processed)") | ||
if args.DryRun { |
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.
different messages for each mode.
} | ||
|
||
if !args.DryRun { | ||
hclMap, err := toHclMap(args.Tags) |
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.
only valid when there are tags... not relevant for dryrun.
@@ -95,6 +95,7 @@ func TestTerragruntWithCache(t *testing.T) { | |||
itShouldRunTerratagTerragruntMode(out, g) | |||
itShouldRunTerragruntValidate(out, g) | |||
itShouldGenerateExpectedTerragruntTerratagFiles(entryDir, g) | |||
itShouldRunTerratagTerragruntModeDryRun(out, g) |
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.
updating the tests to make run a dry run at the end and verify it's resolved.
I'm not running a dry run at the beginning because some tests are not expected to be tagged.
@TomerHeber could you please add some screenshots here or something like that so I could understand the flow and it how it looks like to the user? |
|
talked in Slack - will change to verifing for specific tags - If tags are passed it will check for these tags... otherwise just in general... |
@TomerHeber what's the status here? |
@avnerenv0 - I have been busy with the provider. I will get back to it when things cool down on the provider side. |
@TomerHeber it's Passover soon I have to close this :) |
not deleting the branch though |
Added a new dryrun mode that checks if all resources are tagged.
If a resource isn't tagged, it returns 1 exit code.
resolves #178