Ask questions"Error: Provider configuration not present" when aliased provider is used
Terraform v0.12.0
With terraform version 0.11.10, the files below work as expected.
initially the providers section in the config below was absent, but it was added to try and troubleshoot the issue. The same results happen if it is absent or present.
provider "aws" {
region = "us-west-2"
alias = "env"
}
provider "aws" {
region = "us-west-2"
}
provider "google" {
credentials = "${file("gcp.json")}"
region = "us-central1"
project = "orv5-236500"
}
module "network" {
source = "../../../../terraform-modules/gcp/network"
cluster = "testpad8"
region = "us-central1"
domain = "scratchpad.objectrocket.cloud"
providers = {
aws.env = "aws.env"
google = "google"
aws = "aws"
}
}
The network module is the first part we're porting and testing with TF12. The locals/inputs are in different files in the module.
# DNS Setup
# Parent Zone in Route53 to create subdomains in
data "aws_route53_zone" "main" {
provider = "aws.env"
name = "${var.domain}"
}
# DNS Zone in GCP for the cluster
resource "google_dns_managed_zone" "cluster" {
name = "${local.cluster_domain}"
dns_name = "${local.cluster_domain}"
description = "Domain for CLUSTER: ${var.cluster}"
visibility = "public"
labels = "${merge(var.extra_labels,
map("Name", "${local.cluster_domain}"),
map("launchpad_cluster", "${var.cluster}"))}"
}
# DNS delegation records in the main environment domain
resource "aws_route53_record" "environment-ns" {
provider = "aws.env"
zone_id = "${data.aws_route53_zone.main.zone_id}"
name = "${local.cluster_domain}"
type = "NS"
ttl = "30"
records = [
"${google_dns_managed_zone.cluster.name_servers.*}",
]
}
# Create a zone for mongo product to publish records to
resource "google_dns_managed_zone" "mongo" {
name = "m.${local.cluster_domain}"
dns_name = "m.${local.cluster_domain}"
description = "Domain for mongo records in CLUSTER: ${var.cluster}"
visibility = "public"
labels = "${merge(var.extra_labels,
map("Name", "${local.cluster_domain}"),
map("launchpad_cluster", "${var.cluster}"))}"
}
# Create a delegation for the m.$var.cluster.$environment domain
resource "google_dns_record_set" "environment-mongo-ns" {
managed_zone = "${google_dns_managed_zone.cluster.name}"
name = "m.${google_dns_managed_zone.cluster.dns_name}"
type = "NS"
ttl = "30"
rrdatas = [
"${google_dns_managed_zone.mongo.name_servers.*}",
]
}
# Create the wildcard in the mongo domain
resource "google_dns_record_set" "mongo-wildcard" {
managed_zone = "${google_dns_managed_zone.mongo.name}"
name = "*"
type = "CNAME"
ttl = "30"
rrdatas = ["${format("ingress.%s", local.cluster_domain)}"]
}
https://gist.github.com/ephur/e8ce912655adcb1909c9b565efe2b84a
N/A error message is:
Error: Provider configuration not present
To work with module.network.aws_route53_record.environment-ns its original
provider configuration at module.network.provider.aws.env is required, but it
has been removed. This occurs when a provider configuration is removed while
objects created by that provider still exist in the state. Re-add the provider
configuration to destroy module.network.aws_route53_record.environment-ns,
after which you can remove the provider configuration again.
Plan should have executed, adding a zone in GCP, and NS records in AWS with delegations to the subdomain created in GCP.
Error message indicates a state that does not exist, no prior state existed.
This happens when running
terraform init
terraform plan
We do run terraform via a wrapper, however in this case the wrapper is not used, and it's just a test to call the module to ensure the module works as expected. The test is run manually.
I found similar issues but it looked like in each of those cases the provider configuration was being done inside of the module. In our case the provider configuration is done in the main terraform and passed into the module.
Answer
questions
dimisjim
@scalp42
main.tf
variable "region" {
default = "eu-west-1"
}
provider "aws" {
region = var.region
version = "~> 2.19.0"
}
provider "aws" {
alias = "us-east-1"
region = "us-east-1"
}
inside a module that needs to use a provider in a different region:
provider "aws" {
alias = "us-east-1"
region = "us-east-1"
}
In 0.11, there was no need for specifying the alias provider twice. Apparently, the above was the only way I could get it to work in 0.12.
Related questions