I have a CI/CD pipeline on bitbucket. I want to run some terraform commands. Currently, I get an error in the 3rd "Select workspace" step.
image: hashicorp/terraform
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
- step:
name: 'Select workspace'
script:
- terraform workspace select default
│ Error: Backend initialization required, please run "terraform init"
│
│ Reason: Unsetting the previously set backend "s3"
even though the terraform init command ran successfully in the previous step. This could be because my current pipeline is not able to access S3/AWS.
There is already a provider.tf file in terrafrom/environments/dev
provider "aws" {
region = "eu-central-1"
assume_role {
role_arn = "arn:aws:iam::123:role/terraform-access"
external_id = "abc"
}
}
terraform {
required_version = "> 1.0"
backend "s3" {
key = "dev.tfstate"
region = "eu-central-1"
bucket = "abc.4flow-vista.com"
role_arn = "arn:aws:iam::123:role/terraform-access"
external_id = "abc"
}
}
but i am not referencing this file anywhere in my bitbucket-pipelines.yml. Do I need to? If so, how and where?