-
Notifications
You must be signed in to change notification settings - Fork 4k
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(cdk): adding tags parameter option to cdk deploy command #2185
feat(cdk): adding tags parameter option to cdk deploy command #2185
Conversation
…w to tag full stacks and their associated resources. fixes #932
I have unmarked the tasks because I suspect that is for the reviewer to complete/not me. Let me know if that is the actual process or not. Thanks! |
I think it would make more sense to apply stack-level tags in code (similar to any other tag) and propagate that information through CDK metadata to the toolkit. This feels like what people would expect and will also be more robust when it comes to multi-stack apps. For example, I would expect this to "Just Work": const app = new App();
const stack1 = new Stack(app, 'stack1', { tags: { foo: 'bar' } });
const stack2 = new Stacl(app, 'stack2');
stack2.node.apply(new Tag('boo', 'bug')); Thew result should be:
@moofish32 I am curious what you think. about 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.
See note
That sounds like the best solution. I just wanted to allow to tag the stacks without needing to use the aws cli. What about providing both options? I will appreciate a few pointers on where the code (area, not specific) to change to allow the changes you requested. :) |
Allow both options sounds good to me. A few pointers: the way a CDK app can communicate something like this to the toolkit is by attaching CDK metadata ( I wonder if we should generalize the The owner question is: if I apply a tag at the stack level, and we know CFN will automatically apply them to all taggable resources, maybe the propagation should work differently. @moofish32, thoughts? |
…ption is provided
Waiting for @moofish32 answer but updated the PR with part of the @eladb requirements. The code changes now does the following:
I have tested that you can add stack tags with the following (been stack a cdk.Stack):
Note: should I change the PR title from parameters to arguments? Might be better wait until there is a more clear knowledge of all the things this does. |
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.
I am expecting the standard Tag
aspect to work seamlessly:
const s = new MyStack(...);
s.node.apply(new cdk.Tag('key, value'));
Agree but I was waiting for confirmation from @moofish32. This was just to confirm I could create a stack, add the "Tag" metadata and that will pass to the CDK part (so a WIP) As far as I understand, by adding the tags on the stack, there is no need to add the tags using the aspects. Does adding both adds a benefit that I don't see? |
…Y as it is more accurate
…Y as it is more accurate
I will see if I can dig around the aspects tomorrow, but only if we are really going to use them. If, by tagging the stack, we tag all the resources, there might be a reason to keep them separate? Just wondering if that is a valid reasoning or we just tag everything (stack and resources with the aspects) Thanks and apologies for my ignorance on this project, 1st typescript work and 1st AWS PR. |
Hi @eladb , Could you check my previous message? I am not sure why we will need to be able to do both types of tagging (all stack vs all the resources minus the stack). Maybe I am missing something in here. I will see if I can have a look at the tag aspects today. Soon I will be on holidays for a few weeks so I will like to wrap this beforehand. Any news also from @moofish32 ? |
Sorry for my delay. The reason I prefer the aspect over the CLI is I don't really want to type out all the tags for the stack on the command line or in bash via Jenkins. Aspects let me commit that to VCS. If the next thing we want is to override that for specific environments the CDK has many methods for that (e.g. context, config object, or json/yaml prop file). Now to @eladb's point a stack does not currently implement We might want to move the tag interface out of CfnResource and on to CfnElement? |
Hi @eladb and @moofish32 Will need some tidy up, but code is not that far from the final solution (IMO). I will appreciate a bit of feedback to see if i am going in the right direction. I have added a few changes but still an early WIP. Prefer to see it functionally working and then do the tests rather than writing all up and then needing to redo it. The current version does support passing the tags as tag properties, applying the tag aspect and passing it with yargs. To notice, if passing via yargs (--tags key=value) that then ignores the aspects one. So now is possible to:
That will produce
and
I have also updated a bit the code (pull from master a couple of days) so hopefully the integration is easier. Thanks |
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.
@@ -375,3 +396,8 @@ export interface SelectedStack extends cxapi.SynthesizedStack { | |||
*/ | |||
originalName: string; | |||
} | |||
|
|||
export interface Tag { |
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.
@rix0rrr -- we are still separating interfaces across the cxapi right?
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.
@rix0rrr , any updates on 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.
Why do we need this as a public API?
https://github.com/IsmaelMartinez can you take a look? |
Oh dear, 1st of all apologies. I will see if I can have a look at it tonight if not tomorrow morning |
@AlexRex I see you're running |
I will continue investigation and others in the open issue. |
@skinny85 is the same version, tested out. @IsmaelMartinez no worries, I just following the other issue. Thanks! |
Is there docs on what the net-net way is to implement these tags? |
Adding tags parameter option to cdk deploy command to allow tagging full stacks and their associated resources.
Now it will be possible to:
That will produce
foo bar
andfii bug
boo bug
It is possible also to override constructor tags with the stack.node.apply.
So doing:
stack1 will have tags
foo newBar
andfii bug
Last, but not least, it is also possible to pass it via arguments (using yargs) as in the following example:
That will produce a stack with tags
foo bar
andmyTag myValue
Important
That will ignore tags provided by the constructor and/or aspects.
Fixes #932
Pull Request Checklist
Notes:
This is my first pull request so I will probably be missing quite a few things. Apologies for this. I will add comments in the lines were we have take some assumptions on how to do it.
I haven't found any tests/readme around the functionality that I am extending so not added any extra tests/documentation. Do point me out to documentation/test cases that should be covered if required.
Manually tested that the following works with a stack with a dynamoDB in it:
[x] Creating a new stack with the --tags argument creates tags for the stack and the dynamoDB resource
[x] Creating a new stack without the --tags argument does not create tags for the stack nor modifies any dynamoDB tags generated with Ability to specify Tags across all resources #1516
[x] Updating a stack with a tags but not changed, correctly detects that there are no changes
[x] Updating a stack with tag values or keys changes, updated the stack tags and their associated resources.
[x] Updating a stack removing tag values, updates the stack removing the removed tags.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.