tfstate를 터치해보세요. - Terraform의 기본.
Terraform은 클라우드 자원의 제작이지만 이 글에서 우리는 로컬 PC에서 자원을 제작하려고 노력하고 있다.
Terraform에 대한 추가 보도는 "Terraform의 기본 및 응용 프로그램"에서 시작하십시오.
개요
Terraform을 사용하려면 tfstate에 대한 이해가 필요합니다.tfstate는 Terraform에서 구축한 리소스를 기록하는 데이터베이스입니다.
이 글은 tfstate의 내용(텍스트 파일)을 확인하거나 tfstate를 삭제할 때의 행동을 확인할 수 있습니다.
골대
terraform에서 tfstate의 위치를 이해합니다.
필요한 물건
이른바 tfstate
terraform에서 의식이 가리키는 것은 원본 코드와 구름 위의 자원이기 때문에 다음과 같은 구조로 구상하기 쉽다.

그러나 실제로는 tfstate라고 불리는 데이터베이스가 있는데 다음과 같은 구조이다.

이러한 구조를 채택한 이유는 메타데이터의 관리와 성능을 위해서다.
원작을 읽고 싶은 사람은 여기서부터 시작하세요.
터치 tfstate
hello만 읽습니다.txt 파일을 생성하는 원본 코드를 사용합니다.
hello.tf
resource "local_file" "helloworld" {
content = "hello world!"
filename = "hello.txt"
file_permission = "0555"
}
init/plan/applly 파일을 만듭니다.
hello.txt 파일이 생성되었습니다.

이번 주인공'terraform.tfstate'파일의 내용을 확인해 보세요.텍스트 파일이기 때문에 좋아하는 편집기에서 확인할 수 있습니다.

원본 코드에 대응하는 텍스트 파일의 설정값, 응용 프로그램이 생성될 때 제공하는 id를 기록합니다.

이 상태에서 tfstate를 삭제하고plan과 apply를 실행하면 어떨까요?
먼저 terraform.tfstate 파일을 삭제합니다.

그리고 플랜을 실행해 보세요.

tfstate가 존재하지 않기 때문에 파일이 생성되지 않은 것으로 판단하고 새 파일의 평면을 표시합니다.
이 상태에서 프로그램을 실행합니다.

파일이 이미 존재합니다. 파일을 만드는 중 오류가 발생했습니다.
이 상태의 tfstate 내용을 확인하면 구축된 자원이 비어 있습니다.

샘플 코드
이 글에서 만든 코드는github에 공개됩니다.
다음에 이거 하자.
Reference
이 문제에 관하여(tfstate를 터치해보세요. - Terraform의 기본.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://zenn.dev/sway/articles/terraform_biginner_tfstate텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)