Skip to content

Commit

Permalink
update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Nov 6, 2024
1 parent d0c55c4 commit 173d716
Showing 1 changed file with 87 additions and 76 deletions.
163 changes: 87 additions & 76 deletions internal/services/cdn/cdn_frontdoor_custom_domain_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,94 +41,105 @@ func resourceCdnFrontDoorCustomDomain() *pluginsdk.Resource {
return err
}),

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

// 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,
},
return resource
}

"dns_zone_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: dnsValidate.ValidateDnsZoneID,
},
func resourceCdnFrontDoorCustomDomainSchema() map[string]*pluginsdk.Schema {
result := 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,
},

"dns_zone_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: dnsValidate.ValidateDnsZoneID,
},

"host_name": {
Type: pluginsdk.TypeString,
ForceNew: true,
Required: true,
},

"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(func() []string {
if !features.FivePointOhBeta() {
return []string{
string(cdn.AfdMinimumTLSVersionTLS10),
string(cdn.AfdMinimumTLSVersionTLS12),
}
}
return []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,
},
"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,
},
}

return resource
if !features.FivePointOhBeta() {
tlsElem := result["tls"].Elem.(*pluginsdk.Resource)
tlsElem.Schema["minimum_tls_version"] = &pluginsdk.Schema{
Type: pluginsdk.TypeString,
Optional: true,
Default: string(cdn.AfdMinimumTLSVersionTLS12),
ValidateFunc: validation.StringInSlice([]string{
string(cdn.AfdMinimumTLSVersionTLS12),
string(cdn.AfdMinimumTLSVersionTLS10),
}, false),
}
result["tls"].Elem = tlsElem
}

return result
}

func resourceCdnFrontDoorCustomDomainCreate(d *pluginsdk.ResourceData, meta interface{}) error {
Expand Down

0 comments on commit 173d716

Please sign in to comment.