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

SetSubnets not allowed on LB type network (supersedes #1941) #2293

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion aws/resource_aws_lb.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,16 @@ func resourceAwsLbUpdate(d *schema.ResourceData, meta interface{}) error {

}

if d.HasChange("subnets") {
if d.HasChange("subnets") && !d.IsNewResource() {
// subnets are assigned at Create; the 'change' here is an empty map for old
// and current subnets for new, so this change is redundant when the
// resource is just created.
if d.Get("load_balancer_type").(string) == "network" {
// Load Balancers of type 'network' cannot update their subnets at this
// time.
return fmt.Errorf("Unable to update subnets for loadbalancer %s, updating subnets is not supported for type network. Please use the 'taint' command to force a recreation of this resource", d.Id())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick (read as I'm happy to land this as is): Could we possibly use the new CustomizeDiff to mark subnets as ForceNew in this case? https://github.com/hashicorp/terraform/pull/14887/files#diff-456d1e45f8a8d1585e8228597b9a2176R2845 instead of instructing the user to taint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about CustomizeDiff! I've opened #2310 as a replacement

}

subnets := expandStringList(d.Get("subnets").(*schema.Set).List())

params := &elbv2.SetSubnetsInput{
Expand Down
7 changes: 5 additions & 2 deletions website/docs/r/lb.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ Terraform will autogenerate a name beginning with `tf-lb`.
* `name_prefix` - (Optional) Creates a unique name beginning with the specified prefix. Conflicts with `name`.
* `internal` - (Optional) If true, the LB will be internal.
* `load_balancer_type` - (Optional) The type of load balancer to create. Possible values are `application` or `network`. The default value is `application`.
* `security_groups` - (Optional) A list of security group IDs to assign to the LB.
* `security_groups` - (Optional) A list of security group IDs to assign to the LB. Only valid for Load Balancers of type `application`.
* `access_logs` - (Optional) An Access Logs block. Access Logs documented below.
* `subnets` - (Optional) A list of subnet IDs to attach to the LB.
* `subnets` - (Optional) A list of subnet IDs to attach to the LB. Subnets
cannot be updated for Load Balancers of type `network`; Please use
[Taint](/docs/commands/taint.html) command to force a recreation of the Load
Balancer and change subnets.
* `subnet_mapping` - (Optional) A subnet mapping block as documented below.
* `idle_timeout` - (Optional) The time in seconds that the connection is allowed to be idle. Default: 60.
* `enable_deletion_protection` - (Optional) If true, deletion of the load balancer will be disabled via
Expand Down