Skip to content

Commit

Permalink
update testcase to avoid force replace
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Nov 7, 2024
1 parent 173d716 commit 3af1a9d
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 82 deletions.
143 changes: 68 additions & 75 deletions internal/services/cdn/cdn_frontdoor_custom_domain_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,92 +41,85 @@ func resourceCdnFrontDoorCustomDomain() *pluginsdk.Resource {
return err
}),

Schema: resourceCdnFrontDoorCustomDomainSchema(),
}

return resource
}

func resourceCdnFrontDoorCustomDomainSchema() map[string]*pluginsdk.Schema {
result := map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.FrontDoorCustomDomainName,
},

// NOTE: I need this fake field because I need the profile name during the create operation
"cdn_frontdoor_profile_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.FrontDoorProfileID,
},

"dns_zone_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: dnsValidate.ValidateDnsZoneID,
},
Schema: map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.FrontDoorCustomDomainName,
},

"host_name": {
Type: pluginsdk.TypeString,
ForceNew: true,
Required: true,
},
// NOTE: I need this fake field because I need the profile name during the create operation
"cdn_frontdoor_profile_id": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validate.FrontDoorProfileID,
},

"tls": {
Type: pluginsdk.TypeList,
Required: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{

"certificate_type": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(cdn.AfdCertificateTypeManagedCertificate),
ValidateFunc: validation.StringInSlice([]string{
string(cdn.AfdCertificateTypeCustomerCertificate),
string(cdn.AfdCertificateTypeManagedCertificate),
}, false),
},
"dns_zone_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: dnsValidate.ValidateDnsZoneID,
},

"minimum_tls_version": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(cdn.AfdMinimumTLSVersionTLS12),
ValidateFunc: validation.StringInSlice([]string{
string(cdn.AfdMinimumTLSVersionTLS12),
}, false),
},
"host_name": {
Type: pluginsdk.TypeString,
ForceNew: true,
Required: true,
},

// NOTE: If the secret is managed by FrontDoor this will cause a perpetual diff,
// so this has to be an optional computed field.
"cdn_frontdoor_secret_id": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.FrontDoorSecretID,
"tls": {
Type: pluginsdk.TypeList,
Required: true,
MaxItems: 1,
Elem: &pluginsdk.Resource{
Schema: map[string]*pluginsdk.Schema{
"certificate_type": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(cdn.AfdCertificateTypeManagedCertificate),
ValidateFunc: validation.StringInSlice([]string{
string(cdn.AfdCertificateTypeCustomerCertificate),
string(cdn.AfdCertificateTypeManagedCertificate),
}, false),
},

"minimum_tls_version": {
Type: pluginsdk.TypeString,
Optional: true,
Default: string(cdn.AfdMinimumTLSVersionTLS12),
ValidateFunc: validation.StringInSlice([]string{
string(cdn.AfdMinimumTLSVersionTLS12),
}, false),
},

// NOTE: If the secret is managed by FrontDoor this will cause a perpetual diff,
// so this has to be an optional computed field.
"cdn_frontdoor_secret_id": {
Type: pluginsdk.TypeString,
Optional: true,
Computed: true,
ValidateFunc: validate.FrontDoorSecretID,
},
},
},
},
},

"expiration_date": {
Type: pluginsdk.TypeString,
Computed: true,
},
"expiration_date": {
Type: pluginsdk.TypeString,
Computed: true,
},

"validation_token": {
Type: pluginsdk.TypeString,
Computed: true,
"validation_token": {
Type: pluginsdk.TypeString,
Computed: true,
},
},
}

if !features.FivePointOhBeta() {
tlsElem := result["tls"].Elem.(*pluginsdk.Resource)
tlsElem := resource.Schema["tls"].Elem.(*pluginsdk.Resource)
tlsElem.Schema["minimum_tls_version"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Expand All @@ -136,10 +129,10 @@ func resourceCdnFrontDoorCustomDomainSchema() map[string]*pluginsdk.Schema {
string(cdn.AfdMinimumTLSVersionTLS10),
}, false),
}
result["tls"].Elem = tlsElem
resource.Schema["tls"].Elem = tlsElem
}

return result
return resource
}

func resourceCdnFrontDoorCustomDomainCreate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/features"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/cdn/parse"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/utils"
Expand Down Expand Up @@ -49,6 +50,9 @@ func TestAccCdnFrontDoorCustomDomain_requiresImport(t *testing.T) {
}

func TestAccCdnFrontDoorCustomDomain_update(t *testing.T) {
if features.FivePointOhBeta() {
t.Skipf("There is no avaliable `tls_version` to test update, to test CMK, it requires an official certificate from approved provider list instead of testing cert.")

Check failure on line 54 in internal/services/cdn/cdn_frontdoor_custom_domain_resource_test.go

View workflow job for this annotation

GitHub Actions / golint

`avaliable` is a misspelling of `available` (misspell)
}
data := acceptance.BuildTestData(t, "azurerm_cdn_frontdoor_custom_domain", "test")
r := CdnFrontDoorCustomDomainResource{}

Expand Down Expand Up @@ -119,7 +123,7 @@ resource "azurerm_cdn_frontdoor_custom_domain" "test" {
minimum_tls_version = "TLS12"
}
}
`, template, data.RandomInteger, data.RandomStringOfLength(8))
`, template, data.RandomInteger, data.RandomString)
}

func (r CdnFrontDoorCustomDomainResource) requiresImport(data acceptance.TestData) string {
Expand Down Expand Up @@ -150,18 +154,15 @@ resource "azurerm_cdn_frontdoor_custom_domain" "test" {
name = "acctestcustomdomain-%[2]d"
cdn_frontdoor_profile_id = azurerm_cdn_frontdoor_profile.test.id
dns_zone_id = azurerm_dns_zone.test.id
host_name = join(".", ["sub-%[3]s", azurerm_dns_zone.test.name])
host_name = join(".", ["%s", azurerm_dns_zone.test.name])
tls {
certificate_type = "ManagedCertificate"
minimum_tls_version = "TLS12"
}
tags {
test = "acctest"
}
}
`, template, data.RandomInteger, data.RandomStringOfLength(8))
`, template, data.RandomInteger, data.RandomString)
}

func (r CdnFrontDoorCustomDomainResource) complete(data acceptance.TestData) string {
Expand All @@ -180,7 +181,7 @@ resource "azurerm_cdn_frontdoor_custom_domain" "test" {
minimum_tls_version = "TLS12"
}
}
`, template, data.RandomInteger, data.RandomStringOfLength(8))
`, template, data.RandomInteger, data.RandomString)
}

// TODO: Add test case that uses pre_validated_custom_domain_resource_id
Expand Down

0 comments on commit 3af1a9d

Please sign in to comment.