この前のエラーはstate fileに差分があったようで、
なんとかv0.11.0→v1.3.0にバージョンアップできた。Terraform職人です👍 https://t.co/vjLfyBwpMG— adachin👾SRE (@adachin0817) September 28, 2022
さて、M1 MacでTerraformバージョンアップを取り組んだところ、v.0.15.0からv1.3.0でterraform init時にプロバイダーが見つからんとエラーが出ました。今回はその対応方法をブログします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$ terraform init Initializing the backend... Initializing provider plugins... - terraform.io/builtin/terraform is built in to Terraform - Reusing previous version of hashicorp/template from the dependency lock file - Reusing previous version of hashicorp/aws from the dependency lock file - Installing hashicorp/template v2.2.0... - Installing hashicorp/aws v4.32.0... - Installed hashicorp/aws v4.32.0 (signed by HashiCorp) │ Error: Incompatible provider version │ │ Provider registry.terraform.io/hashicorp/template v2.2.0 does not have a package available for your │ current platform, darwin_arm64. │ │ Provider releases are separate from Terraform CLI releases, so not all providers are available for │ all platforms. Other versions of this provider may have different platforms supported. $ terraform providers ╷ │ Error: Required plugins are not installed │ │ The installed provider plugins are not consistent with the packages selected in the dependency lock │ file: │ - registry.terraform.io/hashicorp/aws: the cached package for registry.terraform.io/hashicorp/aws 4.32.0 (in .terraform/providers) does not match any of the checksums recorded in the dependency lock file │ - registry.terraform.io/hashicorp/template: there is no package for registry.terraform.io/hashicorp/template 2.2.0 cached in .terraform/providers │ │ Terraform uses external plugins to integrate with a variety of different infrastructure services. │ To download the plugins required for this configuration, run: │ terraform init |
Template Provider is deprecated
- terraform version
1 2 3 4 5 |
$ terraform -v Terraform v1.3.0 on darwin_arm64 + provider registry.terraform.io/hashicorp/aws v4.32.0 + provider registry.terraform.io/hashicorp/template v2.2.0 |
https://registry.terraform.io/providers/hashicorp/template/latest/docs
TemplateプロバイダーはM1 (darwin_arm64) リリースが存在する前に廃止されて、アーカイブされています。なので、今コード修正するよりはバージョンアップ後にリファクタリングする方が望ましいです。方法としてはTemplateプロバイダーをローカルでbuildしてバイナリを設置するしかありません。実際に試してみましょう。
- How to remove provider.template from remote state
https://discuss.hashicorp.com/t/how-to-remove-provider-template-from-remote-state/33331
- Template v2.2.0 does not have a package available – Mac M1
https://discuss.hashicorp.com/t/template-v2-2-0-does-not-have-a-package-available-mac-m1/35099
hashicorp/terraform-provider-template
https://github.com/hashicorp/terraform-provider-template
- git clone/go build
1 2 3 4 5 6 |
$ git clone https://github.com/hashicorp/terraform-provider-template.git $ cd terraform-provider-template $ go build . $ mkdir -p ~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64 $ mv terraform-provider-template ~/.terraform.d/plugins/registry.terraform.io/hashicorp/template/2.2.0/darwin_arm64/terraform-provider-template_v2.2.0_x5 |
- terraform init/terraform upgrade
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
$ terraform init Initializing the backend... Initializing provider plugins... - terraform.io/builtin/terraform is built in to Terraform - Reusing previous version of hashicorp/aws from the dependency lock file - Reusing previous version of hashicorp/template from the dependency lock file - Installing hashicorp/aws v4.32.0... - Installed hashicorp/aws v4.32.0 (signed by HashiCorp) - Installing hashicorp/template v2.2.0... ╷ │ Error: Failed to install provider │ │ Error while installing hashicorp/template v2.2.0: the local package for │ registry.terraform.io/hashicorp/template 2.2.0 doesn't match any of the checksums previously │ recorded in the dependency lock file (this might be because the available checksums are for │ packages targeting different platforms); for more information: │ https://www.terraform.io/language/provider-checksum-verification $ rm .terraform.lock.hcl $ terraform init Initializing the backend... Initializing provider plugins... - terraform.io/builtin/terraform is built in to Terraform - Reusing previous version of hashicorp/aws from the dependency lock file - Reusing previous version of hashicorp/template from the dependency lock file - Using previously-installed hashicorp/template v2.2.0 - Using previously-installed hashicorp/aws v4.32.0 Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. $ terraform init -upgrade Initializing the backend... Initializing provider plugins... - terraform.io/builtin/terraform is built in to Terraform - Finding latest version of hashicorp/aws... - Finding latest version of hashicorp/template... - Using previously-installed hashicorp/aws v4.32.0 - Using previously-installed hashicorp/template v2.2.0 Terraform has been successfully initialized! You may now begin working with Terraform. Try running "terraform plan" to see any changes that are required for your infrastructure. All Terraform commands should now work. If you ever set or change modules or backend configuration for Terraform, rerun this command to reinitialize your working directory. If you forget, other commands will detect it and remind you to do so if necessary. $ terraform refresh ~省略~ $ terraform state pull | grep terraform_version "terraform_version": "1.3.0", $ terraform providers Providers required by configuration: . ├── provider[registry.terraform.io/hashicorp/aws] ├── provider[terraform.io/builtin/terraform] └── provider[registry.terraform.io/hashicorp/template] Providers required by state: provider[registry.terraform.io/hashicorp/aws] provider[registry.terraform.io/hashicorp/template] provider[terraform.io/builtin/terraform] |
まとめ
https://t.co/ASxp8aSPGO
もりはやさんのおかげで、Terraform template v2.2.0 M1でterraform initできるようになった。terraform-provider-templateを使ってgoでbuildしないとあかんのかー— adachin👾SRE (@adachin0817) September 28, 2022
そういえば、intelも同じエラー出るのかしら…さっさとTemplateプロバイダーをなくして置き換えよう!もりはやさんあざした!
0件のコメント