aws / aws/aws-sam-cli

Bug: Converts stack tag name spaces to underscores

Open
#7,856 6 comments 0 reactions 0 assignees View on GitHub
stage/needs-feedback
Dominant language
Python
Stars
6.7k
Forks
1.2k
Avg merge
1d 10h
Merged PRs (30d)
52

Description

### Description:

In a recent version we were able to add tags in the toml file with spaces in the names -> these tags were added with no modification to resources.

In the current version it replaces spaces with an underscore:

![Image](https://github.com/user-attachments/assets/11b4a9c0-f77d-4a16-b8d0-fd51b22a19e6)

samconfig.toml

```toml
[staging]
[staging.deploy]
[staging.deploy.parameters]
stack_name = "shop-restack-ecs-stack"
region = "eu-central-1"
confirm_changeset = true
capabilities = "CAPABILITY_NAMED_IAM"
tags = 'Env=staging Repo=shop-restack Stack=shop-restack-ecs-stack "Cost Group"=Restack'
```

I have tried with various formats of the tags arg with the same or worse results.

eg:

```toml
tags = "Env=staging Repo=shop-restack Stack=shop-restack-ecs-stack \"Cost Group\"=Restack"
tags = "Env=staging Repo=shop-restack Stack=shop-restack-ecs-stack 'Cost Group'=Restack"
tags = "Env=staging Repo=shop-restack Stack=shop-restack-ecs-stack Cost Group=Restack"
```

Note: spaces are explicitly allowed: https://docs.aws.amazon.com/tag-editor/latest/userguide/best-practices-and-strats.html#:~:text=For%20information%20about%20what%20characters,and%20values%20are%20case%20sensitive.

This change is breaking out cost allocation tags, and breaking our CI scripts.

### Steps to reproduce:

Using 1.132.0 Windows.

1. Add tags to the toml file with a space in a tag name.
2. Deploy with sam deploy

### Observed result:

Replaces the tag with an underscore.

Cost Group -> Cost_Group

### Expected result:

Creates the tag with the same name set in the samconfig.toml file.

### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

1. OS: Windows
2. `sam --version`: 1.132.0
3. AWS region: eu-central-1

```
{
"version": "1.132.0",
"system": {
"python": "3.12.6",
"os": "Windows-10-10.0.19045-SP0"
},
"additional_dependencies": {
"docker_engine": "24.0.7",
"aws_cdk": "Not available",
"terraform": "1.3.5"
},
"available_beta_feature_env_vars": [
"SAM_CLI_BETA_FEATURES",
"SAM_CLI_BETA_BUILD_PERFORMANCE",
"SAM_CLI_BETA_TERRAFORM_SUPPORT",
"SAM_CLI_BETA_RUST_CARGO_LAMBDA"
]
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.