Terraform: provider/aws: aws_db_instance replica requires Region

Created on 8 Feb 2017  ·  23Comments  ·  Source: hashicorp/terraform

When attempting to create an AWS RDS instance replica in EC2 Classic, I receive an error:

* aws_db_instance.replica: Error creating DB Instance: MissingRegion: could not find region configuration

I cannot find an option to specify the region and manually setting the AZ seems not to have the region inferred.

A brief look through the terraform source code looks to me that this cannot be set, however the AWS Go SDK does seem to accept the region as a parameter.

Creating the resource manually and importing it works. But I do not see a region parameter attached to the imported resource.

Terraform Version

Terraform v0.8.6 (and tested with v0.7.13)

Affected Resource(s)

  • aws_db_instance

Terraform Configuration Files

_Note: This is running in EC2 Classic_

# The leader is created without issue
resource "aws_db_instance" "leader" {
  allocated_storage = 5
  engine            = "postgres"
  engine_version    = "9.5.4"

  instance_class = "db.m3.medium"

  # DBName must begin with a letter and contain only alphanumeric characters
  name     = "${var.db-name}"
  username = "${var.db-username}"
  password = "${var.db-password}"

  security_group_names = [
    "${aws_db_security_group.db.name}",
  ]

  parameter_group_name        = "${aws_db_parameter_group.db.name}"
  storage_type                = "gp2"
  multi_az                    = true
  publicly_accessible         = true
  storage_encrypted           = true
  auto_minor_version_upgrade  = false
  allow_major_version_upgrade = false
  backup_retention_period     = 7
  apply_immediately = ""

  tags {
    Creator = "terraform"
  }
}

resource "aws_db_instance" "replica" {
  allocated_storage = 5
  engine            = "postgres"
  engine_version    = "9.5.4"

  instance_class = "db.m3.medium"

  username = "${var.db-username}"

  security_group_names = [
    "${aws_db_security_group.db.name}",
  ]

  replicate_source_db = "${aws_db_instance.leader.id}"

  parameter_group_name        = "${aws_db_parameter_group.db.name}"
  storage_type                = "gp2"
  multi_az                    = false
  publicly_accessible         = true
  storage_encrypted           = true
  auto_minor_version_upgrade  = false
  allow_major_version_upgrade = false
  backup_retention_period     = 0
  apply_immediately = ""

  tags {
    Creator = "terraform"
  }
}

Expected Behavior

I should be able to create the RDS replica.

Actual Behavior

I receive the error:

* aws_db_instance.replica: Error creating DB Instance: MissingRegion: could not find region configuration

Steps to Reproduce

  1. terraform apply

Important Factoids

Running in EC2 Classic

References

  • GH-11784 may be related, but I'm 100% sure.
bug provideaws

Most helpful comment

Great news! It appears to be an SDK bug and has been patched!

We'll update to the next release when it comes out

All 23 comments

@agy Hi,

I believe the Region gets inferred when the "db_subnet_group" option is specified, as that contains the appropriate subnets to be used. However, because you're using encrypted db you'll run into the issue @gdowmont and I have raised in #11784 .

I'm taking a stab at a PR for this, but it's my first time with Go! 😄

@JoshiiSinfield since I'm using EC2 Classic there are no subnets to specify. That said, your work may well fix my issue too.

I'm getting this same error and my db is not encrypted. It was working fine when we were at 0.8.5.

terraform v0.8.6 has same issue for regular RDS without encryption.
I tested cross region function on regular RDS v0.8.5 and v0.7.13, it was fine.
I also tested create same region read replica, the function works for v0.8.5 and 0.7.13 but not v.0.8.6

aws_db_instance.example_slave: Error creating DB Instance: MissingRegion: could not find region configuration
Open another issue https://github.com/hashicorp/terraform/issues/11891

I tested with a v0.8.5's aws provider and terraform v0.8.6 and it works fine, so the problem does not come from the core:

$ git clone [email protected]:hashicorp/terraform.git
$ git checkout v0.8.5
$ XC_OS=linux XC_ARCH=amd64 make plugin-dev PLUGIN=provider-aws

I can confirm with @mcanevet said, Terraform v0.8.6 with the v0.8.5 AWS provider works

In my case I was creating a storage_encrypted MySQL 5.5 read replica from a storage_encrypted master in VPC (not Classic like some other users reported)

So, according to what other users reported, it seems it happens for both EC2 and Classic and both encrypted and not encrypted databases

Hope this helps!

I'm experiecing the same issue with 0.8.6 and 0.8.7, it really seems that creating a read replica with aws at the moment is broken. I'm creating a db with encryption.
Update : 0.8.5 works .

The same - I'm getting "Error creating DB Instance: MissingRegion: could not find region configuration" on both 0.8.6 and 0.8.7 when creating read replica on VPC.
Tried to explicitly set db_subnet_group_name (instead of default) - no luck.

I am also getting the same error while trying to create a read replica in VPC on 0.8.7

I got the same error as well with 0.8.6. I had to create the replica manually and import it to get around this.

I am hitting this on .8.7 as well.

Even with encrypted storage disabled.

Here is the error I get with Terraform 0.8.7 (I tried the beta for 0.9.0 but got a completely unrelated error):


* aws_db_instance.core_postgres_replica: Error creating DB Instance: MissingRegion: could not find region configuration

And here is my terraform code:


resource "aws_db_subnet_group" "core_postgres_subnet_group" {
    name = "core_postgres"
    subnet_ids = ["${aws_subnet.az1_postgres_subnet.id}", "${aws_subnet.az2_postgres_subnet.id}"]
    tags {
        Name = "Core Postgres DB subnet group"
    }
}

resource "aws_db_instance" "core_postgres_master" {
  allocated_storage        = 5 # gigabytes
  backup_retention_period  = 7   # in days
  db_subnet_group_name     = "${aws_db_subnet_group.core_postgres_subnet_group.id}"
  engine                   = "postgres"
  # engine_version           = "9.5.4"
  identifier               = "core-master"
  instance_class           = "db.r3.large"
  multi_az                 = true
  name                     = "coredatabase"
  password                 = "postgres"
  port                     = 5432
  publicly_accessible      = false
  storage_encrypted        = false
  storage_type             = "gp2"
  username                 = "postgres"
  vpc_security_group_ids   = ["${aws_security_group.postgres.id}"]
}

resource "aws_db_instance" "core_postgres_replica" {
  allocated_storage        = 5 # gigabytes
  backup_retention_period  = 7   # in days
  db_subnet_group_name     = "${aws_db_subnet_group.core_postgres_subnet_group.id}"
  engine                   = "postgres"
 # engine_version           = "9.5.4"
  identifier               = "core-replica"
  instance_class           = "db.r3.large"
  multi_az                 = true
  name                     = "coredatabase"
  replicate_source_db      = "coredatabase"
  password                 = "postgres"
  port                     = 5432
  publicly_accessible      = false
  storage_encrypted        = false
  storage_type             = "gp2"
  username                 = "postgres"
  vpc_security_group_ids   = ["${aws_security_group.postgres.id}"]
}


Same issues with applying replica for MySQL

2017/02/22 19:48:12 [DEBUG] apply: aws_db_instance.database_replica: executing Apply
2017/02/22 19:48:12 [DEBUG] root: eval: *terraform.EvalWriteState
2017/02/22 19:48:12 [DEBUG] root: eval: *terraform.EvalApplyProvisioners
2017/02/22 19:48:12 [DEBUG] root: eval: *terraform.EvalIf
2017/02/22 19:48:12 [DEBUG] root: eval: *terraform.EvalWriteState
2017/02/22 19:48:12 [DEBUG] root: eval: *terraform.EvalWriteDiff
2017/02/22 19:48:12 [DEBUG] root: eval: *terraform.EvalApplyPost
2017/02/22 19:48:12 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:

* aws_db_instance.database_replica: Error creating DB Instance: Missingdatabase: could not find database configuration
2017/02/22 19:48:12 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:

* aws_db_instance.database_replica: Error creating DB Instance: Missingdatabase: could not find database configuration
2017/02/22 19:48:12 [TRACE] [walkApply] Exiting eval tree: aws_db_instance.database_replica
2017/02/22 19:48:12 [TRACE] [walkApply] Exiting eval tree: module.mod_data_center.output.network_dmz
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "module.mod_data_center.output.network_dmz"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.aws_database"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.acl_allowed_ba_lan"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "output.haproxy01_eip"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "module.mod_data_center.output.network_green"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.public_key_path"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "aws_db_instance.database_replica"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "module.mod_data_center.output.vpc_id"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "module.mod_data_center.output.network_red"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.haproxy_ami"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.vpc_details"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "module.mod_fw_rules.output.ELB_Web_Server"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "module.mod_fw_rules.output.INS_Web_Server"
2017/02/22 19:48:12 [DEBUG] vertex "meta.count-boundary (count boundary fixup)", got dep: "var.key_name"
2017/02/22 19:48:12 [ERROR] Shadow graph error: 1 error(s) occurred:

And here is TF

resource "aws_db_instance" "database_replica" {
  identifier              = "${lookup(var.rds_name,var.stack_tags["stack_name"])}-replicadb"
  allocated_storage       = 50
  engine                  = "mysql"
  engine_version          = "5.6.27"
  storage_type            = "gp2"
  instance_class          = "${lookup(var.rds_replica_class, var.stack_tags["stack_name"])}"
  name                    = "databasereplica"
  username                = "admin"
  password                = "${var.rds_password}"
  vpc_security_group_ids  = ["${aws_security_group.INS_DB_RO_RDS.id}"]
  db_subnet_group_name    = "${aws_db_subnet_group.rds-subnet-green.id}"
  parameter_group_name    = "${aws_db_parameter_group.rds-mysql-rw.id}"
  backup_retention_period = "14"

  #skip_final_snapshot       = false
  final_snapshot_identifier = "${var.stack_tags["stack_id"]}-db-FINAL"
  multi_az                  = "${lookup(var.rds_multiaz, var.stack_tags["stack_name"])}"
  copy_tags_to_snapshot     = true
  maintenance_window        = "Sun:01:00-Sun:04:00"
  backup_window             = "04:00-05:00"
  replicate_source_db       = "${aws_db_instance.database_master.arn}"

  tags {
    "Name"          = "replicadb"
  }

}

Maybe indirectly ? the issue is affecting same region replicas...

also hit in terraform 0.8.8 with RDS MySQL

Finding the same issue in .0.8.8

resource "aws_db_instance" "db01" {
identifier = "db01"
allocated_storage = 1024
engine = "mysql"
engine_version = "5.6.34"
instance_class = "db.m4.xlarge"
name = "mydb"
username = "Username"
password = "Password"
parameter_group_name = "slave-pg"
vpc_security_group_ids = ["${aws_security_group.vpc_mysql.id}"]
replicate_source_db = "${aws_db_instance.mysql-core.id}"
backup_retention_period = 7
storage_type = "gp2"
apply_immediately = true
}

I'm with terraform v0.8.8 and I've got the same error:

  • aws_db_instance.read_replica_rds_instance: Error creating DB Instance: MissingRegion: could not find region configuration

Hey all – sorry for the delay here. I've reproduced this but I'm not 100% sure yet that the root of it is in Terraform itself. I've opened https://github.com/aws/aws-sdk-go/issues/1127 and hope to hear more soon!

Great news! It appears to be an SDK bug and has been patched!

We'll update to the next release when it comes out

This has been fixed in 1.7.9 of the SDK. Please let us know if anyone has any more issues. Cheers!

Thanks @xibz ! We have a pr open to bump the sdk here https://github.com/hashicorp/terraform/pull/12680 and will merge as soon as some tests pass locally. We appreciate the quick fix 😄

I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings