๋กœ์ผ“๐Ÿพ
article thumbnail
๋ฐ˜์‘ํ˜•

 

 

 

ํ…Œ๋ผํผ์„ ์ฒ˜์Œ ์‹œ์ž‘ํ•˜๋ฉด ํ—ท๊ฐˆ๋ฆฌ๋Š” ๋ช…๋ น์–ด ์˜ต์…˜์ด ์žˆ์Šต๋‹ˆ๋‹ค.

 

๋ฐ”๋กœ terraform init ๋ช…๋ น์–ด์˜ -migrate-state ์™€ -reconfigure ์ฃ .

 

๋ณดํ†ต backend ๊ตฌ์„ฑ์„ ๋ณ€๊ฒฝํ•˜๋ฉด ํ•ด๋‹น ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋ผ๋Š” ๋ช…๋ น์–ด๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

terraform init

 

๋กœ๊ทธ์—์„œ -migrate-state ์™€ -reconfigure ์— ๋Œ€ํ•œ ์„ค๋ช…์ด ๋‚˜์™€์žˆ์ง€๋งŒ ๋”ฑํžˆ ์™€๋‹ฟ์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค.

tfstate ์˜ ๋ฐฉํ–ฅ์„ฑ์„ ์ขŒ์ง€์šฐ์ง€ ํ•˜๋Š” ์˜ต์…˜์ด๊ธฐ ๋•Œ๋ฌธ์— ์ž˜๋ชป ์ผ๋‹ค๊ฐ„ ์ธํ”„๋ผ๊ฐ€ ๊ผฌ์ผ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

 

์˜ˆ๋ฅผ ๋“ค์–ด, ๋ถ„๋ช… ๋ณ€๊ฒฝ(0 to change)ํ•˜๋Š” ๊ฑด๋ฐ ์ƒˆ๋กญ๊ฒŒ(1 to add) ์ƒ์„ฑํ•œ๋‹ค๋Š” ๋ฌธ๊ตฌ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์ฃ .

์ƒˆ๋กญ๊ฒŒ ์ƒ๊ธฐ๋ฉด ์•ˆ๋˜๋Š”๋ฐ...

 

์ด๋Ÿฐ ๊ฒฝ์šฐ๋Š” ๋ณดํ†ต backend ๊ตฌ์„ฑ์„ ๋ณ€๊ฒฝํ•˜๊ณ , -reconfigure ๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค.

 

์˜ˆ์ œ์—ฌ์„œ ๋”ฑ ํ•˜๋‚˜์˜ state ๋งŒ ์กด์žฌํ•˜์ง€๋งŒ ์‹ค์ œ ์ธํ”„๋ผ ํ™˜๊ฒฝ์ด๋ผ๋ฉด ์ƒ๋‹นํžˆ ๊ท€์ฐฎ์•„์ง€๋Š” ์ผ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์ฃ . (import block ๊ฐ™์€..)

terraform state list

 

 

๊ทธ๋Ÿผ ์ด์ œ ๊ฐ ์˜ต์…˜์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ณ , ์–ธ์ œ ์–ด๋–ค ์˜ต์…˜์„ ์‚ฌ์šฉํ•˜๋Š”์ง€ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

 

๋ ›์ธ ๋‘๋”์ฝ”๋“œ~

 

 

-reconfigure


 

๋‹ค์‹œ ํ•œ๋ฒˆ ๋ง์”€๋“œ๋ฆฌ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด backend ๊ตฌ์„ฑ์„ ๋ณ€๊ฒฝํ•˜๋ฉด -migrate-state ์™€ -reconfigure ๊ด€๋ จ ๋กœ๊ทธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

terraform {
  required_version = ">= 1.5.0"

  backend "local" {
    path = "./tfstates/random-pet.tfstate" #-- ์ด ๊ฐ’์„ ๋ณ€๊ฒฝํ–ˆ์„ ๊ฒฝ์šฐ ๋ฐœ์ƒ
  }

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.0"
    }
  }
}
terraform block ์˜ backend ๊ตฌ์„ฑ์„ ๋ฐ”๊พธ๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฉ”์‹œ์ง€๋ฅผ ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 

-reconfigure ์„ค๋ช…

 

๋ฒˆ์—ญํ•ด๋ณด์ž๋ฉด "state(tfstate ํŒŒ์ผ) ์— ๋Œ€ํ•œ ๋ณ€๊ฒฝ ์—†์ด ํ˜„์žฌ์˜ ์„ค์ • ๊ฐ’์„ ์ €์žฅํ•˜๊ณ  ์‹ถ์œผ๋ฉด -reconfigure ๋ฅผ ์‚ฌ์šฉํ•ด๋ผ" ์ž…๋‹ˆ๋‹ค.

 

๋ฌด์Šจ ๋ง์ธ์ง€ ๋Š๋‚Œ์€ ์˜ค๋‚˜ ํ™•์‹คํžˆ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.. (์ €๋งŒ ๊ทธ๋Ÿฐ ๊ฑฐ์ผ ์ˆ˜๋„ ใ…œใ…œ)

 

ํ•œ๋ฒˆ ์‹ค์Šต์œผ๋กœ ์ž์„ธํžˆ ์ดํ•ดํ•ด๋ณด์ฃ !

 

์ฝ”๋“œ๋Š” ๊ฐ„๋‹จํ•œ terraform block ๊ณผ random ๋ชจ๋“ˆ์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. 

terraform {
  required_version = ">= 1.5.0"

  backend "local" {
    path = "./tfstates/random-pet.tfstate"
  }

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.0"
    }
  }
}

resource "random_pet" "server" {}

 

 

terraform init ์„ ํ†ตํ•ด ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ๊ณผ ๋ชจ๋“ˆ ๋“ฑ์„ ์„ธํŒ…ํ•ด์ค๋‹ˆ๋‹ค.

.terraform

 

terraform init ์„ ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด .terraform/terraform.tfstate ์— ๋ฐฑ์—”๋“œ์™€ ๋ชจ๋“ˆ ๊ด€๋ จ๋œ ์ •๋ณด๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” ํŒŒ์ผ์ด ์ƒ์„ฑ๋ฉ๋‹ˆ๋‹ค.

ํŒŒ์ผ ๋‚ด์šฉ์„ ๋ณด๋ฉด backend ๊ตฌ์„ฑ์ด ๋˜์–ด ์žˆ๋Š”๋ฐ, ํ˜„์žฌ ./tfstates/random-pet.tfstate ๋ฅผ ๋ฐ”๋ผ๋ณด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

{
    "version": 3,
    "serial": 1,
    "lineage": "ab7ad77f-6b5b-a79a-496e-7d244bc1085a",
    "backend": {
        "type": "local",
        "config": {
            "path": "./tfstates/random-pet.tfstate", #-- ์—ฌ๊ธฐ
            "workspace_dir": null
        },
        "hash": 3115818295
    },
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {},
            "depends_on": []
        }
    ]
}

 

์ดํ›„ ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์„ ๋ณ€๊ฒฝํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

terraform {
  required_version = ">= 1.5.0"

  backend "local" {
    path = "./tfstates/change-pet.tfstate" #-- ๋ณ€๊ฒฝ
  }

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.0"
    }
  }
}

resource "random_pet" "server" {}

 

๊ธฐ์กด ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์„ ๋ณ€๊ฒฝํ–ˆ์œผ๋ฏ€๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜ฌ ๊ฒƒ์ด๊ณ , ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด -reconfigure ๋ฅผ ์‚ฌ์šฉํ•ด์ค๋‹ˆ๋‹ค.

error ๋ฌธ๊ตฌ

 

ํ•˜๊ฒŒ ๋˜๋ฉด ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์ด ./tfstates/change-pet.tfstate ๋กœ ๋ณ€๊ฒฝ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

{
    "version": 3,
    "serial": 2,
    "lineage": "ab7ad77f-6b5b-a79a-496e-7d244bc1085a",
    "backend": {
        "type": "local",
        "config": {
            "path": "./tfstates/change-pet.tfstate", #-- ๋ณ€๊ฒฝ๋จ
            "workspace_dir": null
        },
        "hash": 1312397314
    },
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {},
            "depends_on": []
        }
    ]
}

 

๊ทธ๋Ÿผ ์ด๋ฒˆ์—” terraform apply ๊นŒ์ง€ ์ง„ํ–‰ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

terraform {
  required_version = ">= 1.5.0"

  backend "local" {
    path = "./tfstates/random-pet.tfstate" #-- ์›๋ž˜ ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ
  }

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.0"
    }
  }
}

resource "random_pet" "server" {}

 

๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์— ๋ช…์‹œํ•œ ๊ฒฝ๋กœ์— state ๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” tfstate ๊ฐ€ ์ƒ์„ฑ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

.tfstate

 

์ดํ›„ ๋‹ค์‹œ ๋ณ€๊ฒฝํ•ด๋ณด๊ณ  terraform apply ๋ฅผ ์ง„ํ–‰ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

terraform {
  required_version = ">= 1.5.0"

  backend "local" {
    path = "./tfstates/change-pet.tfstate"
  }

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.0"
    }
  }
}

resource "random_pet" "server" {}

 

terraform init, apply ๋‘˜ ๋‹ค ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜๋Š”๋ฐ, ๋ฐ”๋ผ๋ณด๊ณ  ์žˆ๋Š” tfstate ๊ฐ€ ๋ณ€๊ฒฝ๋˜์„œ ๊ทธ๋ ‡์Šต๋‹ˆ๋‹ค.

terraform apply, init

 

.terraform/terraform.tfstate ์— ๋ช…์‹œ๋˜์–ด ์žˆ๋Š” ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ ๊ฒฝ๋กœ์— ๋ณ€๊ฒฝ๋œ change-pet.tfstate ๊ฐ€ ์—†์–ด์„œ ๊ทธ๋ ‡์ฃ .

 

์ด๋•Œ -reconfigure ์˜ต์…˜์„ ํ†ตํ•ด .terraform/terraform.tfstate ์— ๋ช…์‹œ๋˜์–ด ์žˆ๋Š” ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ ๊ฒฝ๋กœ๋ฅผ ๋ณ€๊ฒฝํ•ด์„œ ๋ณ€๊ฒฝ๋œ tfstate ๋ฅผ ๋ฐ”๋ผ๋ณด๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค.

 

-reconfigure ๋ฅผ ์‚ฌ์šฉํ•ด๋ณด๋ฉด ๋ฌธ์ œ ์—†์ด ์ž˜ ๋™์ž‘ํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ๋ณด์ž…๋‹ˆ๋‹ค.

terraform init -reconfigure

 

ํ•˜์ง€๋งŒ ์ฃผ์˜ํ•  ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. terraform apply ๋ฅผ ์ง„ํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด, ์ƒˆ๋กญ๊ฒŒ ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

์•„๊นŒ ๋ถ„๋ช… ์ƒ์„ฑํ–ˆ๋Š”๋ฐ... ์™œ ๊ทธ๋Ÿด๊นŒ์š”?

terraform apply

 

์ด์œ ๋Š” ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค. ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ ๋ณ€๊ฒฝ์œผ๋กœ ์ธํ•ด ๋ฐ”๋ผ๋ณด๊ณ  ์žˆ๋Š” tfstate ํŒŒ์ผ์ด ๋ณ€๊ฒฝ๋˜์„œ ๊ทธ๋ ‡์Šต๋‹ˆ๋‹ค.

tfstates

 

๊ธฐ์กด ๋ฆฌ์†Œ์Šค ์ƒํƒœ(state) ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ํŒŒ์ผ์€ random-pet.tfstate ์˜€๋Š”๋ฐ, ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์ด ๋ฐ”๋€Œ๋ฉด์„œ ๋” ์ด์ƒ random-pet.tfstate ๊ฐ€ ์•„๋‹Œ chagne-pet.tfstate ๋ฅผ ๊ฐ€๋ฅดํ‚ค๊ฒŒ ๋œ ๊ฒƒ์ด๊ณ , ๋‹น์—ฐํžˆ change-pet.tfstate ์—๋Š” ์•„๋ฌด๋Ÿฐ ์ •๋ณด๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.

 

terraform apply ๋ฅผ ํ†ตํ•ด ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒ์„ฑํ•œ ์ ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์ด์ฃ .

 

๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์„ ๋‹ค์‹œ "./tfstates/random-pet.tfstate" ๋กœ ๋ณ€๊ฒฝํ•œ ํ›„ terraform init -reconfigure ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด ์ด์ „ ๋ฆฌ์†Œ์Šค ์ƒํƒœ๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

terraform init -reconfigure

 

์ •๋ฆฌํ•ด๋ณด๋ฉด, -reconfigure ์€ ํ˜„์žฌ ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์„ ์ƒˆ๋กญ๊ฒŒ ์žฌ์„ค์ • ํ•ฉ๋‹ˆ๋‹ค.

 

์ €๋Š” ๋ณดํ†ต -reconfigure ์˜ต์…˜ ๊ฐ™์€ ๊ฒฝ์šฐ๋Š” workspace ๋ฅผ ํ†ตํ•ด dev ์™€ prod ๋ฅผ ๊ตฌ๋ถ„ํ•˜๊ณ , dev ๋Š” AWS Dev Account S3 ๋ฐฑ์—”๋“œ, prod ๋Š” AWS Prod Account S3 ๋ฐฑ์—”๋“œ๋ฅผ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ ๋ฐ”๋ผ๋ณด๋Š” ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์„ ๋ณ€๊ฒฝํ•  ๋•Œ ์ฃผ๋กœ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

workspace ์™€ Multi S3 Backend with AWS Cross-Account

workspace ์™€ Multi S3 Backend with AWS Cross-Account ์— ๋Œ€ํ•ด์„  ๋‹ค์Œ ๊ธ€์—์„œ ๋‹ค๋ฃจ๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค!

 

terraform ์„ ์ฒ˜์Œ ์‚ฌ์šฉํ–ˆ์„ ๋•Œ -reconfigure ์˜ต์…˜์„ ์ž˜ ์•Œ์ง€ ๋ชปํ•˜๋Š” ์ƒํƒœ์—์„œ ์‚ฌ์šฉํ–ˆ๋‹ค๊ฐ€ ๋ฆฌ์†Œ์Šค๋ฅผ ์ƒˆ๋กญ๊ฒŒ ์ƒ์„ฑํ•œ๋‹ค๋Š” ๋ฌธ๊ตฌ๊ฐ€ ๋– ์„œ ๋งŽ์ด ๋‹นํ™ฉํ–ˆ๋˜ ์ ์ด ์žˆ์—ˆ๋Š”๋ฐ, ์—ฌ๋Ÿฌ๋ถ„์„ ๊ทธ๋Ÿฐ ์ผ์ด ์—†์œผ์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค!

 

 

-migrate-state


 

์ด๋ฒˆ์— -migrate-state ์ž…๋‹ˆ๋‹ค. 

-migrate-state

 

๋ฒˆ์—ญํ•ด๋ณด์ž๋ฉด "state(tfstate ํŒŒ์ผ) ๋ฅผ ์ž๋™์œผ๋กœ ์ด์ „ํ•˜๊ณ  ์‹ถ์œผ๋ฉด -migrate-state ๋ฅผ ์‚ฌ์šฉํ•ด๋ผ" ์ž…๋‹ˆ๋‹ค.

-reconfigure ์™€ ๋‹ค๋ฅด๊ฒŒ ์ง๊ด€์ ์ด๋ผ๊ณ  ๋ด…๋‹ˆ๋‹ค. ์ด๋ฆ„ ๊ทธ๋Œ€๋กœ tfstate ๋ฅผ ์ด์ „ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

์‹ค์Šต ์ฝ”๋“œ๋Š” ์•„๊นŒ์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.

terraform {
  required_version = ">= 1.5.0"

  backend "local" {
    path = "./tfstates/random-pet.tfstate"
  }

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.0"
    }
  }
}

resource "random_pet" "server" {}

 

ํ˜„์žฌ ํ…Œ๋ผํผ ๋ฆฌ์†Œ์Šค๋ฅผ tfstates/random-pet.tfstate ์— state(์ƒํƒœ) ๋ฅผ ์ €์žฅํ•˜๊ณ  ์žˆ์ฃ .

 

๊ทธ์น˜๋งŒ tfstates ๋””๋ ‰ํ„ฐ๋ฆฌ๊ฐ€ ์•„๋‹Œ, rocket ๋””๋ ‰ํ„ฐ๋ฆฌ๋กœ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ๊ณ  ์ด์ฐธ์— random-pet.tfstate ๊ฐ€ ์•„๋‹Œ rocket.tfstate ๋กœ ํŒŒ์ผ ์ด๋ฆ„๋„ ๋ณ€๊ฒฝํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค.

terraform {
  required_version = ">= 1.5.0"

  backend "local" {
    path = "./rocket/rocket.tfstate" #-- ๋ณ€๊ฒฝ
  }

  required_providers {
    random = {
      source  = "hashicorp/random"
      version = "3.6.0"
    }
  }
}

resource "random_pet" "server" {}

 

๋ณ€๊ฒฝํ•œ ํ›„, terraform init -migrate-state ๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋˜๋ฉด, ์•„๋ž˜์™€ ๊ฐ™์€ ๋ฌธ๊ตฌ๊ฐ€ ๋‚˜์˜ต๋‹ˆ๋‹ค.

terraform init -migrate-state

 

ํ•ต์‹ฌ์€ "์ƒˆ๋กœ์šด ๋ฐฑ์—”๋“œ๋กœ ํ˜„์žฌ state ๋ฅผ ๋ณต์‚ฌํ•˜๊ณ  ์‹ถ๋ƒ?" ์ž…๋‹ˆ๋‹ค.

yes ๋ฅผ ํ•ด์ค๋‹ˆ๋‹ค.

yes

 

๊ทธ๋Ÿผ rocket/rocket.tfstate ์— ๊ธฐ์กด tfstates/random-pet.tfstate ๊ฐ€ ๋ณต์‚ฌ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

rocket/rocket.tfstate

 

-reconfigure ๋•Œ์™€ ๋‹ค๋ฅด๊ฒŒ ์ƒˆ๋กœ์šด ๋ฆฌ์†Œ์Šค๊ฐ€ ์ƒ์„ฑ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

no changes

 

-migrate-state ๊ฐ™์€ ๊ฒฝ์šฐ ๋น„๋ก ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ์ด ๋ณ€๊ฒฝ๋˜๊ธด ํ–ˆ์ง€๋งŒ ๋ณ€๊ฒฝ๊ณผ ๋™์‹œ์— ๊ธฐ์กด ์ƒํƒœ๋„ ๊ฐ™์ด ๋ณต์‚ฌ(์ด์ „) ๋˜์—ˆ๊ธฐ ๋•Œ๋ฌธ์ด์ฃ !

 

์ €๋Š” ๋ณดํ†ต state(์ƒํƒœ)๋ฅผ ๋‹ด๊ณ  ์žˆ๋Š” tfstate ์˜ ์ด๋ฆ„์€ ๋ณ€๊ฒฝํ•˜๊ฑฐ๋‚˜, workspace ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•˜๋˜ ํ…Œ๋ผํผ ๋ฆฌ์†Œ์Šค๋ฅผ workspace ๋กœ ์ด์ „ํ•  ๋•Œ -migrate-state ๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.

 

๋งˆ์ฐฌ๊ฐ€์ง€๋กœ workspace ์™€ Multi S3 Backend with AWS Cross-Account ๊ธ€์—์„œ ๋‹ค๋ฃจ๊ธด ํ•  ๊ฑฐ์ง€๋งŒ, ๋ง›๋ณด๊ธฐ ํ•ด๋ณด๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ง„ํ–‰๋ฉ๋‹ˆ๋‹ค.
# (backend ๊ตฌ์„ฑ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š๊ณ , ๊ธฐ์กด ๊ทธ๋Œ€๋กœ) ๊ธฐ์กด ๋””๋ ‰ํ„ฐ๋ฆฌ์—์„œ
$ terraform state pull > dev.tfstate

# ์ค‘์š”!!!!!! -> ์ง„ํ–‰ํ•˜๊ธฐ ์ „์— ๋ฐฑ์—”๋“œ ๊ตฌ์„ฑ ๋ฐ”๊ฟ”์ฃผ๊ธฐ
# init ์„ ํ†ตํ•ด ๋ฐฑ์—”๋“œ ๋ฐ”๊ฟ”์ฃผ๊ธฐ
$ terraform init -backend-config=backend-configs/dev.hcl -migrate-state

# pull ํ•œ tfstate ์ด๋ฆ„ ๋ณ€๊ฒฝ ํ›„ ์›Œํฌ์ŠคํŽ˜์ด์Šค ์ƒ์„ฑ
$ terraform workspace new -state="dev.tfstate" dev

# push ํ•˜๊ธฐ 
$ terraform state push dev.tfstate

# ํ™•์ธํ•˜๊ธฐ
$ terraform state list

 

 

์˜ค๋Š˜์€ terraform ์„ ์ฒ˜์Œ ๊ณต๋ถ€ํ–ˆ์„ ๋•Œ ํ—ท๊ฐˆ๋ ธ๋˜ ๋ถ€๋ถ„ ์ค‘ ํ•˜๋‚˜์˜€๋˜ -reconfigure ์™€ -migrate-state ์— ๋Œ€ํ•ด ์•Œ์•„๋ดค์Šต๋‹ˆ๋‹ค!

์ž˜๋ชป๋œ ์‚ฌ์šฉ์œผ๋กœ ์ธํ•ด ๊ณ ์ƒํ–ˆ๋˜ ๊ธฐ์–ต์ด ์žˆ๋„ค์š”..

 

ํ•˜์ง€๋งŒ ์ž˜๋งŒ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์ •๋ง ์œ ์šฉํ•˜๊ฒŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์˜ต์…˜์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค. (Muli S3 Backend with AWS Cross-Account)

 

๊ทธ๋Ÿผ ์˜ค๋Š˜์€ ์—ฌ๊ธฐ๊นŒ์ง€!

๋ฐ˜์‘ํ˜•
profile on loading

Loading...