hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.74k stars 9.1k forks source link

[Bug]: AWS Codebuild envirnment variable is not set properly #39047

Open rafay-tariq opened 2 weeks ago

rafay-tariq commented 2 weeks ago

Terraform Core Version

1.7.0

AWS Provider Version

5.33.0

Affected Resource(s)

https://registry.terraform.io/providers/hashicorp/aws/4.40.0/docs/resources/codebuild_project.html#environment

resource "aws_codebuild_project" "code_build" {
  name          = var.code_build_project_name
  description   = "CodeBuild project"
  service_role  = aws_iam_role.codebuild_role.arn
  build_timeout = "10"
  source {
    type      = "CODEPIPELINE"
    buildspec = "buildspec.yml"
  }
  artifacts {
    type = "CODEPIPELINE"
  }
  environment {
    compute_type                = "BUILD_GENERAL1_SMALL"
    image                       = "aws/codebuild/amazonlinux2-x86_64-standard:5.0"
    type                        = "LINUX_CONTAINER"
    image_pull_credentials_type = "CODEBUILD"

    environment_variable {
      name  = "S3_BUCKET_NAME"
      value = "some value"
      type  = "PLAINTEXT"
    }

    }
    }

Expected Behavior

Not adding in the aws code build environment. It should create the environment variable in the codebuild stage in aws but it is not creating it.

Actual Behavior

It should create the code build environment variable there.

Relevant Error/Panic Output Snippet

No response

Terraform Configuration Files

# make sure to add the versions so that future versions may not break the code
terraform {
  required_version = ">= 1.7.0"

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = ">= 5.33.0"
    }
  }
}

Steps to Reproduce

resource "aws_codebuild_project" "code_build" {
  name          = var.code_build_project_name
  description   = "CodeBuild project"
  service_role  = aws_iam_role.codebuild_role.arn
  build_timeout = "10"
  source {
    type      = "CODEPIPELINE"
    buildspec = "buildspec.yml"
  }
  artifacts {
    type = "CODEPIPELINE"
  }
  environment {
    compute_type                = "BUILD_GENERAL1_SMALL"
    image                       = "aws/codebuild/amazonlinux2-x86_64-standard:5.0"
    type                        = "LINUX_CONTAINER"
    image_pull_credentials_type = "CODEBUILD"

    environment_variable {
      name  = "S3_BUCKET_NAME"
      value = "some value"
      type  = "PLAINTEXT"
    }

    # dynamic "environment_variable" {
    #   for_each = var.codebuild_environment_variables
    #   content {
    #     name  = environment_variable.key
    #     value = environment_variable.value
    #     type  = "PLAINTEXT"
    #   }
    # }
  }
  logs_config {
    cloudwatch_logs {
      group_name  = format("/codebuild/%s", var.AWS_CODE_PIPELINE_NAME)
      stream_name = format("/codebuild/%s", var.AWS_CODE_PIPELINE_NAME)
    }
  }
}

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

None

github-actions[bot] commented 2 weeks ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue