Skip to content
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

How to add tags with sam deploy #7050

Open
ajithkumar999 opened this issue May 10, 2024 · 4 comments
Open

How to add tags with sam deploy #7050

ajithkumar999 opened this issue May 10, 2024 · 4 comments
Labels
area/deploy sam deploy command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days type/question

Comments

@ajithkumar999
Copy link

Hello,
we are using SAM to deploy our cloud formation template, we are passing --tags along with the SAM deploy command to add tags for all the resources present in the template in one go.
I noticed a few tags were missing on the API gateway resource level, I want to reassign the tags through SAM deploy only, I added a new tag in the SAM deploy command, but it added only that particular tag. it didn’t add the old tags.
my sam deploy command:
sam deploy \ --template-file template.yml \ --stack-name $ENV_NAME-$APP_NAME \ --capabilities CAPABILITY_NAMED_IAM \ --region $AWS_REGION \ --role-arn $CFN_ROLE_ARN \ --parameter-overrides Env=$ENV_NAME BuildArtifactName=$GO_PIPELINE_LABEL Application=$APP_NAME LogLevel=$log_level \ --s3-bucket <bucket_name> \ --s3-prefix $APP_NAME \ --no-fail-on-empty-changeset \ --tags \ env=$ENV_NAME \ dept=abc \ squad=abc \ product=abc \ audience=abc \ client_code=abc \ sensitive_data=true \ Application=$APP_NAME \ team=abc --> added newly
but only a few tags were present currently, I want to re-add all these tags back to the resource

@ajithkumar999 ajithkumar999 added the stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. label May 10, 2024
@hawflau
Copy link
Contributor

hawflau commented May 11, 2024

Hi @ajithkumar999 thanks for raising the issue.

Did you include all your existing tags and new tags in the --tags flag?
In my experiment, when I only added new tags and didn't keep any existing tags under --tags, the deployed result is existing tags got removed. If I keep existing tags under --tags and add new tags, the deployed resource contains both existing tags and new tags.

Aside, I'd suggest you to use samconfig to keep your tags. You can define tags as a list instead of a concatenated string and also be able to your existing tags in the config file

example:

[default.deploy.parameters]
capabilities = "CAPABILITY_IAM"
confirm_changeset = true
resolve_s3 = true
tags = [
    "aaa=ddd",
    "bbb=ccc",
]

@hawflau hawflau added type/question area/deploy sam deploy command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days and removed stage/needs-triage Automatically applied to new issues and PRs, indicating they haven't been looked at. labels May 11, 2024
@ajithkumar999
Copy link
Author

Hi @hawflau, thanks for looking into this issue
Here my concern is somehow my old tags were missing from the resources, I want to add them back again to the resources, if I add a new tag in the --tags param, it only adds the new tag to the resource, it's not adding the old tags
Please check the below image, only 3 tags were present for the resource, but my sam deploy command has 9 tags init, the team tag which I added newly, how can I add my old tags to the resource?

Screenshot 2024-05-13 at 11 51 49 AM Thanks

@mndeveci
Copy link
Contributor

@ajithkumar999

I've tried to reproduce the issue you mentioned. I've created stack with a=1 and b=2 tags. And then I've added c=3 and d=4 tags. After the second deployment I can see all the tags which I've added there. Can you provide more details of your issue?

image

@ajithkumar999
Copy link
Author

Hello @mndeveci
Thanks for looking into this
let's say the stack has lambda and API gateway resources with these tags a=1 b=2 c=3 and d=4.
I've manually deleted the tags c=3 and d=4 in the API gateway resource, and lambda has all the required tags.
If I try to re-deploy the stack with the same tags using SAM it's not adding back, if I've modified the tag in the SAM deploy command like d=5 then it will add it back but lambda tags also will get affected.
How can I add the deleted tags back to the resources without affecting the other resources in the stack with the sam deploy command?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deploy sam deploy command blocked/close-if-inactive Blocked for >14 days with no response, will be closed if still inactive after 7 days type/question
Projects
None yet
Development

No branches or pull requests

3 participants