-2

variables.tf

variable "region" {
  default = "us-central1"
}

variable "zone" {
  description = "override default zone specified in region_params"
  default     = ""
}

variable "region_params" {
  description = "Map of default zones for each region. Can be overridden using the `zone`."
  type        = map(string)

  default = {
    asia-east1 = {
      zone = "asia-east1-b"
    }
    asia-east2 = {
      zone = "asia-east2-b"
    }
    asia-northeast1 = {
      zone = "asia-northeast1-b"
    }
    asia-south1 = {
      zone = "asia-south1-b"
    }
    asia-southeast1 = {
      zone = "asia-southeast1-b"
    }
    australia-southeast1 = {
      zone = "australia-southeast1-b"
    }
    europe-north1 = {
      zone = "europe-north1-b"
    }
    europe-west1 = {
      zone = "europe-west1-b"
    }
    europe-west2 = {
      zone = "europe-west2-b"
    }
    europe-west3 = {
      zone = "europe-west3-b"
    }
    europe-west4 = {
      zone = "europe-west4-b"
    }
    northamerica-northeast1 = {
      zone = "northamerica-northeast1-b"
    }
    southamerica-east1 = {
      zone = "southamerica-east1-b"
    }
    us-central1 = {
      zone = "us-central1-b"
    }
    us-east1 = {
      zone = "us-east1-b"
    }
    us-east4 = {
      zone = "us-east4-b"
    }
    us-west1 = {
      zone = "us-west1-b"
    }
    us-west2 = {
      zone = "us-west2-b"
    }
  }
}

variable "network" {
}

variable "instance_tags" {
  default = []
}

variable "ip_cidr_range" {
  description = "Subnetwork range - required"
}

variable "environment" {
  description = "The build environment tier"
  default     = "dev"
}

output "nat-gateway-ip" {
  value = module.nat.external_ip
}

./terraform0.13 init -reconfigure

There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.
╷
│ Error: Invalid default value for variable
│
│   on variables.tf line 71, in variable "region_params":
│   71:   default = {
│   72:     asia-east1 = {
│   73:       zone = "asia-east1-b"
│   74:     }
│   75:     asia-east2 = {
│   76:       zone = "asia-east2-b"
│   77:     }
│   78:     asia-northeast1 = {
│   79:       zone = "asia-northeast1-b"
│   80:     }
│   81:     asia-south1 = {
│   82:       zone = "asia-south1-b"
│   83:     }
│   84:     asia-southeast1 = {
│   85:       zone = "asia-southeast1-b"
│   86:     }
│   87:     australia-southeast1 = {
│   88:       zone = "australia-southeast1-b"
│   89:     }
│   90:     europe-north1 = {
│   91:       zone = "europe-north1-b"
│   92:     }
│   93:     europe-west1 = {
│   94:       zone = "europe-west1-b"
│   95:     }
│   96:     europe-west2 = {
│   97:       zone = "europe-west2-b"
│   98:     }
│   99:     europe-west3 = {
│  100:       zone = "europe-west3-b"
│  101:     }
│  102:     europe-west4 = {
│  103:       zone = "europe-west4-b"
│  104:     }
│  105:     northamerica-northeast1 = {
│  106:       zone = "northamerica-northeast1-b"
│  107:     }
│  108:     southamerica-east1 = {
│  109:       zone = "southamerica-east1-b"
│  110:     }
│  111:     us-central1 = {
│  112:       zone = "us-central1-f"
│  113:     }
│  114:     us-east1 = {
│  115:       zone = "us-east1-b"
│  116:     }
│  117:     us-east4 = {
│  118:       zone = "us-east4-b"
│  119:     }
│  120:     us-west1 = {
│  121:       zone = "us-west1-b"
│  122:     }
│  123:     us-west2 = {
│  124:       zone = "us-west2-b"
│  125:     }
│  126:   }
│
│ This default value is not compatible with the variable's type constraint: element "asia-east2": string required.
uday
  • 257
  • 2
  • 21

1 Answers1

1

Try setting it to us-central-1. You're formatting your regions wrong, you need a dash before the number. Additionally you don't need to specify a, b, or c since terraform gets the information from your subnet setting.

Some Linux Nerd
  • 3,157
  • 3
  • 18
  • 20
  • SOrry I didn't mention the cloud, GCP. For GCP it is the structure – uday Aug 06 '21 at 04:41
  • On second though you're possibly not using a map correctly and might be defining it wrong. Also... I wouldn't define zone as a variable. A map is like an array that uses names instead of numbers, so there's two problems. By defining zone you might be making it both a variable and a map index. Also each map [index] (if thats the right term) should be unique. Here's an example: https://www.devopsschool.com/blog/terraform-variable-map-type-explained/ – Some Linux Nerd Aug 13 '21 at 00:18
  • I'm afraid I really don't know anything about GCP. You might want to check that you're using an up to date copy of terraform and you might even want to delete .terraform and run terraform init again to redownload your libraries. – Some Linux Nerd Aug 13 '21 at 00:18
  • Invalid default value really makes sense when you compare the example against what you have. It probably means that you're (literally) defining the default map wrong. – Some Linux Nerd Aug 13 '21 at 00:22