11 มิถุนายน 2566

terraform import existing GCP resources to terraform module

If you want to import your existing resources, e.g., existing GCP compute engine instance, to your terraform module. Try steps below.


Your terraform code structure will look like this

main.tf

module "instances" {
source = "./modules/instances"
}


modules/instances.tf

resource "google_compute_instance" "tf-instance-1" {
name = "tf-instance-1"
machine_type = "n1-standard-1"
boot_disk {
initialize_params {
image = "debian-10-buster-v20230510"
}
}
network_interface {
network = "default"

access_config {
}
}
metadata_startup_script = <<-EOT
#!/bin/bash
EOT
allow_stopping_for_update = true
# other config
}


You can use this command to import your existing GCP compute engine instance to your terraform module

terraform import module.instances.google_compute_instance.tf-instance-1 tf-instance-1

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

บทความยอดนิยม (ล่าสุด)

บทความยอดนิยม (1 ปีย้อนหลัง)