1

I am using AWS Codebuild to build infrastructure through terraform. I created this buildspec.yaml file.

version: 0.2

phases: 
  install:
    commands:
      - "apt install unzip -y"
      - "wget https://releases.hashicorp.com/terraform/1.1.8/terraform_1.1.8_linux_arm64.zip"
      - "unzip terraform_1.1.8_linux_arm64.zip"
      - "mv terraform /usr/local/bin/"

  pre_build:
    commands:
      - terraform init

  build:
    commands:
      - terraform plan
      - terraform apply -auto-approve
  post_build:
    commands:
      - echo "terraform apply completed on `date`"

I am able to install terraform successfully but not able to run terraform init and initialize the code. I am getting this error:

[Container] 2022/06/23 10:25:29 Phase complete: INSTALL State: SUCCEEDED
[Container] 2022/06/23 10:25:29 Phase context status code:  Message: 
[Container] 2022/06/23 10:25:29 Entering phase PRE_BUILD
[Container] 2022/06/23 10:25:29 Running command terraform init
/codebuild/output/tmp/script.sh: 4: /codebuild/output/tmp/script.sh: terraform: Exec format error

This is my terraform setup.

terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.0"
    }
  }
  backend "s3" { }
}

I tried different things such changing aws provider version. I turned on and off "privileged" flag on codebuild project. Can someone please suggest what I am doing wrong?

1 Answer 1

1

You are using TF binary for arm64 architectures. Probably you should be using amd64 instead:

      - "wget https://releases.hashicorp.com/terraform/1.1.8/terraform_1.1.8_linux_amd64.zip"
      - "unzip terraform_1.1.8_linux_amd64.zip"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @marcin. I knew I was making stupid mistake
@Shank No problem. So does the error persist after the change to amd64?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.