Slide 1

Slide 1 text

.terraform.lock.hcl ׬શʹཧղͨ͠ Terraform meetup ONLINE #2021.02 2021/02/10 @minamijoyo

Slide 2

Slide 2 text

ࣗݾ঺հ • Masayuki Morita • Twitter/GitHub/Qiita: @minamijoyo • SRE at CrowdWorks Inc. • Contributor of hashicorp/terraform, hcl, etc… • Author of: tfschema, tfupdate, tfmigrate, hcledit

Slide 3

Slide 3 text

.terraform.lock.hclͱ͸

Slide 4

Slide 4 text

• Terraform v0.14͔Βಋೖ͞ΕͨґଘϩοΫϑΝΠϧ • Terraform v0.14Ͱ͸ϓϩόΠμͷΈ؅ཧ(ϞδϡʔϧະରԠ) • terraform init͢ΔͱࣗಈͰੜ੒͞ΕΔ (ߋ৽͸-upgrade) • GitͳͲͷόʔδϣϯ؅ཧπʔϧʹίϛοτΛެࣜʹਪ঑ • .gitignoreˍຖճterraform init -upgrade͢Ε͹v0.13Ҏલͱ΄΅ಉ༷ ͷڍಈ .terraform.lock.hclͱ͸ ※஫: ຊࢿྉ࡞੒࣌ͷTerraform͸v0.14.5Ͱ͢

Slide 5

Slide 5 text

# This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", "zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", "zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b", "zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535", "zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587", "zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d", "zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea", "zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", "zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58", "zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01", ] } ੍໿৚݅ͱબ୒͞Εͨόʔδϣϯ ϓϩόΠμͷϋογϡ஋ ϓϩόΠμ໊

Slide 6

Slide 6 text

͋ʔɺ͸͍͸͍ɻ Α͋͘ΔґଘϥΠϒϥϦͷ ϩοΫϑΝΠϧͶɻ

Slide 7

Slide 7 text

.terraform.lock.hcl ׬શʹཧղͨ͠

Slide 8

Slide 8 text

ͰɺऴΘΕ͹Α͔͕ͬͨɺ ͦΜͳʹ୯७Ͱ͸ͳ͔ͬͨ

Slide 9

Slide 9 text

• TF_PLUGIN_CACHEͰϓϩόΠμΛΩϟογϡ͢Δͱ৑௕ͳμ΢ϯϩʔυճආ Ͱ͖Δ • Ωϟογϡͷ༗ແͰੜ੒͞ΕΔϩοΫϑΝΠϧͷத਎͕ҟͳΔ ϩοΫϑΝΠϧ͕Ωϟογϡঢ়ଶʹґଘ͢Δ໰୊ $ mkdir -p /tmp/plugin-cache $ TF_PLUGIN_CACHE_DIR=/tmp/plugin-cache terraform init $ rm -rf .terraform && rm .terraform.lock.hcl $ TF_PLUGIN_CACHE_DIR=/tmp/plugin-cache terraform init $ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", ] } ϋογϡ͕ߦ͔͠ه࿥͞Εͳ͍ Ωϟογϡ͋ΓͰੜ੒͞ΕͨϩοΫ

Slide 10

Slide 10 text

# This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", "zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", "zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b", "zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535", "zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587", "zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d", "zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea", "zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", "zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58", "zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01", ] } ͦ΋ͦ΋Iͱ͔[Iͱ͔Կʁʁʁ Ωϟογϡͳ͠ͷ৔߹

Slide 11

Slide 11 text

.terraform.lock.hcl φχϞϫΧϥφΠ

Slide 12

Slide 12 text

• https://www.terraform.io/docs/language/dependency-lock.html • zh: zip hash (legacy) • ϓϩόΠμͷ഑෍෺ͷzipύοέʔδͷϋογϡ஋ • Terraform Registry͔Βμ΢ϯϩʔυͨ͠৔߹ʹ෇༩͞ΕΔ • ͢΂ͯͷϓϥοτϑΥʔϜ෼Λه࿥ • h1: hash scheme 1 • ϓϩόΠμͷ഑෍෺ͷίϯςϯπͷϋογϡ஋ • ϛϥʔ΍ΩϟογϡͰ΋࢖͑Δ • σϑΥϧτͰ͸࣮ߦ͢ΔϓϥοτϑΥʔϜ෼͚ͩه࿥ ݱঢ়zhͱh1ͷ2छྨͷϋογϡํ͕ࣜ͋Δ

Slide 13

Slide 13 text

# This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", "zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", "zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b", "zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535", "zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587", "zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d", "zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea", "zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", "zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58", "zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01", ] } NBD04 EBSXJO@BNE ͢΂ͯͷϓϥοτϑΥʔϜͱ͸ʁʁʁ

Slide 14

Slide 14 text

$ curl -s https://registry.terraform.io/v1/providers/hashicorp/aws/3.26.0/download/darwin/amd64 | jq . { "protocols": [ "5.0" ], "os": "darwin", "arch": "amd64", "filename": "terraform-provider-aws_3.26.0_darwin_amd64.zip", "download_url": "https://releases.hashicorp.com/terraform-provider-aws/3.26.0/terraform-provider- aws_3.26.0_darwin_amd64.zip", "shasums_url": "https://releases.hashicorp.com/terraform-provider-aws/3.26.0/terraform-provider-aws_3.26.0_SHA256SUMS", "shasums_signature_url": "https://releases.hashicorp.com/terraform-provider-aws/3.26.0/terraform-provider- aws_3.26.0_SHA256SUMS.sig", "shasum": "90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", "signing_keys": { $ TF_LOG=TRACE terraform init (snip.) 2021/02/03 23:32:13 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/aws/versions 2021/02/03 23:32:13 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/aws/versions 2021/02/03 23:32:13 [DEBUG] GET https://registry.terraform.io/v1/providers/hashicorp/aws/3.26.0/download/darwin/amd64 2021/02/03 23:32:13 [TRACE] HTTP client GET request to https://registry.terraform.io/v1/providers/hashicorp/aws/3.26.0/ download/darwin/amd64 2021/02/03 23:32:14 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-aws/3.26.0/terraform-provider- aws_3.26.0_SHA256SUMS 2021/02/03 23:32:14 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-aws/3.26.0/ terraform-provider-aws_3.26.0_SHA256SUMS 2021/02/03 23:32:14 [DEBUG] GET https://releases.hashicorp.com/terraform-provider-aws/3.26.0/terraform-provider- aws_3.26.0_SHA256SUMS.sig 2021/02/03 23:32:14 [TRACE] HTTP client GET request to https://releases.hashicorp.com/terraform-provider-aws/3.26.0/ terraform-provider-aws_3.26.0_SHA256SUMS.sig (snip.) σόοάϩάΛग़ྗ ͜͜ʹνΣοΫαϜ͕͋Γͦ͏ 5FSSBGPSN3FHJTUSZͱ௨৴ͯ͠Δ

Slide 15

Slide 15 text

$ curl -s https://releases.hashicorp.com/terraform-provider-aws/3.26.0/terraform-provider-aws_3.26.0_SHA256SUMS | sort 26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb terraform-provider-aws_3.26.0_linux_amd64.zip 2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300 terraform-provider-aws_3.26.0_windows_386.zip 3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b terraform-provider-aws_3.26.0_freebsd_arm.zip 46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535 terraform-provider-aws_3.26.0_linux_386.zip 5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587 terraform-provider-aws_3.26.0_freebsd_amd64.zip 60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d terraform-provider-aws_3.26.0_linux_arm64.zip 896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea terraform-provider-aws_3.26.0_freebsd_386.zip 90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4 terraform-provider-aws_3.26.0_darwin_amd64.zip ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58 terraform-provider-aws_3.26.0_linux_arm.zip e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01 terraform-provider-aws_3.26.0_windows_amd64.zip TPSU͢Δͱ hashes = [ "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", "zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", "zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b", "zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535", "zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587", "zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d", "zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea", "zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", "zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58", "zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01", ] ׬શʹҰக

Slide 16

Slide 16 text

.terraform.lock.hcl ׬શʹཧղͨ͠

Slide 17

Slide 17 text

͋Εɺ͏ͪͷCI͸ Docker(Linux)ͳΜ͚ͩͲʁ h1͸macOS༻Ͱ͍͍ͷʁ

Slide 18

Slide 18 text

ͳΔ΄Ͳʙɺ ͍͍࣭໰Ͱ͢Ͷɻ

Slide 19

Slide 19 text

$ # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", ] } [I͕ͳ͍৔߹ NBD04 EBSXJO@BNE $ docker run -it --rm -v $(pwd):/work hashicorp/terraform:0.14.5 -chdir=/work init Initializing the backend... Initializing provider plugins... - Reusing previous version of hashicorp/aws from the dependency lock file - Installing hashicorp/aws v3.26.0... Error: Failed to install provider Error while installing hashicorp/aws v3.26.0: the current package for registry.terraform.io/hashicorp/aws 3.26.0 doesn't match any of the checksums previously recorded in the dependency lock file νΣοΫαϜΤϥʔ %PDLFS -JOVY Ͱ࣮ߦͯ͠ΈΔ

Slide 20

Slide 20 text

ͦΕ͸ͦ͏ɻ ͩͬͯνΣοΫαϜͬͯ վ͟Μݕ஌ͳΜ͔ͩΒ ͦ͏͍͏΋Μɻ

Slide 21

Slide 21 text

# This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", "zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", "zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b", "zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535", "zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587", "zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d", "zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea", "zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", "zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58", "zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01", ] } I͸NBD04 EBSXJO@BNE [I͕͋Δ

Slide 22

Slide 22 text

$ git diff diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 9591972..a0f76ee 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -5,6 +5,7 @@ provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ + "h1:0i78FItlPeiomd+4ThZrtm56P5K33k7/6dnEe4ZePI0=", "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", “zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", (snip.) $ docker run -it --rm -v $(pwd):/work hashicorp/terraform:0.14.5 -chdir=/work init %PDLFS -JOVY Ͱ࣮ߦͯ͠ΈΔ ͳΜ͔૿͑ͯΔʂʂ

Slide 23

Slide 23 text

উखʹ૿͑ͯ΂ΜΓʙ ʢͳΘ͚ͳ͍ʣ CIͰgit diffग़Δͷ΍ͩʔɻ

Slide 24

Slide 24 text

.terraform.lock.hcl φχϞϫΧϥφΠ

Slide 25

Slide 25 text

ͦΜͳ͜ͱ΋͋Ζ͏͔ͱ terraform providers lock

Slide 26

Slide 26 text

• ͋Β͔͡ΊඞཁͳϓϥοτϑΥʔϜ໊Λࢦఆͯ͠ϩοΫϑΝΠϧΛੜ੒͢Δ • https://www.terraform.io/docs/cli/commands/providers/lock.html terraform providers lock $ terraform providers lock -platform=linux_amd64 -platform=darwin_amd64 hashes = [ "h1:0i78FItlPeiomd+4ThZrtm56P5K33k7/6dnEe4ZePI0=", "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", "zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", "zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b", "zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535", "zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587", "zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d", "zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea", "zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", "zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58", "zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01", ] NBD04 EBSXJO@BNE -JOVY MJOVY@BNE

Slide 27

Slide 27 text

.terraform.lock.hcl ׬શʹཧղͨ͠

Slide 28

Slide 28 text

͋ΕɺΩϟογϡ͕ޮ͍͍ͯ ͳ͍Α͏ͳʁʁʁ

Slide 29

Slide 29 text

• terraform providers lockίϚϯυ͸σϑΥϧτͰ͸Registryͱ ௨৴͢ΔͷͰɺΩϟογϡΛແࢹ͢ΔʢόάͰ͸ͳ͘࢓༷ʣ • ϩοΫ͸rootϞδϡʔϧ (=σΟϨΫτϦ) ͝ͱʹ؅ཧ͢Δ • h1Λܭࢉ͢ΔͨΊϓϩόΠμͷμ΢ϯϩʔυ͕ඞཁ • σΟϨΫτϦ͍ͬͺ͍͋ΔͱɺຖճσΟϨΫτϦ਺෼͚ͩॏ ෳμ΢ϯϩʔυ͢Δͷແବ͗͢Ͷʁʁʁ • ϦϙδτϦϧʔτͰϩοΫϑΝΠϧੜ੒ͯ͠ɺ֤σΟϨΫτϦ ʹίϐʔͱ͍͏Ҋ΋ͳ͘͸ͳ͍͕ɺϩοΫϑΝΠϧ͕কདྷϞ δϡʔϧ΋αϙʔτ͢Δͱഁ୼ͦ͠͏ TF_PLUGIN_CACHEޮ͔ͳ͍໰୊

Slide 30

Slide 30 text

.terraform.lock.hcl φχϞϫΧϥφΠ

Slide 31

Slide 31 text

ͦΜͳ͋ͳͨʹ terraform providers mirror

Slide 32

Slide 32 text

• ϩʔΧϧϑΝΠϧγεςϜϛϥʔΛ࡞੒͠ɺϛϥʔ͔ΒϩοΫϑΝΠϧ΋࡞ΕΔ • https://www.terraform.io/docs/cli/commands/providers/mirror.html terraform providers mirror $ FS_MIRROR=“/tmp/terraform.d/plugins" $ terraform providers mirror -platform=linux_amd64 -platform=darwin_amd64 "${FS_MIRROR}" $ terraform providers lock -fs-mirror="${FS_MIRROR}" -platform=linux_amd64 -platform=darwin_amd64 # This file is maintained automatically by "terraform init". # Manual edits may be lost in future updates. provider "registry.terraform.io/hashicorp/aws" { version = "3.26.0" constraints = "~> 3.0" hashes = [ "h1:0i78FItlPeiomd+4ThZrtm56P5K33k7/6dnEe4ZePI0=", "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", ] } 3FHJTUSZͱ௨৴͠ͳ͍৔߹ I͔͠ه࿥͞Εͳ͍ ϛϥʔΛࢦఆ

Slide 33

Slide 33 text

·͊ඞཁͳh1Λੜ੒Ͱ͖Ε͹ zh͍Βͳ͘Ͷʁ

Slide 34

Slide 34 text

#!/bin/bash set -eo pipefail export TF_PLUGIN_CACHE_DIR="/tmp/terraform.d/plugin-cache" mkdir -p "${TF_PLUGIN_CACHE_DIR}" FS_MIRROR="/tmp/terraform.d/plugins" terraform providers mirror -platform=linux_amd64 -platform=darwin_amd64 "${FS_MIRROR}" ALL_DIRS=$(find . -type f -name '*.tf' | xargs -I {} dirname {} | sort | uniq | grep -v 'modules/') for dir in ${ALL_DIRS} do pushd "$dir" rm -f .terraform.lock.hcl terraform providers lock -fs-mirror="${FS_MIRROR}" -platform=linux_amd64 -platform=darwin_amd64 popd done ΅͘ͷ͔Μ͕͍͖͑ͨ͞ΐ͏ͷ.sh • ϦϙδτϦϧʔτͰඞཁͳϓϩόΠμΛྻڍͨ͠ .tfΛ͋Β͔͡Ί഑ஔ • ϦϙδτϦϧʔτͰϩʔΧϧϛϥʔΛ࡞੒͠ɺαϒσΟϨΫτϦͰϩοΫϑΝΠϧΛੜ੒

Slide 35

Slide 35 text

$ terraform providers lock Error: Module not installed on main.tf line 1: 1: module "foo" { This module is not yet installed. Run "terraform init" to install all modules required by this configuration. Ϟδϡʔϧࢀর͕͋Δͱ ΤϥʔʹͳΔ Ϟδϡʔϧࢀর͕͋ΔͱΤϥʔʹͳΔ໰୊ • Ϟδϡʔϧ͔Βؒ઀తʹϓϩόΠμͷґଘ͕૿͑Δ͜ͱ͸͋Γ͏Δ • providers lockίϚϯυ͸ґଘ͢Δ͢΂ͯͷϞδϡʔϧΛಡΈࠐΉඞཁ͕͋Δ

Slide 36

Slide 36 text

#!/bin/bash set -eo pipefail export TF_PLUGIN_CACHE_DIR="/tmp/terraform.d/plugin-cache" mkdir -p "${TF_PLUGIN_CACHE_DIR}" FS_MIRROR="/tmp/terraform.d/plugins" terraform providers mirror -platform=linux_amd64 -platform=darwin_amd64 "${FS_MIRROR}" ALL_DIRS=$(find . -type f -name '*.tf' | xargs -I {} dirname {} | sort | uniq | grep -v 'modules/') for dir in ${ALL_DIRS} do pushd “$dir" rm -f .terraform.lock.hcl terraform init -input=false -no-color -backend=false -plugin-dir=“${FS_MIRROR}" rm -f .terraform.lock.hcl terraform providers lock -fs-mirror="${FS_MIRROR}" -platform=linux_amd64 -platform=darwin_amd64 rm -rf .terraform popd done QSPWJEFSTMPDLલʹ JOJUͰϞδϡʔϧΛऔಘ ΅͘ͷ͔Μ͕͍͖͑ͨ͞ΐ͏ͷ.sh

Slide 37

Slide 37 text

.terraform.lock.hcl ׬શʹཧղͨ͠

Slide 38

Slide 38 text

͋Εɺ ·ͨͳΜ͔gitࠩ෼͕ग़ͨ

Slide 39

Slide 39 text

$ terraform init $ git diff diff --git a/.terraform.lock.hcl b/.terraform.lock.hcl index 88ac68e..a0f76ee 100644 --- a/.terraform.lock.hcl +++ b/.terraform.lock.hcl @@ -7,5 +7,15 @@ provider "registry.terraform.io/hashicorp/aws" { hashes = [ "h1:0i78FItlPeiomd+4ThZrtm56P5K33k7/6dnEe4ZePI0=", "h1:b1qNzEzDHZpnHSOW4fRo1PFC0U2Ft25PKKs9NSDGe3U=", + "zh:26043eed36d070ca032cf04bc980c654a25821a8abc0c85e1e570e3935bbfcbb", + "zh:2fe68f3f78d23830a04d7fac3eda550eef1f627dfc130486f70a65dc5c254300", + "zh:3d66484c608c64678e639db25d63872783ce60363a1246e30317f21c9c23b84b", + "zh:46ffd755cfd4cf94fe66342797b5afdcef010a24e126c67fee141b357d393535", + "zh:5e96f24357e945c9067cf5e032ad1d003609629c956c2f9f642fefe714e74587", + "zh:60c27aca36bb63bf3e865c2193be80ca83b376581d00f9c220af4b013e163c4d", + "zh:896f0f22d19d41e71b22f9240b261714c3915b165ddefeb771e7734d69dc47ea", + "zh:90de9966cb2fd3e2f326df291595e55d2dd2d90e7d6dd085c2c8691dce82bdb4", + "zh:ad05a91a88ceb1d6de5a568f7cc0b0e5bc0a79f3da70bc28c1e7f3750e362d58", + "zh:e8c63f59c6465329e1f3357498face3dd7ef10a033df3c366a33aa9e94b46c01", ] } [I͕௥ه͞ΕΔ ϩʔΧϧʹΩϟογϡ͕ͳ͍৔߹ Ωϟογϡ͕ͳ͍ͱzh௥ه͞ΕͪΌ͏໰୊

Slide 40

Slide 40 text

WindowsͰ΋࢖͏͔΋ͩ͠ɺ zh௥ه͓͍ͯͨ͠Α ʢ༨ܭͳ͓ੈ࿩ʣ

Slide 41

Slide 41 text

.terraform.lock.hcl φχϞϫΧϥφΠ

Slide 42

Slide 42 text

ͦ΋ͦ΋ Terraform Registry͕௚઀ zhͱh1྆ํฦͯ͘͠ΕΕ͹ શ෦ղܾͰ͸ʁʁʁ

Slide 43

Slide 43 text

https://github.com/hashicorp/terraform/issues/27264

Slide 44

Slide 44 text

https://github.com/hashicorp/terraform/issues/27264 UFSSBGPSNMPDLIDMνϣοτσΩϧ 5FSSBGPSNίΞνʔϜͷ BQQBSFOUMZNBSUࢯʹΑΔղઆ

Slide 45

Slide 45 text

ͳΜͰ͜ΜͳΊΜͲ͍͘͜͞ ͱʹͳ͍ͬͯΔͷ͔ʁ ͬ͘͟Γཁ໿ˍิ଍͢Δͱ

Slide 46

Slide 46 text

• Terraform v0.12·Ͱ͸ϓϩόΠμ͸ releases.hashicorp.com ͔Β഑ ෍͍ͯͨ͠ • ͦ΋ͦ΋ releases.hashicorp.com ͸Terraformઐ༻Ͱ͸ͳ͍ͷͰɺ഑ ෍෺ͷzipΞʔΧΠϒͷνΣοΫαϜΛ࢖͏ͱ͍͏ͷ͸ଥ౰ • v0.13ͰϓϩόΠμͷ഑෍΋Registryܦ༝ʹͳ͕ͬͨɺஈ֊తʹҠߦ ͢ΔͨΊɺRegistry͸࣮ࡍʹ͸ͨͩͷindexͰɺ഑෍෺͸Ҿ͖ଓ͖ releases.hashicorp.com ͔Β഑෍͢Δ͜ͱʹ • ݁Ռͱͯ͠ɺRegistry͸releases.hashicorp.comͷνΣοΫαϜͷ࢓ ༷ΛҾ͖ܧ͍ͩ ݱঢ়Terraform Registry͸zh͔͠ฦͤͳ͍

Slide 47

Slide 47 text

• h1͸౰ॳLocal Filesystem MirrorΛαϙʔτ͢ΔͨΊʹಋೖ͞Εͨ • Local Filesystem Mirror͸zipܗ͚ࣜͩͰͳ͘ɺzipల։ࡁΈͷσΟϨΫτ Ϧܗࣜ΋αϙʔτ͓ͯ͠ΓɺσΟϨΫτϦܗࣜͷ৔߹͸zhΛܭࢉͰ͖ͳ ͍ʢѹॖ͢ΔͨͼʹzipϑΝΠϧͷϝλσʔλ͕มΘͬͯ͠·͏ͷͰʣ • ࣗ࡞ϓϩόΠμͷ৔߹͸ɺRegistry͔Β഑෍͞ΕΔ͜ͱ͸ͳ͘ɺh1͚ͩ Ͱ໰୊ͳ͔͕ͬͨɺRegistryͰ഑෍͞Ε͍ͯΔ΋ͷΛɺLocal Filesystem Mirrorܦ༝ͰΠϯετʔϧ͠Α͏ͱ͢ΔͱɺΠϯετʔϧํ๏ʹґଘ͠ ͯϩοΫϑΝΠϧͷத਎͕มΘͬͯ͠·͏ • ͱ͍͏Θ͚Ͱɺ͋Β͔͡ΊϩοΫϑΝΠϧΛੜ੒͢Δterrform providers lock͕࣮૷͞Εͨ Local Filesystem Mirror ͸zhΛܭࢉͰ͖ͳ͍

Slide 48

Slide 48 text

• h1͸ܭࢉʹμ΢ϯϩʔυ͕ඞཁͳͷͰɺ௨ৗ͸terraform initͨ͠ϓ ϥοτϑΥʔϜ෼͔͠ه࿥͞Εͳ͍ • ͨͩzhΛ͋Β͔͡Ί͢΂ͯͷϓϥοτϑΥʔϜ෼ه࿥͓͚ͯ͠͹ɺ ଞͷϓϥοτϑΥʔϜͰ΋ɺ৴པͰ͖Δط஌ͷzhʹϚον͢Δzipͷ ίϯςϯπͷh1Λޙ͔Β௥هͯ͠΋҆શɻ • ඞཁʹͳͬͨλΠϛϯάͰ৽͍͠h1Λ௥ه͢Δͱ͍͏࢓༷͸ɺਓ͕ ϩοΫϑΝΠϧΛݟͯߋ৽Λίϛοτ͢Δͱ͍͏ϫʔΫϑϩʔΛ૝ ఆͯ͠ઃܭ͞Ε͍ͯΔ • ҰํɺϓϩόΠμͷόʔδϣϯΞοϓΛࣗಈԽ͠ɺϩοΫϑΝΠϧ Λߋ৽͞ΕΔλΠϛϯάΛݫີʹίϯτϩʔϧ͍ͨ͠৔߹ʹ͸ɺҙ ਤ͠ͳ͍λΠϛϯάͰߋ৽͞ΕΔͷ͸ࠔͬͯ͠·͏ ҆શʹh1Λݕূͯ͠௥Ճ͢Δʹ͸

Slide 49

Slide 49 text

• ݱঢ়ͷRegistryϓϩτίϧ͸ෳ਺ͷϋογϡํ͕ࣜ͋Δ͜ͱ Λ૝ఆ͍ͯ͠ͳ͍ • Registry ͕ෳ਺ͷϋογϡํࣜΛѻ͑ΔΑ͏ʹ͢΂͖ͩ ͠ɺඞཁੑ͸ೝ͍ࣝͯ͠Δ͕ɺv0.14.0ͷϦϦʔεʹ͸ؒʹ ߹ΘͤΒΕͳ͔ͬͨ • Registryϓϩτίϧͷมߋʹ͸͠͹Β͕͔͔࣌ؒ͘Γͦ͏ Registry͸h1Λฦͤͳ͍ͷ͔ʁ

Slide 50

Slide 50 text

.terraform.lock.hcl ׬શʹཧղͨ͠

Slide 51

Slide 51 text

͋ͨ͞͠ΓϩοΫϑΝΠϧߋ৽Λ ཈ࢭ͍ͨ͠ͷ͚ͩΕͲ΋ Կ͔Φϓγϣϯੜ΍͢ͷ͋Γʁ UFSSBGPSNJOJUMPDLpMFSFBEPOMZ ͸͋Γ͡Όͳ͍ʁ

Slide 52

Slide 52 text

https://github.com/hashicorp/terraform/pull/27630 ϨϏϡʔ଴ͪ terraform init -lockfile=readonly ࡞ͬͯΈͨ

Slide 53

Slide 53 text

• Terraform v0.14͔Βಋೖ͞Εͨ.terraform.lock.hclΛɺෳ਺ͷ σΟϨΫτϦͱϓϥοτϑΥʔϜࠞࡏ؀ڥͰޮ཰Α͘ӡ༻͢Δ ʹ͸ɺݱঢ়͍Ζ͍Ζͳٕज़తͳ੍໿͕͋Γେมݫ͍͠ • .gitignoreͨ͠Βෛ͚͔ͳͱࢥͬͯΔͷͰӡ༻ํ๏Λ໛ࡧத • terraform providers mirrorͱterraform providers lockΛ૊Έ߹ ΘͤΕ͹ɺΩϟογϡ͕ͳ͍৔߹Ҏ֎͸͍͚ͦ͏ײ • terraform init -lockfile=readonly͕ύζϧͷ࠷ޙͷϐʔε • ࠜຊతʹ͸Registry͕h1Λ௚઀ฦͯ͘͠ΕΔ͜ͱΛظ଴ ·ͱΊ: .terraform.lock.hcl ׬શʹཧղͨ͠