Has anyone out there worked with namespaces in was Codepipeline? I have the reference link from AWS but as always Terraform does not have actual examples. What I want to do is take the output variable from one buildspec in one phase and access those later in my deploy stage. I feel like I am headed down the right path with the syntax I am using below but I keep getting an error regarding the usage of the namespace.
Stage Build: Snippet from the code
action {
run_order = 1
name = "Terraform-Plan"
category = "Build"
owner = "AWS"
provider = "CodeBuild"
version = "1"
input_artifacts = ["CodeWorkspace"]
output_artifacts = ["CodeSource","TerraformPlanFile"]
namespace = "buildvariables"
configuration = {
ProjectName = var.codebuild_project_name
EnvironmentVariables = jsonencode([
{
name = "CONFIG"
value = "#{buildvariables.CONFIG}"
type = "PLAINTEXT"
}
])
}
}
This is the stage where I tried to reference the namespace inside my buildspec_plan file. Not sure i am invoking it correctly:
version: 0.2
env:
variables:
...some variables here
parameter-store:
...some variables here
secrets-manager:
...some variables here
git-credential-helper: yes
exported-variables:
- CONFIG
phases:
install:
commands:
- ...some commands here
pre_build:
- ...some commands here
build:
on-failure: ABORT
commands:
# Import S3 Folder Location Variable
- ...some commands here
- CONFIG=newvariable
I have removed parts of the buildspec which are not relevant to this but my first question is, am I using it correctly because it seems to error out with the following error:
Error creating CodePipeline: InvalidActionDeclarationException: Variables can only reference namespaces produced by an earlier stage or earlier run order in the same stage. The references for the following variables are not valid. StageName=[Plan], ActionName=[Terraform-Plan], ActionConfigurationKey=[EnvironmentVariables], VariableReferenceText=[buildvariables.CONFIG]
I believe i am headed in the right direction but can not find working examples on the terraform usage.
The last part of my question does not relate to my current issue but more with using the variable in another stage once I finally get past the namespace declaration. I plan on invoking this variable in a different build spec known as buildspec_apply by doing the following:
build:
commands:
- cd ${CODEBUILD_SRC_DIR}
- ls
- echo ${buildvariables.CONFIG}
I am obviously using an echo as a sample to verify the variable works but i am not sure this is correct.
Links and tips are welcomed thank you