Hi,
I am trying to upgrade to Terraform 0.12 from Terraform 0.11.14, however, I am getting issues when trying to define resources that use different providers.
For instance, I try to define a resource such that:
variable region {}
resource "...." "..." {
provider = "kubernetes.mycluster-${var.region}"
...
}
But terraform 0.12 gives this error:
Error: Invalid provider reference
Provider argument requires a provider name followed by an optional alias, like "aws.foo".
I am not sure what is the correct way of templating here.
Thanks!
EDIT: Minimum reproducible example
Template for Terraform 0.11.14 (works as expected)
variable "region" {}
provider "google" {
credentials = "${file("adc.json")}"
project = "my-project-id"
region = "${var.region}"
}
provider "kubernetes" {
alias = "cluster-${var.region}"
}
resource "kubernetes_config_map" "autoscaler" {
provider = "kubernetes.cluster-${var.region}"
metadata {
name = "autoscaler"
}
data {
"foo" = "bar"
}
}
Upgraded template using terraform 0.12upgrade
variable "region" {
}
provider "google" {
credentials = file("adc.json")
project = "my-project-id"
region = var.region
}
provider "kubernetes" {
alias = "cluster-$${var.region}"
}
resource "kubernetes_config_map" "autoscaler" {
provider = "kubernetes.cluster-$${var.region}"
metadata {
name = "autoscaler"
}
data = {
"foo" = "bar"
}
}
Notice that it produces the provider alias as kubernetes.cluster-$${var.region}
which would be translate to this string literal kubernetes.cluster-${var.region}
rather than kubernetes.cluster-central1
if the value provided for region
was central1
.
If I remove the double $$
and replace it with a single $
for string interpolation, I get the following error using client version 0.12:
Error: Invalid provider configuration alias
An alias must be a valid name. A name must start with a letter and may contain
only letters, digits, underscores, and dashes.
Error: Unsuitable value type
on master.tf line 11, in provider "kubernetes":
11: alias = "cluster-${var.region}"
Unsuitable value: value must be known
Error: Variables not allowed
on master.tf line 11, in provider "kubernetes":
11: alias = "cluster-${var.region}"
Variables may not be used here.
Error: Invalid provider configuration reference
on master.tf line 15, in resource "kubernetes_config_map" "autoscaler":
15: provider = "kubernetes.cluster-${var.region}"
A provider configuration reference must not be given in quotes.