Terraform: resource depends on non-existent resource when using depends_on

Created on 17 Feb 2015  ยท  4Comments  ยท  Source: hashicorp/terraform

Hi,
I have ran into an issue with a simple config trying to use depends_on and receiving an error.

  • aws_db_instance.db_main: resource depends on non-existent resource '${aws_db_subnet_group.db_subnet}'

tf.config:

tell terraform what provider we are gonig to use

provider "aws" {
    region = "us-west-2"
}

resource "aws_db_subnet_group" "db_subnet" {
    name = "DBSubnet"
    description = "assign the other two VPC subnets"

    subnet_ids = ["${var.second_subnet}", "${var.third_subnet}"]
}

resource "aws_db_instance" "db_main" {
    #depends_on = ["${var.dbsg_name}"]
    #depends_on = "DBSubnet"
    depends_on = "${aws_db_subnet_group.db_subnet}"
    identifier = "DBONE"
    allocated_storage = 5
    engine = "mysql"
    engine_version = "5.6.19b"
    instance_class = "db.t1.micro"
    name = "mydb"
    username = "jason"
    password = "DB0p3nm3"
    vpc_security_group_ids = ["${var.sg_name}"]
    #security_group_names = ["${aws_db_security_group.db.name}"]
    db_subnet_group_name = "DB Subnet"
    #parameter_group_name = "default.mysql5.6"
    final_snapshot_identifier = "snap"
    skip_final_snapshot = "true"
}

This my RDS module to spin up a sql DB, I am wanting terraform to wait an attempt to provision the DB until after the DB subnet net group is online to avoid this issue when I apply my plan:

module.rds2.aws_db_instance.db_main: Error: Error creating DB Instance: DBSubnetGroupNotFoundFault: DBSubnetGroup 'db subnet' not found.

module.rds.aws_db_subnet_group.db_subnet: Creation complete

I tried using depends_on with a variable populated from another module, failed also tried using it in various ways within the same .tf file and still fails. I am rather new to using Terraform, so if it is a simple syntax issue sorry to bother you, but it seems like it should be correct. Any help would be appreciated.

bug core

All 4 comments

depends_on can't contain variables. It must be hardcoded. We should add validation to verify this.

Thanks makes sense

Reopening until we get the PR merged in to do the validation. :)

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