terracognita
terracognita copied to clipboard
GCP compute instances feedback
General information:
- Operating System: Cycloid SaaS (InfraImport)
- Terracognita version / tag: Cycloid SaaS (InfraImport)
- Did you build Terracognita from sources or did you use the Docker image: Cycloid SaaS (InfraImport)
Describe the bug:
In the shared generated Terraform file I identified 3 issues
1) book disk definition
The actual generated code is working with plan/apply but is not valid from a Terraform point of view to recreate the instance:
boot_disk {
auto_delete = true
device_name = "instance-1"
initialize_params {
image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-10-buster-v20220310"
size = 10
type = "pd-balanced"
}
mode = "READ_WRITE"
source = "https://www.googleapis.com/compute/v1/projects/cycloid-demo/zones/europe-west1-b/disks/instance-1"
}
As you can see initialize_params
is used in addition to source
parameter.
Which raise an issue when you try to apply the code to recreate the VM after a destroy eg https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/compute_instance#initialize_params
Parameters for a new disk that will be created alongside the new instance. Either initialize_params or source must be set.
Looking on the generated code, Terracognita imported my google_compute_disk
in a dedicated resource :
resource "google_compute_disk" "europe_west1_b_cycloid_demo_demo_front_demo" {
...
So I think the expected generated code would have been using source
with interpolated value like this:
source = google_compute_disk.europe_west1_b_cycloid_demo_demo_front_demo.self_link
2) Instance resize usecase issue
A variable have been defined to change the machine_type
eg machine_type = var.google_compute_instance_cycloid_demo_europe_west1_b_instance_1_machine_type
Giving a try to change it actually want to replace (destroy/recreate) the compute instance.
machine_type Note: If you want to update this value (resize the VM) after initial creation, you must set allow_stopping_for_update to true.
To avoid this behavior it could be great to add the following Terraform flag by default on instance definition
allow_stopping_for_update = true
allow_stopping_for_update - (Optional) If true, allows Terraform to stop the instance to update its properties. If you try to update a property that requires stopping the instance without setting this field, the update will fail.
3) ephemeral nat_ip issue when destroy/create
The actual generated code for the network part is the following
network_interface {
access_config {
nat_ip = "34.79.210.126"
network_tier = "PREMIUM"
}
If I destroy/recreate the instance I got this error
Error: Error creating instance: googleapi: Error 400: Invalid value for field 'resource.networkInterfaces[0].accessConfigs[0].natIP': '34.79.154.138'. The specified external IP address '34.79.154.138' was not found in region 'europe-west1'., invalid
Looking on terraform doc:
nat_ip - (Optional) The IP address that will be 1:1 mapped to the instance's network ip. If not given, one will be generated.
This is due to the fact nat_api can be static or ephemeral eg
In case of a static IP it's ok to give a fixed value, or import a compute_address resource and use interpolation.
In case of an ephemeral IP address it would be better to not specify this parameter.
Additional context
resource "google_compute_disk" "europe_west1_b_cycloid_demo_demo_front_demo" {
labels = {
project = "obs"
}
image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-10-buster-v20220310"
name = "cycloid-demo-demo-front-demo"
physical_block_size_bytes = 4096
project = "cycloid-demo"
size = 10
type = "pd-standard"
zone = "europe-west1-b"
}
resource "google_compute_instance" "cycloid_demo_europe_west1_b_instance_1" {
labels = {
project = "obs"
}
boot_disk {
auto_delete = true
device_name = "instance-1"
initialize_params {
image = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-10-buster-v20220310"
size = 10
type = "pd-balanced"
}
mode = "READ_WRITE"
source = "https://www.googleapis.com/compute/v1/projects/cycloid-demo/zones/europe-west1-b/disks/instance-1"
}
confidential_instance_config {
enable_confidential_compute = false
}
machine_type = var.google_compute_instance_cycloid_demo_europe_west1_b_instance_1_machine_type
name = "instance-1"
network_interface {
access_config {
nat_ip = "34.79.154.138"
network_tier = "PREMIUM"
}
network = "https://www.googleapis.com/compute/v1/projects/cycloid-demo/global/networks/default"
network_ip = "10.132.15.218"
subnetwork = "https://www.googleapis.com/compute/v1/projects/cycloid-demo/regions/europe-west1/subnetworks/default"
subnetwork_project = "cycloid-demo"
}
project = "cycloid-demo"
scheduling {
automatic_restart = true
on_host_maintenance = "MIGRATE"
}
service_account {
email = "[email protected]"
scopes = ["https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/service.management.readonly", "https://www.googleapis.com/auth/servicecontrol", "https://www.googleapis.com/auth/trace.append", "https://www.googleapis.com/auth/monitoring.write"]
}
shielded_instance_config {
enable_integrity_monitoring = true
enable_vtpm = true
}
zone = "europe-west1-b"
}