Hi,
I have set up a simple Terraform Gitlab ci pipeline using the following configuration. Some reason it’s failing with below error. Can someone please tell what is root cause of this error?
ws_instance.test_web: Error launching source instance: UnauthorizedOperation: You are not authorized to perform this operation. Encoded authorization failure message: t2z5mCYK7CJSGU7MTZYRqRGICoHGVIRNo3VPO1nXzoZQHbFTB2WIJc3ZQKfZ8AfC3ObMRtDZJ50yjzRwKXokSKgCuWUiaRFtrVDJ5Nnw49cHwKQzRXs
.gitlab-ci.yml
image:
name: hashicorp/terraform:light
entrypoint:
- ‘/usr/bin/env’
- ‘PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin’
Default output file for Terraform plan
variables:
PLAN: plan.tfplan
cache:
paths:
- .terraform
before_script:
- terraform --version
- terraform init -backend=true -get=true -input=false
stages:
- validate
- build
- deploy
validate:
stage: validate
script:
- terraform validate
plan:
stage: build
script:
- terraform plan -out=$PLAN
artifacts:
name: plan
paths:
- $PLAN
Separate apply job for manual launching Terraform as it can be destructive
action.
apply:
stage: deploy
script:
- terraform apply -input=false $PLAN
dependencies:
- plan
# when: manual
only:
- master
main.tf
resource “aws_instance” “test_web” {
ami = “ami-0aff30363d302d23a”
instance_type = “t2.micro”
tags {
Name = “test”
}
}
provider.tf
provider “aws” {
region = “ap-southeast-2”
}
NOTE: access_key, secret_key I have simply placed in Gitlab secret variable