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

Flag to not override existing tags #217

Closed
eranelbaz opened this issue Mar 20, 2025 · 0 comments · Fixed by #218
Closed

Flag to not override existing tags #217

eranelbaz opened this issue Mar 20, 2025 · 0 comments · Fixed by #218
Assignees
Labels
enhancement New feature or request

Comments

@eranelbaz
Copy link
Member

Is your feature request related to a problem? Please describe.
When using Terratag with existing tags Terratag override my tags
See example
main.tf -

resource "aws_s3_bucket" "example" {
  bucket = "my-tf-test-bucket"

  tags = {
    Name        = "My bucket"
    Environment = "Dev"
  }
}

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

Terratag command -

> /opt/terratag -tags="{\"Name\":\"By Terratag\"}" -rename=false 

Results with this file

resource "aws_s3_bucket" "example" {
  bucket = "my-tf-test-bucket"

  tags = merge({
    "Name"        = "My bucket"
    "Environment" = "Dev"
  }, local.terratag_added_main)
}

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.0"
    }
  }
}

provider "aws" {
  region = "us-east-1"
}

locals {
  terratag_added_main = {"Name"="By Terratag"}
}

Plan results in

      + tags                        = {
          + "Environment"         = "Dev"
          + "Name"                = "By Terratag"
        }
      + tags_all                    = {
          + "Environment"         = "Dev"
          + "Name"                = "By Terratag"
        }

Describe the solution you'd like
Flag that enables a different behaviour of merging tags instead of overriding tags, meaning the plan will result in

      + tags                        = {
          + "Environment"         = "Dev"
          + "Name"                = "My bucket"
        }
      + tags_all                    = {
          + "Environment"         = "Dev"
          + "Name"                = "My bucket"
        }

As Name exists in our Terraform configuration

Describe alternatives you've considered

Additional context

Image
@TomerHeber TomerHeber self-assigned this Mar 20, 2025
@TomerHeber TomerHeber added the enhancement New feature or request label Mar 20, 2025
@TomerHeber TomerHeber moved this from To do to In progress in Ongoing Issues Mar 23, 2025
@github-project-automation github-project-automation bot moved this from In progress to Done in Ongoing Issues Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants