Search code examples
pythonamazon-web-servicesterraformbitbucketatlassian-sourcetree

terraform not found in bitbucket


So i am trying to create a pipeline on bitbucket. On my local computer, I navigate to the folder cd terraform/environments/devand run terraform init without an issue. However, when I run the test pipeline on bitbucket, it stops on the second action because

bash: terraform: command not found

How can I fix this? I believe I need to install terraform on bitbucket somehow but I am not sure how to do so. Do I use python pip commands? If so, how and why?

image: atlassian/default-image:2

pipelines:
  branches:

    test:
      - step:
          name: 'Navigate to Dev'
          script:
            - cd terraform/environments/dev
          condition:
            changesets:
              includePaths:
                - "terraform/modules"
                - "terraform/environments/dev"
      - step:
          name: 'Initialize Terraform'
          script:
            - terraform init


Solution

  • You need the correct image for your build agent. In this situation, the agent basically only needs terraform installed and accessible:

    image: hashicorp/terraform
    

    This will fix your issue. You can also of course set the tag for the image to your specific version of Terraform.