misc: skip message about community license with marketplace image

This commit is contained in:
Malte Poll 2024-03-01 17:06:02 +01:00
parent 1c8a7e4c22
commit f94c6ca0d4
12 changed files with 66 additions and 28 deletions

View file

@ -58,6 +58,10 @@ Required:
- `$SEMANTIC_VERSION` is the semantic version of the image, e.g. `vX.Y.Z` or `vX.Y.Z-pre...`.
- `version` (String) Semantic version of the image.
Optional:
- `marketplace_image` (Boolean) Whether a marketplace image should be used.
<a id="nestedatt--attestation"></a>
### Nested Schema for `attestation`

View file

@ -49,6 +49,10 @@ The Constellation OS image must be [replicated to the region](https://docs.edgel
<a id="nestedatt--image"></a>
### Nested Schema for `image`
Optional:
- `marketplace_image` (Boolean) Whether a marketplace image should be used.
Read-Only:
- `reference` (String) CSP-specific unique reference to the image. The format differs per CSP.

View file

@ -162,6 +162,10 @@ Required:
- `$SEMANTIC_VERSION` is the semantic version of the image, e.g. `vX.Y.Z` or `vX.Y.Z-pre...`.
- `version` (String) Semantic version of the image.
Optional:
- `marketplace_image` (Boolean) Whether a marketplace image should be used.
<a id="nestedatt--network_config"></a>
### Nested Schema for `network_config`

View file

@ -447,28 +447,31 @@ func (r *ClusterResource) ModifyPlan(ctx context.Context, req resource.ModifyPla
return
}
licenseID := plannedState.LicenseID.ValueString()
if licenseID == "" {
resp.Diagnostics.AddWarning("Constellation license ID not set.",
"Continuing with community license.")
}
if licenseID == license.CommunityLicense {
resp.Diagnostics.AddWarning("Using community license.",
"For details, see https://docs.edgeless.systems/constellation/overview/license")
}
// Validate during plan. Must be done in ModifyPlan to read provider data.
// See https://developer.hashicorp.com/terraform/plugin/framework/resources/configure#define-resource-configure-method.
_, diags := r.getMicroserviceVersion(&plannedState)
resp.Diagnostics.Append(diags...)
_, _, diags = r.getImageVersion(ctx, &plannedState)
var image imageAttribute
image, _, diags = r.getImageVersion(ctx, &plannedState)
resp.Diagnostics.Append(diags...)
if resp.Diagnostics.HasError() {
return
}
licenseID := plannedState.LicenseID.ValueString()
switch {
case image.MarketplaceImage != nil && *image.MarketplaceImage:
// Marketplace images do not require a license.
case licenseID == "":
resp.Diagnostics.AddWarning("Constellation license ID not set.",
"Continuing with community license.")
case licenseID == license.CommunityLicense:
resp.Diagnostics.AddWarning("Using community license.",
"For details, see https://docs.edgeless.systems/constellation/overview/license")
}
// Checks running on updates to the resource. (i.e. state and plan != nil)
if !req.State.Raw.IsNull() {
// Read currentState supplied by Terraform runtime into the model
@ -759,9 +762,13 @@ func (r *ClusterResource) apply(ctx context.Context, data *ClusterResourceModel,
// parse license ID
licenseID := data.LicenseID.ValueString()
if licenseID == "" {
switch {
case image.MarketplaceImage != nil && *image.MarketplaceImage:
licenseID = license.MarketplaceLicense
case licenseID == "":
licenseID = license.CommunityLicense
}
// license ID can be base64-encoded
licenseIDFromB64, err := base64.StdEncoding.DecodeString(licenseID)
if err == nil {

View file

@ -97,9 +97,10 @@ func TestViolatedImageConstraint(t *testing.T) {
}
input, diags := basetypes.NewObjectValueFrom(context.Background(), map[string]attr.Type{
"version": basetypes.StringType{},
"reference": basetypes.StringType{},
"short_path": basetypes.StringType{},
"version": basetypes.StringType{},
"reference": basetypes.StringType{},
"short_path": basetypes.StringType{},
"marketplace_image": basetypes.BoolType{},
}, img)
require.Equal(t, 0, diags.ErrorsCount())
_, _, diags2 := sut.getImageVersion(context.Background(), &ClusterResourceModel{

View file

@ -229,13 +229,19 @@ func newImageAttributeSchema(t attributeType) schema.Attribute {
Computed: !isInput,
Required: isInput,
},
"marketplace_image": schema.BoolAttribute{
Description: "Whether a marketplace image should be used.",
MarkdownDescription: "Whether a marketplace image should be used.",
Optional: true,
},
},
}
}
// imageAttribute is the image attribute's data model.
type imageAttribute struct {
Reference string `tfsdk:"reference"`
Version string `tfsdk:"version"`
ShortPath string `tfsdk:"short_path"`
Reference string `tfsdk:"reference"`
Version string `tfsdk:"version"`
ShortPath string `tfsdk:"short_path"`
MarketplaceImage *bool `tfsdk:"marketplace_image"`
}