terraform-aws-modules / terraform-aws-s3-bucket

Terraform module to create AWS S3 resources 🇺🇦

Home Page:https://registry.terraform.io/modules/terraform-aws-modules/s3-bucket/aws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default tags are not being applied

mmoreno43 opened this issue · comments

Description

Hello, I am creating an S3 bucket using the terraform module and i have noticed that during creation that the default tags are not created.

If your request is for a new feature, please use the Feature request template.

  • [ X ] ✋ I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

  • Module version [Required]: 3.15.1

  • Terraform version: v1.5.2

  • Provider version(s): v5.8.0

Reproduction Code [Required]

main.tf

module "s3_bucket" {
  source = "terraform-aws-modules/s3-bucket/aws"

  bucket = "somenamehere435354353165156"

  versioning = {
    enabled = true
  }
}

providers.tf

provider "aws" {
    region  = "us-west-2"
    access_key = "x"
    secret_key = "x"
    assume_role {
        role_arn = "arn:aws:iam::x:role/AWSAdministratorAccess"
    }
    default_tags {
        tags = {
            "tag1"              = var.tag1
            "tag2"              = var.tag2
            "tag3"              = var.tag3
            "tag4"              = var.tag4

      }
    }
}

terraform.tfvars

tag1              = "something"
tag2                = "boo"
tag3                = "foo"
tag4                = "doo" 

Steps to reproduce the behavior:

  • terraform init
  • terraform plan
  • terraform apply

Expected behavior

The expected behavior is that the default tags are applied when I create an S3 bucket.

Actual behavior

The actual behavior is that S3 buckets being created without default tags. I have other resources where default tags get applied no problem.

Terminal Output Screenshot(s)

Screenshot 2023-10-23 at 1 25 10 PM
Screenshot 2023-10-23 at 1 26 06 PM

Additional context

I cloned the repo and did some testing of my own. I found that if I added a static tag on line 33 like

tags                = merge(var.tags, {"Name" = "${var.bucket}"})

This would cause the tags to present on the S3 bucket:
Screenshot 2023-10-23 at 1 46 09 PM
Screenshot 2023-10-23 at 1 49 58 PM

Hi @mmoreno43 !

I can't reproduce it with your code, but I recommend you to double-check that var.tag1 and others are not null. In your example, tag4 is set to null, and as a result, it is not added to the bucket.

Please ask follow-up clarification questions on discuss.hashicorp.com and keep this repo to bugs/improvements in the module.