Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with new aws_vpc data source #9377

Closed
jamtur01 opened this issue Oct 14, 2016 · 2 comments
Closed

Issue with new aws_vpc data source #9377

jamtur01 opened this issue Oct 14, 2016 · 2 comments

Comments

@jamtur01
Copy link
Contributor

Terraform Version

0.7.6

Affected Resource(s)

  • aws_vpc data source

Terraform Configuration Files

variable "vpc_id" {}

data "aws_vpc" "environment_api" {
  id = "${var.vpc_id}"
}

resource "aws_instance" "api" {
  ami           = "${lookup(var.ami, var.region)}"
  instance_type = "${var.instance_type}"
  key_name      = "${var.key_name}"
  subnet_id     = "${element(var.public_subnet_ids, 1)}"
  user_data     = "${file("files/api_bootstrap.sh")}"
  vpc_security_group_ids = [
    "${aws_security_group.api_host_sg.id}"
  ]
  tags {
    Name = "${var.environment}-api-${count.index}"
  }
  count = 5
}

resource "aws_elb" "api" {
  name                = "${var.environment}-api-elb"
  subnets             = ["${element(var.public_subnet_ids, 1)}"]
  security_groups     = ["${aws_security_group.api_inbound_sg.id}"]
  listener {
    instance_port     = 80
    instance_protocol = "http"
    lb_port           = 80
    lb_protocol       = "http"
  }
  instances = ["${aws_instance.api.*.id}"]
}

resource "aws_security_group" "api_inbound_sg" {
  name        = "${var.environment}-api_inbound"
  description = "Allow API from Anywhere"
  vpc_id      = "${var.vpc_id}"

  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 8
    to_port     = 0
    protocol    = "icmp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

resource "aws_security_group" "api_host_sg" {
  name        = "${var.environment}-api_host"
  description = "Allow SSH & HTTP to api hosts"
  vpc_id      = "${var.vpc_id}"

  ingress {
    from_port   = 22
    to_port     = 22
    protocol    = "tcp"
    cidr_blocks = ["0.0.0.0/0"]
  }

  # HTTP access from the VPC
  ingress {
    from_port   = 80
    to_port     = 80
    protocol    = "tcp"
    cidr_blocks = ["${aws_vpc.environment_api.cidr_block}"]
  }

  egress {
    from_port   = 0
    to_port     = 0
    protocol    = "-1"
    cidr_blocks = ["0.0.0.0/0"]
  }

  ingress {
    from_port   = 8
    to_port     = 0
    protocol    = "icmp"
    cidr_blocks = ["0.0.0.0/0"]
  }
}

Debug Output

https://gist.github.com/jamtur01/bfc5378ec6b6699355b0ba6665d84964

Expected Behavior

Expect the module to download and work.

Actual Behavior

Module load fails with:

Error loading Terraform: module api.root: 1 error(s) occurred:

* resource 'aws_security_group.api_host_sg' config: unknown resource 'aws_vpc.environment_api' referenced in variable aws_vpc.environment_api.cidr_block

Steps to Reproduce

  1. terraform get -update

References

#6819 (and @apparentlymart probably?)

@jamtur01
Copy link
Contributor Author

Oh goddamit. Variable naming. Should be:

data.aws_vpc.environment_api...

PEBCAK. Suspect this means some of the docs are wrong. Will look.

@ghost
Copy link

ghost commented Apr 21, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant