I
I
Iceforest2021-12-11 19:23:40
GitLab
Iceforest, 2021-12-11 19:23:40

How to delete created resources using terraform via gitlab?

through the terminal it is deleted and created perfectly if you are in a directory with files, and if you use gitlab, it always writes that it deletes 0 resources, but it creates normally. Here is a yaml file. Problems only in the last stage destroy

stages:
  - validate
  - plan
  - apply
  - destroy

before_script:
  - rm -rf .terraform
  - export AWS_ACCESS_KEY_ID
  - export AWS_SECRET_ACCESS_KEY  
  - terraform init

validate:
  stage: validate
  script:    
    - terraform validate
  tags:
    - shell-runner

plan:
  stage: plan
  script:
    - terraform plan -out "planfile"
  dependencies:
    - validate
  artifacts:
    paths:      
      - "planfile"      
  tags:
    - shell-runner
      
apply:
  stage: apply
  script:
    - terraform apply -input=false -auto-approve   
  dependencies:
    - plan  
  tags:
    - shell-runner
  when: manual

destroy:
  stage: destroy
  script:
    - terraform destroy -auto-approve    
  tags:
    - shell-runner
  when: manual

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akelsey, 2021-12-11
@akelsey

1. gitlab-runner user doesn't have access to terraform.tfstate
2. terraform.tfstate file is missing
3. something else we don't know

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question