Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Importing proxy only subnet is successful but then not saved in state. terraform plan shows subnet being created #559

Closed
thbriggs opened this issue May 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@thbriggs
Copy link

TL;DR

If I try to import an existing proxy only subnet I get a message saying its successful but then it doesnt show up in state.

Expected behavior

subnet to become part of state for being managed by terraform

Observed behavior

terraform plan shows a creation of the subnet

Terraform Configuration

from main.tf
resource "google_compute_subnetwork" "subnet" {
  for_each                 = var.subnetwork
  name                     = each.key
  project                  = var.project
  region                   = var.region
  ip_cidr_range            = each.value.ip_cidr_range
  private_ip_google_access = each.value.private_ip_google_access
  network                  = var.network != null ? var.network : local.network
  purpose                  = lookup(each.value, "purpose", null)
  role                     = lookup(each.value, "role", null)

from variables.tf
variable "subnetwork" {
  description = "List of subnet definitions."
  type = map(object({
    ip_cidr_range            = string
    private_ip_google_access = bool
    purpose                  = optional(string)
    role                     = optional(string)
    subnetwork_logging       = bool

from subnetworks.tf which uses the modules listed int the previous files:

locals {
  subnetworks = {
    "test-2" = {
      ip_cidr_range            = "192.168.60.0/24"
      private_ip_google_access = false
      purpose                  = "REGIONAL_MANAGED_PROXY"
      role                     = "ACTIVE"
      subnetwork_logging       = false
      log_config = []
      use_secondary_ip_range = false
      secondary_ip_range     = []
    }
  }
}

Terraform Version

Terraform v1.4.6
on darwin_arm64

Additional information

No response

@thbriggs thbriggs added the bug Something isn't working label May 10, 2024
@thbriggs thbriggs changed the title Importing proxy only subnet is successful but then not saved in state Importing proxy only subnet is successful but then not saved in state. terraform plan shows subnet being created May 10, 2024
@thbriggs
Copy link
Author

I realized I was importing the subnet wrong in the module after all.

This formatting worked. The bracketed, quoted subnet name was what I was missing.
terraform import 'module.subnetwork.google_compute_subnetwork.subnet["test-2"]' projects/[project name]/regions/us-east4/subnetworks/test-2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant