Skip to content

Commit

Permalink
Revert "revert tags generator comparator change"
Browse files Browse the repository at this point in the history
This reverts commit 33de098.
  • Loading branch information
johnsonaj committed Sep 26, 2024
1 parent 7ee33f8 commit 92e2a00
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 373 deletions.
62 changes: 27 additions & 35 deletions internal/generate/tags/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

//go:build generate
// +build generate

package main

import (
Expand Down Expand Up @@ -36,7 +39,6 @@ var (
serviceTagsSlice = flag.Bool("ServiceTagsSlice", false, "whether to generate service tags for slice")
untagInNeedTagType = flag.Bool("UntagInNeedTagType", false, "whether Untag input needs tag type")
updateTags = flag.Bool("UpdateTags", false, "whether to generate UpdateTags")
updateTagsForResource = flag.Bool("UpdateTagsForResource", false, "whether to generate UpdateTagsForResource")
updateTagsNoIgnoreSystem = flag.Bool("UpdateTagsNoIgnoreSystem", false, "whether to not ignore system tags in UpdateTags")
waitForPropagation = flag.Bool("Wait", false, "whether to generate WaitTagsPropagated")

Expand Down Expand Up @@ -79,9 +81,9 @@ var (
untagInTagsElem = flag.String("UntagInTagsElem", "TagKeys", "untagInTagsElem")
untagOp = flag.String("UntagOp", "UntagResource", "untagOp")
updateTagsFunc = flag.String("UpdateTagsFunc", defaultUpdateTagsFunc, "updateTagsFunc")
updateTagsForResourceFunc = flag.String("UpdateTagsForResourceFunc", "updateTagsForResource", "updateTagsForResourceFunc")
waitTagsPropagatedFunc = flag.String("WaitFunc", defaultWaitTagsPropagatedFunc, "waitFunc")
waitContinuousOccurence = flag.Int("WaitContinuousOccurence", 0, "ContinuousTargetOccurence for Wait function")
waitFuncComparator = flag.String("WaitFuncComparator", "Equal", "waitFuncComparator")
waitDelay = flag.Duration("WaitDelay", 0, "Delay for Wait function")
waitMinTimeout = flag.Duration("WaitMinTimeout", 0, `"MinTimeout" (minimum poll interval) for Wait function`)
waitPollInterval = flag.Duration("WaitPollInterval", 0, "PollInterval for Wait function")
Expand All @@ -108,14 +110,13 @@ func usage() {
}

type TemplateBody struct {
getTag string
header string
listTags string
serviceTagsMap string
serviceTagsSlice string
updateTags string
updateTagsForResource string
waitTagsPropagated string
getTag string
header string
listTags string
serviceTagsMap string
serviceTagsSlice string
updateTags string
waitTagsPropagated string
}

func newTemplateBody(version int, kvtValues bool) *TemplateBody {
Expand All @@ -133,25 +134,23 @@ func newTemplateBody(version int, kvtValues bool) *TemplateBody {
case sdkV2:
if kvtValues {
return &TemplateBody{
getTag: "\n" + v2.GetTagBody,
header: v2.HeaderBody,
listTags: "\n" + v2.ListTagsBody,
serviceTagsMap: "\n" + v2.ServiceTagsValueMapBody,
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
updateTags: "\n" + v2.UpdateTagsBody,
updateTagsForResource: "\n" + v2.UpdateTagsForResourceBody,
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
getTag: "\n" + v2.GetTagBody,
header: v2.HeaderBody,
listTags: "\n" + v2.ListTagsBody,
serviceTagsMap: "\n" + v2.ServiceTagsValueMapBody,
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
updateTags: "\n" + v2.UpdateTagsBody,
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
}
}
return &TemplateBody{
getTag: "\n" + v2.GetTagBody,
header: v2.HeaderBody,
listTags: "\n" + v2.ListTagsBody,
serviceTagsMap: "\n" + v2.ServiceTagsMapBody,
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
updateTags: "\n" + v2.UpdateTagsBody,
updateTagsForResource: "\n" + v2.UpdateTagsForResourceBody,
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
getTag: "\n" + v2.GetTagBody,
header: v2.HeaderBody,
listTags: "\n" + v2.ListTagsBody,
serviceTagsMap: "\n" + v2.ServiceTagsMapBody,
serviceTagsSlice: "\n" + v2.ServiceTagsSliceBody,
updateTags: "\n" + v2.UpdateTagsBody,
waitTagsPropagated: "\n" + v2.WaitTagsPropagatedBody,
}
default:
return nil
Expand Down Expand Up @@ -211,13 +210,12 @@ type TemplateData struct {
UntagInTagsElem string
UntagOp string
UpdateTagsFunc string
UpdateTagsForResource bool
UpdateTagsForResourceFunc string
UpdateTagsIgnoreSystem bool
WaitForPropagation bool
WaitTagsPropagatedFunc string
WaitContinuousOccurence int
WaitDelay string
WaitFuncComparator string
WaitMinTimeout string
WaitPollInterval string
WaitTimeout string
Expand Down Expand Up @@ -372,9 +370,9 @@ func main() {
UntagInTagsElem: *untagInTagsElem,
UntagOp: *untagOp,
UpdateTagsFunc: *updateTagsFunc,
UpdateTagsForResourceFunc: *updateTagsForResourceFunc,
UpdateTagsIgnoreSystem: !*updateTagsNoIgnoreSystem,
WaitForPropagation: *waitForPropagation,
WaitFuncComparator: *waitFuncComparator,
WaitTagsPropagatedFunc: *waitTagsPropagatedFunc,
WaitContinuousOccurence: *waitContinuousOccurence,
WaitDelay: formatDuration(*waitDelay),
Expand Down Expand Up @@ -432,12 +430,6 @@ func main() {
}
}

if *updateTagsForResource {
if err := d.WriteTemplate("updatetagsforresource", templateBody.updateTagsForResource, templateData); err != nil {
g.Fatalf("generating file (%s): %s", filename, err)
}
}

if *waitForPropagation {
if err := d.WriteTemplate("waittagspropagated", templateBody.waitTagsPropagated, templateData); err != nil {
g.Fatalf("generating file (%s): %s", filename, err)
Expand Down
3 changes: 1 addition & 2 deletions internal/generate/tags/templates/v2/update_tags_body.gtpl
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ func {{ .UpdateTagsFunc }}(ctx context.Context, conn {{ .ClientType }}, identifi

{{ if .WaitForPropagation }}
if len(removedTags) > 0 || len(updatedTags) > 0 {
check := checkFunc(ctx, conn, newTags, identifier, optFns...)
if err := {{ .WaitTagsPropagatedFunc }}(ctx, newTags, check); err != nil {
if err := {{ .WaitTagsPropagatedFunc }}(ctx, conn, identifier, newTags, optFns...); err != nil {
return fmt.Errorf("waiting for resource (%s) tag propagation: %w", identifier, err)
}
}
Expand Down
195 changes: 0 additions & 195 deletions internal/generate/tags/templates/v2/update_tags_for_resource_body.gtpl

This file was deleted.

3 changes: 0 additions & 3 deletions internal/generate/tags/templates/v2/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,5 @@ var ServiceTagsSliceBody string
//go:embed update_tags_body.gtpl
var UpdateTagsBody string

//go:embed update_tags_for_resource_body.gtpl
var UpdateTagsForResourceBody string

//go:embed wait_tags_propagated_body.gtpl
var WaitTagsPropagatedBody string
Loading

0 comments on commit 92e2a00

Please sign in to comment.