Skip to content

Commit

Permalink
droplet: Prevent inconsistent plan when enabling IPv6. (#982)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsomething committed May 2, 2023
1 parent 81893b0 commit 7b1fb28
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions digitalocean/droplet/resource_droplet.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/tag"
"github.com/digitalocean/terraform-provider-digitalocean/digitalocean/util"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
Expand Down Expand Up @@ -148,6 +149,7 @@ func ResourceDigitalOceanDroplet() *schema.Resource {

"ipv6_address": {
Type: schema.TypeString,
Optional: true,
Computed: true,
},

Expand Down Expand Up @@ -220,6 +222,22 @@ func ResourceDigitalOceanDroplet() *schema.Resource {
ValidateFunc: validation.NoZeroValues,
},
},

CustomizeDiff: customdiff.All(
// If the `ipv6` attribute is changed to `true`, we need to mark the
// `ipv6_address` attribute as changing in the plan. If not, the plan
// will become inconsistent once the address is known when referenced
// in another resource such as a domain record, e.g.:
// https://github.com/digitalocean/terraform-provider-digitalocean/issues/981
customdiff.IfValueChange("ipv6",
func(ctx context.Context, old, new, meta interface{}) bool {
return !old.(bool) && new.(bool)
},
customdiff.ComputedIf("ipv6_address", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool {
return d.Get("ipv6").(bool)
}),
),
),
}
}

Expand Down

0 comments on commit 7b1fb28

Please sign in to comment.