From e5b0323d1a6cdbd0a6a6df0476b50710fcae22f1 Mon Sep 17 00:00:00 2001 From: Toshinori Sugita Date: Sun, 28 Aug 2022 17:01:49 +0900 Subject: [PATCH] Add moved --- README.md | 1 + moved/.terraform.lock.hcl | 9 +++++++++ moved/README.md | 24 ++++++++++++++++++++++++ moved/main.tf | 22 ++++++++++++++++++++++ 4 files changed, 56 insertions(+) create mode 100644 moved/.terraform.lock.hcl create mode 100644 moved/README.md create mode 100644 moved/main.tf diff --git a/README.md b/README.md index 191d33b..1388b8b 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Samples are explained in the below books. * [Remote backend](./remote-backend) * [Separate state by backend end environment](./state-separation) * [terraformer](./terraformer-test) +* [moved](./moved) ## Practical edition diff --git a/moved/.terraform.lock.hcl b/moved/.terraform.lock.hcl new file mode 100644 index 0000000..603aaa0 --- /dev/null +++ b/moved/.terraform.lock.hcl @@ -0,0 +1,9 @@ +# This file is maintained automatically by "terraform init". +# Manual edits may be lost in future updates. + +provider "registry.terraform.io/hashicorp/google" { + version = "4.32.0" + hashes = [ + "h1:hGZiuBPYAQyjp4D8/nLNcNM6T+FYn1YHGM1NdBPGojQ=", + ] +} diff --git a/moved/README.md b/moved/README.md new file mode 100644 index 0000000..38b9657 --- /dev/null +++ b/moved/README.md @@ -0,0 +1,24 @@ +This example doesn't specify a credential and a project intentionally. + +```shell +$ gcloud auth application-default login + +# export GOOGLE_PROJECT=terraform-toshi0607 +# 【YOUR PROJECT】をあなたのGCPプロジェクトに置き換えてください。 +$ export GOOGLE_PROJECT=【YOUR PROJECT】 + +$ terraform init +$ terraform plan +$ terraform apply + +# Change resource name from before-move to after-move +# Confirm resource recreation (+ create and -destroy) would happen +$ terraform plan + +# Enable (comment in moved block) +# Confirm resource recreation would NOT happen +$ terraform plan +$ terraform apply + +$ terraform destroy +``` \ No newline at end of file diff --git a/moved/main.tf b/moved/main.tf new file mode 100644 index 0000000..542f21e --- /dev/null +++ b/moved/main.tf @@ -0,0 +1,22 @@ +moved { + from = google_compute_instance.before-move + to = google_compute_instance.after-move +} + +resource "google_compute_instance" "after-move" { +# resource "google_compute_instance" "before-move" { + name = "moved" + machine_type = "f1-micro" + zone = "asia-northeast1-c" + + boot_disk { + initialize_params { + # gcloud compute images list | grep debian, if the image can't be found + image = "debian-cloud/debian-11" + } + } + + network_interface { + network = "default" + } +}