-
Notifications
You must be signed in to change notification settings - Fork 33
feat: add custom certificate #983
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?
feat: add custom certificate #983
Conversation
Co-authored-by: Marcel Jacek <[email protected]>
Co-authored-by: Marcel Jacek <[email protected]>
Co-authored-by: Marcel Jacek <[email protected]>
Co-authored-by: Marcel Jacek <[email protected]>
Co-authored-by: Marcel Jacek <[email protected]>
// Update shouldn't be called; custom domains have only computed fields and fields that require replacement when changed | ||
core.LogAndAddError(ctx, &resp.Diagnostics, "Error updating CDN custom domain", "Custom domain cannot be updated") | ||
func (r *customDomainResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { // nolint:gocritic // function signature required by Terraform | ||
var plan CustomDomainModel |
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.
Only a nitpick, but could rename plan
to model
.
var plan CustomDomainModel | |
var model CustomDomainModel |
@@ -51,7 +57,7 @@ func configResources(regions string) string { | |||
resource "stackit_dns_zone" "dns_zone" { | |||
project_id = "%s" | |||
name = "cdn_acc_test_zone" | |||
dns_name = "cdntestzone.stackit.gg" | |||
dns_name = "cdntest-zone.stackit.gg" |
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.
When I run the acc tests, I get an error that this dns_name is already used. To avoid collisions, this should be (partly) a random name. You can create a var, which stores the dns name for the acc test run and reuse it everywhere. e.g.:
var dnsName = fmt.Sprintf("tf-acc-%s.stackit.gg", acctest.RandStringFromCharSet(5, acctest.CharSetAlpha))
// Check if the credentials not update | ||
{ | ||
Config: configDatasources(instanceResource["config_regions"], string(cert), string(key)), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.stackit_cdn_custom_domain.custom_domain", "certificate.version", "1"), | ||
), | ||
}, |
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.
This step isn't needed and can be removed, because you already checked this a few lines above. Also the datasource can't perform an update, only the resource can do it. You can change the step to use configCustomDomainResources
if you want, but this step is not necessary
Optional: true, | ||
Sensitive: true, | ||
}, | ||
"private_key": schema.StringAttribute{ | ||
Description: certificateSchemaDescriptions["private_key"], | ||
Optional: true, |
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.
Both values should be changed to computed, since they don't need to be set for a read and it doesn't change everything.
Optional: true, | |
Sensitive: true, | |
}, | |
"private_key": schema.StringAttribute{ | |
Description: certificateSchemaDescriptions["private_key"], | |
Optional: true, | |
Computed: true, | |
Sensitive: true, | |
}, | |
"private_key": schema.StringAttribute{ | |
Description: certificateSchemaDescriptions["private_key"], | |
Computed: true, |
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.
Actually, I think they both attributes can be removed, because they can't be read from the API and will always stay empty. This will probably require some adjustments, because then the datasource and resource can't share a model and the map function
certificateObj, conversionDiags := types.ObjectValue(certificateTypes, certAttributes) | ||
diags.Append(conversionDiags...) | ||
if diags.HasError() { | ||
return core.DiagsToError(diags) | ||
} |
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.
nitpick
certificateObj, conversionDiags := types.ObjectValue(certificateTypes, certAttributes) | |
diags.Append(conversionDiags...) | |
if diags.HasError() { | |
return core.DiagsToError(diags) | |
} | |
certificateObj, diags := types.ObjectValue(certificateTypes, certAttributes) | |
if diags.HasError() { | |
return fmt.Errorf("failed to map certificate: %w", core.DiagsToError(diags)) | |
} |
if err != nil { | ||
return fmt.Errorf("Certificate error in normalizer: %w", err) | ||
} | ||
var diags diag.Diagnostics |
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.
Can be removed when applying the previous change
var diags diag.Diagnostics |
var certModel struct { | ||
Certificate types.String `tfsdk:"certificate"` | ||
PrivateKey types.String `tfsdk:"private_key"` | ||
Version types.Int64 `tfsdk:"version"` | ||
} |
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.
Can be stored in a separate type and reuse it here.
Add this at the top of this file, next to CustomDomainModel
type CertificateModel struct {
Certificate types.String `tfsdk:"certificate"`
PrivateKey types.String `tfsdk:"private_key"`
Version types.Int64 `tfsdk:"version"`
}
and then you can use it here
var certModel struct { | |
Certificate types.String `tfsdk:"certificate"` | |
PrivateKey types.String `tfsdk:"private_key"` | |
Version types.Int64 `tfsdk:"version"` | |
} | |
var certModel CertificateModel |
Co-authored-by: Marcel Jacek <[email protected]>
Description
https://jira.schwarz/browse/STACKITCDN-1000
Implement Certificate to CDN custom domain
relates to #1234
Checklist
make fmt
examples/
directory)make generate-docs
(will be checked by CI)make test
(will be checked by CI)make lint
(will be checked by CI)