How to inject a value from GitHub workflow into Terraform?

Viewed 187

I have wrote a GitHub action workflow which creates a new repository using a hardcoded repository name. But now when I want to enhance it by asking the developer for a repository name user input

I'm having a hard time to inject the value from GitHub into Terraform. The working part of it is the pipeline does get the value inputed by the developer. this is how it's configured enter image description here enter image description here

On the terraform side I have the name as environment variable enter image description here

That is the error i'm getting enter image description here

Document used to create that workflow:

2 Answers

In order to set env variable, sharable in the same job, you should redirect the oputput to the $GITHUB_ENV variable, as example:

echo "TF_VAR_INPUT_REPOSITORY_NAME=${{ github.event.inputs.repository-name }}" >> $GITHUB_ENV

See more about Naming conventions for environment variables here in the doc

I did configured the run command to execute: echo "TF_VAR_INPUT_REPOSITORY_NAME=${{ github.event.inputs.repository-name }}" >> $GITHUB_ENV

how to declare it in the root module of terraform

Related