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

aws_subnet resoure (imported) with a count parameter fails #13000

Closed
BlaCatRu opened this issue Mar 23, 2017 · 1 comment
Closed

aws_subnet resoure (imported) with a count parameter fails #13000

BlaCatRu opened this issue Mar 23, 2017 · 1 comment

Comments

@BlaCatRu
Copy link

Hi there,

I've imported an existing aws subnets and the state looks right
$ terraform state list
module.ireland.aws_availability_zones.available
module.ireland.aws_subnet.net[0]
module.ireland.aws_subnet.net[1]
module.ireland.aws_subnet.net[2]
module.ireland.aws_vpc.main

On refreshing the state it looses zero index
$ terraform plan
...
aws_vpc.main: Refreshing state... (ID: vpc-VVVV)
data.aws_availability_zones.available: Refreshing state...
aws_subnet.net.2: Refreshing state... (ID: subnet-ZZZZ)
aws_subnet.net.1: Refreshing state... (ID: subnet-YYYY)
aws_subnet.net: Refreshing state... (ID: subnet-XXXX)

Terraform Version

Terraform Version: 0.9.1

Affected Resource(s)

  • aws_subnet

Terraform Configuration Files

main.tf

module ireland {
  source = "modules/vpc"
  region = "eu-west-1"
}

modules/vpc/main.tf

variable "region" { type = "string" }
variable "vpc_name" { type = "string" default = "vpc" }
variable "group" { type = "string" default = "sys" }
variable "dnsnames" { type = "string" default = "true" }
variable "hostnames" { type = "string" default = "true" }
variable "public_ip" {type = "string" default = "true"}

variable "vpc_number" {
  # arbitrary mapping of region name to number to use in a VPC's CIDR prefix.
  default = {
    us-east-1      = 1 # nvirginia
    us-west-1      = 2 # ncalifornia
    us-west-2      = 3 # oregon
    eu-west-1      = 4 # ireland
    eu-central-1   = 5 # frankfurt
    sa-east-1      = 6 # saopaolo
    us-east-2      = 7 # ohio
    ap-southeast-1 = 8 # singapore
  }
}

provider "aws" {
  region = "${var.region}"
}

resource "aws_vpc" "main" {
    cidr_block = "${cidrsubnet("10.0.0.0/8", 8, var.vpc_number[var.region])}"
    enable_dns_support = "${var.dnsnames}"
    enable_dns_hostnames = "${var.hostnames}"
    tags {
        Name = "${var.vpc_name}${var.vpc_number[var.region]}"
        group = "${var.group}"
    }
}

data "aws_availability_zones" "available" {}

resource "aws_subnet" "net" {
  count = "${length(data.aws_availability_zones.available.names)}"
  vpc_id = "${aws_vpc.main.id}"
  availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
  cidr_block = "${cidrsubnet("${aws_vpc.main.cidr_block}", 4, "${count.index}")}"
  map_public_ip_on_launch = "${var.public_ip}"
  tags {
    group = "${var.group}"
    Name = "${var.vpc_name}${var.vpc_number[var.region]}net${join("",slice(split("",data.aws_availability_zones.available.names[count.index]), length(var.region) - 1, length(var.region) + 1))}"
  }
}

Debug Output

https://gist.github.com/BlaCatRu/71c745b9d46d351690986f0c5f93639c

@ghost
Copy link

ghost commented Apr 9, 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 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants