From bdbef3b1ba6ad4b75680771f318dd0720ca1d814 Mon Sep 17 00:00:00 2001 From: Douglas Parsons Date: Tue, 7 Jun 2022 17:10:10 +0100 Subject: [PATCH] Add `UseStateForUnknown` plan modifier to attributes that are stable when being updated When updating a resource with `Computed` attributes, these attributes will be set to `unknown` at plan time (as they could change). This means any dependent resources will be flagged as requiring deletion and recreation. However, for the vast majority of attributes within our Terraform provider, such as `ID` fields, these attributes _never_ change when a resource is updated. Instead, they only change when the resource is destroyed and created again. This is the exact behaviour of the `UseStateForUnknown` plan modifier. --- vercel/resource_deployment.go | 17 ++++++++++------- vercel/resource_dns_record_test.go | 10 +++++----- vercel/resource_project.go | 9 +++++---- vercel/resource_project_domain.go | 5 +++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/vercel/resource_deployment.go b/vercel/resource_deployment.go index 39dcc62c..5635664a 100644 --- a/vercel/resource_deployment.go +++ b/vercel/resource_deployment.go @@ -35,8 +35,9 @@ terraform to your Deployment. `, Attributes: map[string]tfsdk.Attribute{ "domains": { - Description: "A list of all the domains (default domains, staging domains and production domains) that were assigned upon deployment creation.", - Computed: true, + Description: "A list of all the domains (default domains, staging domains and production domains) that were assigned upon deployment creation.", + Computed: true, + PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.UseStateForUnknown()}, Type: types.ListType{ ElemType: types.StringType, }, @@ -62,8 +63,9 @@ terraform to your Deployment. Type: types.StringType, }, "id": { - Computed: true, - Type: types.StringType, + Computed: true, + PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.UseStateForUnknown()}, + Type: types.StringType, }, "path_prefix": { Description: "If specified then the `path_prefix` will be stripped from the start of file paths as they are uploaded to Vercel. If this is omitted, then any leading `../`s will be stripped.", @@ -72,9 +74,10 @@ terraform to your Deployment. PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.RequiresReplace()}, }, "url": { - Description: "A unique URL that is automatically generated for a deployment.", - Computed: true, - Type: types.StringType, + Description: "A unique URL that is automatically generated for a deployment.", + Computed: true, + PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.UseStateForUnknown()}, + Type: types.StringType, }, "production": { Description: "true if the deployment is a production deployment, meaning production aliases will be assigned.", diff --git a/vercel/resource_dns_record_test.go b/vercel/resource_dns_record_test.go index b12ed60c..61185e9a 100644 --- a/vercel/resource_dns_record_test.go +++ b/vercel/resource_dns_record_test.go @@ -233,35 +233,35 @@ resource "vercel_dns_record" "a" { } resource "vercel_dns_record" "aaaa" { domain = "%[1]s" - name = "test-acc-%s-aaaa-record" + name = "test-acc-%[2]s-aaaa-record" type = "AAAA" ttl = 120 value = "::1" } resource "vercel_dns_record" "alias" { domain = "%[1]s" - name = "test-acc-%s-alias" + name = "test-acc-%[2]s-alias" type = "ALIAS" ttl = 120 value = "example.com." } resource "vercel_dns_record" "caa" { domain = "%[1]s" - name = "test-acc-%s-caa" + name = "test-acc-%[2]s-caa" type = "CAA" ttl = 120 value = "0 issue \"letsencrypt.org\"" } resource "vercel_dns_record" "cname" { domain = "%[1]s" - name = "test-acc-%s-cname" + name = "test-acc-%[2]s-cname" type = "CNAME" ttl = 120 value = "example.com." } resource "vercel_dns_record" "mx" { domain = "%[1]s" - name = "test-acc-%s-mx" + name = "test-acc-%[2]s-mx" type = "MX" ttl = 120 mx_priority = 123 diff --git a/vercel/resource_project.go b/vercel/resource_project.go index 6c6153a3..11e2ae44 100644 --- a/vercel/resource_project.go +++ b/vercel/resource_project.go @@ -117,9 +117,10 @@ For more detailed information, please see the [Vercel documentation](https://ver Sensitive: true, }, "id": { - Description: "The ID of the environment variable", - Type: types.StringType, - Computed: true, + Description: "The ID of the environment variable", + Type: types.StringType, + PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.UseStateForUnknown()}, + Computed: true, }, }, tfsdk.SetNestedAttributesOptions{}), }, @@ -156,7 +157,7 @@ For more detailed information, please see the [Vercel documentation](https://ver "id": { Computed: true, Type: types.StringType, - PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.RequiresReplace()}, + PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.UseStateForUnknown()}, }, "install_command": { Optional: true, diff --git a/vercel/resource_project_domain.go b/vercel/resource_project_domain.go index e4d20833..5dba9b25 100644 --- a/vercel/resource_project_domain.go +++ b/vercel/resource_project_domain.go @@ -38,8 +38,9 @@ By default, Project Domains will be automatically applied to any ` + "`productio Description: "The ID of the team the project exists under.", }, "id": { - Computed: true, - Type: types.StringType, + Computed: true, + PlanModifiers: tfsdk.AttributePlanModifiers{tfsdk.UseStateForUnknown()}, + Type: types.StringType, }, "domain": { Description: "The domain name to associate with the project.",