terraform:import
to import a resource on tfstate in case of tfstate lost follow these steps:
- Ordered List Itemfind the resource to import (in this example a cluster GKE)
in this case we need to find the cluster name, and cluster location [ <cluster-name>,projects/<project-id>/locations/<location>/clusters/<cluster-name> ] the other requested information may change with the case - define the resource in a tf file, for example import.tf with the contents:
resource "google_container_cluster" "resource-name" { name = "cluster-name" location = "location" initial_node_count = 1 network = "projects/<project-id within the network>/global/networks/<network name>" master_authorized_networks_config { dynamic "cidr_blocks" { for_each = var.master_authorized_networks_cidr_blocks content { cidr_block = cidr_blocks.value.cidr_block display_name = cidr_blocks.value.display_name } } } dns_config { # forces replacement cluster_dns = "CLOUD_DNS" #it depends on original creation cluster_dns_domain = "domain.name" #it depends on original creation cluster_dns_scope = "CLUSTER_SCOPE" #it depends on original creation } timeouts { #it depends on original creation create = null delete = null read = null update = null } } - importing resource issuing the command:
terraform import google_container_cluster.<resource-name> projects/<project-id>/locations/<location>/clusters/<cluster-name>
terraform/import.txt · Last modified: 2024/11/10 08:01 by 127.0.0.1
