Hi,
I try to understand some of the subject’s Terraform.
- I removed one block of code in main.tf by deleting it.
resource “google_compute_instance” “sample” {
name = “any”
machine_type = “e2-micro”
boot_disk {
initialize_params {
image = “debian-cloud/debian-11”
}
}
}
I saw then I can do the same with:
terraform taint google_compute_instance.sample
Then terraform init/apply.
Whihc method should I use on production? Why? Currently I am practicing only in my dev. env.
- I removed
terraform.tfstate
file and then when I runterraform init
andterraform apply
I got the error:
│ Error: Error creating Network: googleapi: Error 409: The resource ‘projects/env/regions/us-west1/subnetworks/my-network’ already exists, alreadyExists
│
│ with google_compute_network.sample_network,
│ on main.tf line 7, in resource “google_compute_network” “sample_network”:
│ 7: resource “google_compute_network” “sample_network” {
How to fix it? I mean how to sync again Terraform with the cloud gcp configuration. In fact there was already sample_network
already but if so I expected to see nothing to update etc.
- Sorry for dumb question, but if that first block is always mandatory? (marked in bold) Or what does it?
terraform {
backend “gcs” {
bucket = “tf-bucket”
prefix = “terraform/state”
}
required_providers {
google = {
source = “hashicorp/google”
version = “4.51.0”
}
}
}
provider “google” {
project = var.project_id
region = var.region
zone = var.zone
}
I am asking since If I am correct my first attempts of terraform file creation work fine without terraform
block. Then I added google_storage_bucket
so I had to add that block marked in bold. What is the practice? I used that doc for provider google
: Terraform Registry however I am wondering about that terraform
and required_providers
block.
Thanks!