Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Terraform pipeline and state lock problem

mc84
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
July 2, 2024

I created a bitbucket pipeline, that looks like this. A first step will simply do:

 - /bin/sh scripts/createDeployConfigFile.sh
- terraform init -backend-config=./deploy.conf
- terraform validate
- terraform plan -out=tfplan

The second step is triggered manually and (should) simply do:

- terraform apply tfplan

Have in mind that the first step exports the following artifacts:
artifacts:
- tfplan
- terraform.tfstate
- .terraform/**
- .terraform.lock.hcl
and that the above commnads correctly edploy the environment when executed in my workstation (with the same backend).
Any one had a similar issue? As a workaround I issued terraform init -backend-config=./deploy.conf even in the second step, and this resolved the problem, but I'm feeling uncomfortable because some of the steps and artiffacts are executed two times.

1 answer

1 vote
Theodora Boudale
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 3, 2024

Hi @mc84 and welcome to the community!

If you run this Pipelines build on Atlassian's infrastructure, every step of the build runs on a different Docker container. For every step of the build, a Docker container starts. The repo is cloned in that container (unless you have disabled cloning), and then the commands of that step's script are executed. When the step finishes, the Docker container gets destroyed.

I'm not familiar with terraform, but is it possible that the commands in the first step are doing some additional tasks other than generating the files you have defined as artifacts?

When you run these commands on your workstation, I'm assuming that you execute them in the same environment. A second step in a Pipelines build runs in a separate Docker container, so in a different enviornment than the first step. I suggest looking into the exact tasks performed by the command you need to rerun in the second step, and maybe reach out to terraform's community or support team.

Kind regards,
Theodora

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
TAGS
AUG Leaders

Atlassian Community Events