Terraform v0.11.15-oci
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
}
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.
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]
```
buildspec.ymlterraform applyHi 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!
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!