You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To import the first instance, use the following command, using the Instance ID for tf-instance-1 you copied down earlier.
terraform import module.instances.google_compute_instance.tf-instance-1 <Instance ID - 1>
To import the second instance, use the following command, using the Instance ID for tf-instance-2 you copied down earlier.
terraform import module.instances.google_compute_instance.tf-instance-2 <Instance ID - 2>
The two instances have now been imported into your terraform configuration. You can now optionally run the commands to update the state of Terraform. Type yes at the dialogue after you run the apply command to accept the state changes.
terraform plan
terraform apply
Task 2. Import infrastructure
Add the following code to the modules/storage/storage.tf file:
Run the following commands to initialize the module and create the storage bucket resource. Type yes at the dialogue after you run the apply command to accept the state changes.
terraform init
terraform apply
Next, update the main.tf file so that the terraform block looks like the following. Fill in your GCP Project ID for the bucket argument definition.
terraform {
backend "gcs" {
bucket = "<FILL IN PROJECT ID>"
prefix = "terraform/state"
}
required_providers {
google = {
source = "hashicorp/google"
version = "3.55.0"
}
}
}
Run the following to initialize the remote backend. Type yes at the prompt.
terraform init
Task 3. Configure a remote backend
Navigate to modules/instances/instance.tf. Replace the entire contents of the file with the following:
Run the following commands to initialize the module and create/update the instance resources. Type yes at the dialogue after you run the apply command to accept the state changes.
terraform init
terraform apply
Task 4. Modify and update infrastructure
Taint the tf-instance-3 resource by running the following command: