Implementing-Terraform-on-Microsoft-Azure
Implementing-Terraform-on-Microsoft-Azure copied to clipboard
Cannot intiliaze 1-main-vnet
I'm following the course and I've reached the first exercise 1-main-vnet . The Terraform version on Azure has evolved since the creation of the course:
$ terraform version
Terraform v0.15.1
After creating the main.tf file, I've tried initialize the project but got the following errors:
~/terraform/1-main-vnet$ terraform init
Initializing modules...
Downloading Azure/vnet/azurerm 1.2.0 for vnet-main...
- vnet-main in .terraform/modules/vnet-main
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.
╷
│ Warning: Version constraints inside provider configuration blocks are deprecated
│
│ on main.tf line 35, in provider "azurerm":
│ 35: version = "~> 1.0"
│
│ Terraform 0.13 and earlier allowed provider version constraints inside the provider configuration block, but that is now
│ deprecated and will be removed in a future version of Terraform. To silence this warning, move the provider version constraint
│ into the required_providers block.
╵
╷
│ Error: Invalid quoted type constraints
│
│ on .terraform/modules/vnet-main/variables.tf line 39, in variable "nsg_ids":
│ 39: type = "map"
│
│ Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed
│ in a future version of Terraform. Remove the quotes around "map" and write map(string) instead to explicitly indicate that the
│ map elements are strings.
╵
╷
│ Error: Invalid quoted type constraints
│
│ on .terraform/modules/vnet-main/variables.tf line 49, in variable "tags":
│ 49: type = "map"
│
│ Terraform 0.11 and earlier required type constraints to be given in quotes, but that form is now deprecated and will be removed
│ in a future version of Terraform. Remove the quotes around "map" and write map(string) instead to explicitly indicate that the
│ map elements are strings.
As a workaround, the way to fix it is to go to 1-main-vnet/.terraform/modules/vnet-main, edit the variables.tf and change type = "map" with type = map(string):
variable "nsg_ids" {
description = "A map of subnet name to Network Security Group IDs"
type = map(string)
default = {
subnet1 = "nsgid1"
subnet3 = "nsgid3"
}
}
variable "tags" {
description = "The tags to associate with your network and subnets."
type = map(string)
default = {
tag1 = ""
tag2 = ""
}
}
See: https://github.com/terraform-google-modules/terraform-google-kubernetes-engine/issues/358