Terraform-provider-aws: Referencing namespace variable in CodePipeline action fails

Created on 26 Feb 2020  ·  3Comments  ·  Source: hashicorp/terraform-provider-aws

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

Terraform v0.11.15-oci

Affected Resource(s)

  • aws_codepipeline

Terraform Configuration Files

resource "aws_codepipeline" "build_push_deploy" {

  # omitted code

  stage {
    name = "BuildAndPush"

    action {
      name             = "BuildDockerImages"
      category         = "Build"
      owner            = "AWS"
      provider         = "CodeBuild"
      input_artifacts  = ["source"]
      output_artifacts = ["build"]
      version          = "1"
      namespace        = "BuildVariables" # <----- this is actually not in the code and it's done manually in console as this PR is not yet merged in the AWS provider https://github.com/terraform-providers/terraform-provider-aws/issues/11418

      configuration = {
        ProjectName          = "build"

        EnvironmentVariables = <<EOF
[{"name":"SERVICES","value":"test","type":"PLAINTEXT"}]
EOF
      }

      run_order = 1
    }

    action {
      name            = "PushToECR"
      category        = "Build"
      owner           = "AWS"
      provider        = "CodeBuild"
      input_artifacts = ["source", "build"]
      version         = "1"

      configuration = {
        ProjectName   = "push"
        PrimarySource = "source"

        EnvironmentVariables = <<EOF
[{"name":"SERVICES","type":"PLAINTEXT","value":"#{BuildVariables.SERVICES}"}]
EOF
      }

      run_order = 2
    }
  }

# omitted code

}

Expected Behavior

Referencing a namespace variable should proceed even if it's not declared in previous steps. For example it can be defined only in the buildspec.yml file and then there is no record of existence of the namespace variable before running the pipeline.

env:
  variables:
     SERVICES: "service1"
  exported-variables:
    - SERVICES

Configuration in the AWS Console allows referencing variables that are known only after running previous CodePipeline Actions.

Actual Behavior

Before running the Plan, the variable namespace is already defined in the AWS Console. screenshot

As you can see in the Plan - Terraform is not removing that settings. The only change that I am adding is referencing that variable from previous step as described in the AWS docs.

Terraform plan

Terraform will perform the following actions:

  ~ aws_codepipeline.build_push_deploy
      stage.1.action.1.configuration.%:                    "2" => "3"
      stage.1.action.1.configuration.EnvironmentVariables: "" => "[{\"name\":\"SERVICES\",\"type\":\"PLAINTEXT\",\"value\":\"#{BuildVariables.SERVICES}\"}]\n"

Error output

```aws_codepipeline.build_push_deploy: Modifying... (ID: mallpay-be-accept-build-push-deploy-v2)
stage.1.action.1.configuration.%: "2" => "3"
stage.1.action.1.configuration.EnvironmentVariables: "" => "[{\"name\":\"SERVICES\",\"type\":\"PLAINTEXT\",\"value\":\"#{BuildVariables.SERVICES}\"}]n"

Error: Error applying plan:

1 error occurred:
* aws_codepipeline.build_push_deploy: 1 error occurred:
* aws_codepipeline.build_push_deploy: [ERROR] Error updating CodePipeline (mallpay-be-accept-build-push-deploy-v2): InvalidActionDeclarationException: Valid format for a pipeline execution variable reference is a namespace and a key separated by a period (.). The following pipeline execution variables are referencing a namespace that does not exist.
StageName=[BuildAndPush], ActionName=[PushToECR], ActionConfigurationKey=[EnvironmentVariables], VariableReferenceText=[BuildVariables.SERVICES]
```

Steps to Reproduce

  1. In CodePipeline action in AWS Console - manually create a variable namespace (until this is merged https://github.com/terraform-providers/terraform-provider-aws/issues/11418)
  2. Terraform won't try to remove the namespace - as it doesn't know about that field. screenshot
  3. Define the variable in the Action Environment / buildspec.yml
  4. run terraform apply

References

  • #11418
needs-triage serviccodepipeline

Most helpful comment

This has been released in version 2.59.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

All 3 comments

Hi folks 👋 Sorry for the confusing behavior here. We have merged in support for stage action namespaces, which hopefully should alleviate problems here. It will release with version 2.59.0 of the Terraform AWS Provider, later this week.

If you are still having trouble after that release, please reach out in a new GitHub issue and we will take a fresh look. Thanks so much.

This has been released in version 2.59.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

Was this page helpful?
0 / 5 - 0 ratings