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 #631

Closed
hashibot opened this issue Jun 13, 2017 · 4 comments
Closed

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

hashibot opened this issue Jun 13, 2017 · 4 comments
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@hashibot
Copy link

This issue was originally opened by @BlaCatRu as hashicorp/terraform#13000. It was migrated here as part of the provider split. The original body of the issue is below.


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

@hashibot hashibot added the bug Addresses a defect in current functionality. label Jun 13, 2017
@radeksimko radeksimko added the service/ec2 Issues and PRs that pertain to the ec2 service. label Jan 27, 2018
@tbugfinder
Copy link
Contributor

Will this be fixed maybe with tf 0.12 or is it an issue within the AWS provider?
As per my understanding the data provider is not queried before the resource is evaluated.

@tbugfinder
Copy link
Contributor

Is there any workaround available ?

@github-actions
Copy link

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Sep 24, 2020
@ghost
Copy link

ghost commented Nov 24, 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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/ec2 Issues and PRs that pertain to the ec2 service. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

3 participants