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

Private Subnet management is destructive #403

Closed
ghost opened this issue Mar 9, 2020 · 10 comments
Closed

Private Subnet management is destructive #403

ghost opened this issue Mar 9, 2020 · 10 comments

Comments

@ghost
Copy link

ghost commented Mar 9, 2020

We are creating a set of private subnets, and one of our use cases is the ability to add and remove subnets at will. We notice that the creation of subnets seems to have the "count issue", where if for example, another private subnet is added after the first of three, the second and third are deleted and recreated after the (new) second one is created. Needless to say, this would be disruptive to anyone using the second and third private subnets.

Is there a workaround for this, other than modifying the relevant code to use for_each instead of count?

@dpiddockcmp
Copy link

Quick answer: no. Terraform does not play well with modifying lists.

Suggestions:

  • Only append or delete from the end of the list
  • Modify the state file by shifting items in the list before doing plan/apply: terraform state mv resource[n] resource[n+1]

In both of these cases you will see knock on issues with other resources not just the subnet. NAT gateways, route tables, routes, etc etc. Terraform also seems to like to trigger full recreation of dependent resources if an item in a counted resource is unknown.

Best option for your usecase would be a forked/new module that uses for_each.

@achachw
Copy link

achachw commented Oct 6, 2020

Hi
Why don't use a map instead of list to define subnets,to avoid this behaviour
We can for example define a public subnet like this :

public-subnets = {
  subnet1 = {
    cidr = 10.0.11.0/24,
    az    = "eu-west-1b"
  },
  subnet2 = {
    cidr = 10.0.11.0/24,
    az    = "eu-west-1c"
  }
}

What do you this about this ?

@barryib
Copy link
Member

barryib commented Oct 6, 2020

Hi @antonbabenko,

How can we move forward on this ? Can we work on a PR to add map support ? How do we handle breaking changes ?

Related to #178

@antonbabenko
Copy link
Member

@barryib Good question. Let's discuss it during our own meeting on Friday.

@Nickmman
Copy link

Nickmman commented Apr 5, 2021

Hi there, we've run into this same issue and think that using the for_each method instead of the count method would resolve this issue.

Have talks on this improvement stalled?

@github-actions
Copy link

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@github-actions github-actions bot added the stale label Feb 11, 2022
@github-actions
Copy link

This issue was automatically closed because of stale in 10 days

@dusansusic
Copy link

Any plans for this?

@bryantbiggs
Copy link
Member

there are plans and some preliminary work underway on what a potential v4 *might look like which would look to solve problems such as this - you can track that here if interested https://github.com/clowdhaus/terraform-aws-vpc-v4

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2022
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

7 participants