terraform-community-modules/tf_aws_sg

Implied variable dependencies

rvangundy opened this issue · 2 comments

I'm setting up a VPC in my terraform template and would like to pass the output ID to the sg_web module. This module requires the vpc_id to be set explicitly, but since I'm dynamically creating the vpc, I don't have this information. I would rather use variable interpolation, but because the internals of the module seem to require the variable to be set explicitly, this will not work.

I just realized that probably what's going on is terraform isn't able to determine that the module depends on the vpc resource. And since it's a module, it doesn't use the depends_on property, so I can't force it.

Is there another way I can work around this?

I have not tested it because I'm not making any VPCs with Terraform yet, but you should be able to do something like

resource "aws_vpc" "my_cool_vpc" {
    cidr_block = "10.0.0.0/16"
    instance_tenancy = "dedicated"

    tags {
        Name = "this_is_on_fleek"
    }
}

module "sg_web" {
  source = "github.com/terraform-community-modules/tf_aws_sg//sg_memcached"
  security_group_name = "${var.security_group_name}-vpc-memcached"
  aws_access_key = "${var.aws_access_key}"
  aws_secret_key = "${var.aws_secret_key}"
  aws_region = "${var.aws_region}"
  vpc_id = "${aws_vpc.my_cool_vpc.id}"
  source_cidr_block = "${var.source_cidr_block}"
}

@antonbabenko: @solarce answer is proper; it will be working as long as vpc resource outputs id. Ticket can be closed.