-
Notifications
You must be signed in to change notification settings - Fork 87
feat(cdn): Add skip_dns_check property field #1727
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
base: main
Are you sure you want to change the base?
Changes from all commits
f7dbaef
f04373b
1cf9fc4
5117efd
936201f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,16 +42,18 @@ var ( | |||||||||
| _ resource.ResourceWithImportState = &customDomainResource{} | ||||||||||
| ) | ||||||||||
| var certificateSchemaDescriptions = map[string]string{ | ||||||||||
| "main": "The TLS certificate for the custom domain. If omitted, a managed certificate will be used. If the block is specified, a custom certificate is used.", | ||||||||||
| "certificate": "The PEM-encoded TLS certificate. Required for custom certificates.", | ||||||||||
| "private_key": "The PEM-encoded private key for the certificate. Required for custom certificates. The certificate will be updated if this field is changed.", | ||||||||||
| "version": "A version identifier for the certificate. Required for custom certificates. The certificate will be updated if this field is changed.", | ||||||||||
| "main": "The TLS certificate for the custom domain. If omitted, a managed certificate will be used. If the block is specified, a custom certificate is used.", | ||||||||||
| "certificate": "The PEM-encoded TLS certificate. Required for custom certificates.", | ||||||||||
| "private_key": "The PEM-encoded private key for the certificate. Required for custom certificates. The certificate will be updated if this field is changed.", | ||||||||||
| "version": "A version identifier for the certificate. Required for custom certificates. The certificate will be updated if this field is changed.", | ||||||||||
| "skip_dns_check": "When true, skips the verification check that the custom domain points to the distribution domain via CNAME. Useful for zero-downtime migrations.", | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var certificateTypes = map[string]attr.Type{ | ||||||||||
| "version": types.Int32Type, | ||||||||||
| "certificate": types.StringType, | ||||||||||
| "private_key": types.StringType, | ||||||||||
| "version": types.Int32Type, | ||||||||||
| "certificate": types.StringType, | ||||||||||
| "private_key": types.StringType, | ||||||||||
| "skip_dns_check": types.BoolType, | ||||||||||
| } | ||||||||||
|
|
||||||||||
| var customDomainSchemaDescriptions = map[string]string{ | ||||||||||
|
|
@@ -63,9 +65,10 @@ var customDomainSchemaDescriptions = map[string]string{ | |||||||||
| } | ||||||||||
|
|
||||||||||
| type CertificateModel struct { | ||||||||||
| Certificate types.String `tfsdk:"certificate"` | ||||||||||
| PrivateKey types.String `tfsdk:"private_key"` | ||||||||||
| Version types.Int32 `tfsdk:"version"` | ||||||||||
| Certificate types.String `tfsdk:"certificate"` | ||||||||||
| PrivateKey types.String `tfsdk:"private_key"` | ||||||||||
| Version types.Int32 `tfsdk:"version"` | ||||||||||
| SkipDnsCheck types.Bool `tfsdk:"skip_dns_check"` | ||||||||||
| } | ||||||||||
|
|
||||||||||
| type CustomDomainModel struct { | ||||||||||
|
|
@@ -87,8 +90,9 @@ func NewCustomDomainResource() resource.Resource { | |||||||||
| } | ||||||||||
|
|
||||||||||
| type Certificate struct { | ||||||||||
| Type string | ||||||||||
| Version *int32 | ||||||||||
| Type string | ||||||||||
| Version *int32 | ||||||||||
| SkipDnsCheck *bool | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func (r *customDomainResource) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) { | ||||||||||
|
|
@@ -166,6 +170,11 @@ func (r *customDomainResource) Schema(_ context.Context, _ resource.SchemaReques | |||||||||
| Description: certificateSchemaDescriptions["version"], | ||||||||||
| Computed: true, | ||||||||||
| }, | ||||||||||
| "skip_dns_check": schema.BoolAttribute{ | ||||||||||
| Description: certificateSchemaDescriptions["skip_dns_check"], | ||||||||||
| Optional: true, | ||||||||||
| Computed: true, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| "status": schema.StringAttribute{ | ||||||||||
|
|
@@ -417,8 +426,9 @@ func normalizeCertificate(certInput cdnSdk.GetCustomDomainResponseCertificate) ( | |||||||||
| // Now we process the extracted certificates | ||||||||||
| if customCert != nil && customCert.Type != "" { | ||||||||||
| return Certificate{ | ||||||||||
| Type: customCert.Type, | ||||||||||
| Version: new(customCert.Version), | ||||||||||
| Type: customCert.Type, | ||||||||||
| Version: &customCert.Version, | ||||||||||
| SkipDnsCheck: &customCert.SkipDnsCheck, | ||||||||||
| }, nil | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -465,6 +475,7 @@ func toCertificatePayload(ctx context.Context, model *CustomDomainModel) (*cdnSd | |||||||||
| keyStr, | ||||||||||
| "custom", | ||||||||||
| ) | ||||||||||
| customCert.SkipDnsCheck = conversion.BoolValueToPointer(certModel.SkipDnsCheck) | ||||||||||
| certPayload := cdnSdk.PutCustomDomainCustomCertificateAsPutCustomDomainPayloadCertificate(customCert) | ||||||||||
|
|
||||||||||
| return &certPayload, nil | ||||||||||
|
|
@@ -495,11 +506,12 @@ func mapCustomDomainResourceFields(customDomainResponse *cdnSdk.GetCustomDomainR | |||||||||
| model.Certificate = types.ObjectNull(certificateTypes) | ||||||||||
| } else { | ||||||||||
| // If the certificate is custom, we need to preserve the user-configured | ||||||||||
| // certificate and private key from the plan/state, and only update the computed version. | ||||||||||
| // certificate and private key from the plan/state, and update the computed version and skip_dns_check. | ||||||||||
| certAttributes := map[string]attr.Value{ | ||||||||||
| "certificate": types.StringNull(), // Default to null | ||||||||||
| "private_key": types.StringNull(), // Default to null | ||||||||||
| "version": types.Int32Null(), | ||||||||||
| "certificate": types.StringNull(), // Default to null | ||||||||||
| "private_key": types.StringNull(), // Default to null | ||||||||||
| "version": types.Int32Null(), | ||||||||||
| "skip_dns_check": types.BoolNull(), | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // Get existing values from the model's certificate object if it exists | ||||||||||
|
|
@@ -511,12 +523,18 @@ func mapCustomDomainResourceFields(customDomainResponse *cdnSdk.GetCustomDomainR | |||||||||
| if val, ok := existingAttrs["private_key"]; ok { | ||||||||||
| certAttributes["private_key"] = val | ||||||||||
| } | ||||||||||
| if val, ok := existingAttrs["skip_dns_check"]; ok { | ||||||||||
| certAttributes["skip_dns_check"] = val | ||||||||||
| } | ||||||||||
|
Comment on lines
+526
to
+528
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't necessary here. Within the if clause |
||||||||||
| } | ||||||||||
|
|
||||||||||
| // Set the computed version from the API response | ||||||||||
| if normalizedCert.Version != nil { | ||||||||||
| certAttributes["version"] = types.Int32Value(*normalizedCert.Version) | ||||||||||
| } | ||||||||||
| if normalizedCert.SkipDnsCheck != nil { | ||||||||||
| certAttributes["skip_dns_check"] = types.BoolValue(*normalizedCert.SkipDnsCheck) | ||||||||||
| } | ||||||||||
|
Comment on lines
+535
to
+537
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can be simplified
Suggested change
|
||||||||||
|
|
||||||||||
| certificateObj, diags := types.ObjectValue(certificateTypes, certAttributes) | ||||||||||
| if diags.HasError() { | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting optional and computed to true can lead to unexpected behavior. At the moment it has the following behavior: