brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Aug 08. 2023

12. 5주차- 테라폼-협업-테라폼 클라우드 잠금 기능

<1> 프로비저닝 수행 시 동일한 State 접근 못하게 잠금 → State 마지막 상태에 대한 무결성 확보

<2> 삭제




<1> 프로비저닝 수행 시 동일한 State 접근 못하게 잠금 → State 마지막 상태에 대한 무결성 확보



1

Jerry가 프로비저닝 실행 시 변경 사항이 발생하도록 코드를 수정한다고 가정하여, null_resource에 정의한 내용이 항상 수행되도록 trigger를 추가함

trigger에 timestamp() 함수를 지정하면 테라폼 프로비저닝 실행마다 다른 값이 저장되므로 항상 변경이 유발함


2

jerry 루트 모듈에서 main.tf 파일 코드 변경 및 실행 - 주석 해제



resource "null_resource" "configure-cat-app" {

  depends_on = [aws_eip_association.hashicat]


  triggers = {

    build_number = timestamp()

  }



terraform apply -var=prefix=dev

...

Enter a value: <대기>



  # null_resource.configure-cat-app must be replaced

-/+ resource "null_resource" "configure-cat-app" {

      ~ id       = "8047617178209046850" -> (known after apply)

      + triggers = { # forces replacement

          + "build_number" = (known after apply)

        }

    }




3


신규 터미널에서 tom 루트 모듈에서 실행


cd 

cd terraform-aws-collaboration-tom


terraform apply -var=prefix=dev

│ Error: Error acquiring the state lock

│ 

│ Error message: workspace already locked (lock ID: "gasida-org/terraform-aws-collaboration")

│ Lock Info:

│   ID:        4869b6f7-8c57-6f50-857c-9730999b8b2a

│   Path:      

│   Operation: OperationTypeApply

│   Who:       gasida@seojonghoui-MacBookPro.local

│   Version:   1.5.1

│   Created:   2023-08-06 09:01:03.131157 +0000 UTC

│   Info:      

│ 

│ 

│ Terraform acquires a state lock to protect the state from being written

│ by multiple users at the same time. Please resolve the issue above and try

│ again. For most commands, you can disable locking with the "-lock=false"

│ flag, but this is not recommended.




2

 TFC Workspace 에 State 확인



4

jerry 루트 모듈에서 실행


terraform apply -var=prefix=dev

...

Enter a value: yes


Apply complete! Resources: 1 added, 0 changed, 1 destroyed.

Outputs:



6

TFC Workspace 에 State → [Changes in this version] 에서 변경 사항 확인


unlock

상태 변경이 하나더 추가 됨





<2>  삭제


1

terraform destroy -auto-approve -var=prefix=dev


Destroy complete! Resources: 12 destroyed.


2

TFC에 워크스페이스 삭제 : Setting → Destruction and Deletion 클릭 후 삭제


3

Github Repo 삭제 : terraform-aws-collaboration → Setting → Delete this repository


4

로컬 디렉터리 삭제 : terraform-aws-collaboration-tom , terraform-aws-collaboration-jerry



5

AWS 콘솔에서 리소스 확인후 삭제




휴식

https://vclock.kr/timer/#countdown=00:10:00&enabled=0&seconds=0&sound=xylophone&loop=1



다음과정

https://brunch.co.kr/@topasvga/3407


전체 보기

https://brunch.co.kr/@topasvga/3347

다음은 주말 CloudNet 테라폼 스터디 내용 참고하여  정리한 부분입니다.

https://gasidaseo.notion.site/gasidaseo/CloudNet-Blog-c9dfa44a27ff431dafdd2edacc8a1863  



감사합니다.



매거진의 이전글 11. 5주 차 - 테라폼-협업,공유 저장소-2022

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari