Skip to content

Manage CloudFromation Stack tags - #17

Merged
linki merged 2 commits into
linki:masterfrom
StarOfService:feature/tags
Nov 2, 2018
Merged

linki merged 2 commits into
linki:masterfrom
StarOfService:feature/tags

Conversation

@spa-87

@spa-87 spa-87 commented Nov 1, 2018

Copy link
Copy Markdown
Contributor

Hello. I've implemented a possibility to manage tags for CloudFormation Stack. This feature is critical for us because we actively use tags for AWS billing reports.
In order to not to make developers assign global tags like environment, we want to define such tags as a command-line argument. But component-specific tags can be received only from a Stack resource. So we've implemented both possibilities:

  • define global tags through command-line arguments
  • define component-specific tags at Stack resource

Comment thread README.md Outdated

Resource-specific tags have precedence over global tags. Thus if a tag is defined at command-line arguments and for a `Stack` resource, the value from the `Stack` resource will be used.

If we run the operation and a `Stack` resource with the describved above examples, we'll see such picture:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: describved

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @davidxjohnson , thank you, fixed. Along with some other texting issues.

@linki

linki commented Nov 2, 2018 •

Copy link
Copy Markdown
Owner

@spa-87 awesome!

I changed it a little to not require to parse json by using StringMapVar. This way you would specify multiple tags via --tag fo=bar --tag wambo=baz and with a line break when using the env var. Also changed some naming things.

Let me know what you think.

@spa-87

spa-87 commented Nov 2, 2018

Copy link
Copy Markdown
Contributor Author

@linki it's ok for me

@linki
linki merged commit 7dd04e7 into linki:master Nov 2, 2018
@linki

linki commented Nov 2, 2018

Copy link
Copy Markdown
Owner

@spa-87 Thank you!

@spa-87

spa-87 commented Nov 6, 2018 •

Copy link
Copy Markdown
Contributor Author

Hi @linki, I've found a bug with the approach based on kingpin. The problem is that StringMapVar uses both : and = symbols as a delimiter: https://github.com/alecthomas/kingpin/blob/master/values.go#L139
Taking into account that regexp is used, it's impossible to escape a symbol.
But a colon symbol is commonly used for complex tags. For example we use tag sos:biliing:environment, AWS beanstalk uses elasticbeanstalk:environment-id, Spotinst uses spotinst:accountId.
Currently, if I provide an argument --tag=sos:biliing:environment=qa, a new tag will have sos key and billing:environment=qa value. Thus it's a common practice which isn't supported by the approach proposed at your commit.
I tried both: the command-line argument and the environment variable. Unfortunately, the result is the same.
If you would like to keep --tag argument as it is now, I propose to add --tag-json argument which was introduced at my initial commit.
What do you think?

@spa-87

spa-87 commented Nov 6, 2018

Copy link
Copy Markdown
Contributor Author

If --tag-json or --tags-json is ok for you, I'll create a new PR with this new argument.

@linki

linki commented Nov 6, 2018

Copy link
Copy Markdown
Owner

Damn 😞 There's one way to make it work by using kingpin's custom parser and building a slightly modified version of the StringMap parser (differs only in the regexp).

I tested it quickly here which needs to be cleaned up but it seems to work:

$ KUBERNETES_CONFIG=~/.kube/config go run ./cmd/cloudformation-operator/main.go --region eu-central-1 --dry-run --debug --tag sos:biliing:environment=qa

ERROR: logging before flag.Parse: E1106 16:40:59.504621   23339 memcache.go:153] couldn't get resource list for external.metrics.k8s.io/v1beta1: <nil>
(*map[string]string)(0xc4202f2180)((len=1) {
 (string) (len=23) "sos:biliing:environment": (string) (len=2) "qa"
})

If you still prefer the JSON approach I'm fine with that, too.

@spa-87 spa-87 mentioned this pull request Nov 7, 2018
@spa-87

spa-87 commented Nov 7, 2018 •

Copy link
Copy Markdown
Contributor Author

It's ok for me to stay with --tag parameter managed by kingpin if the mentioned issue is fixed. This approach is cleaner indeed, I just haven't worked with this library yet.
I've polished your POC and created another pull request. Please review.
I've tested it with my use-cases. It works fine.

Thank you for the fast response.

@linki

linki commented Nov 7, 2018

Copy link
Copy Markdown
Owner

Merged. Thanks for cleaning it up!

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

Successfully merging this pull request may close these issues.

3 participants