feat(cdn) - Feature parity - #1601
Conversation
|
Hi @matheuspolitano, |
|
This PR was marked as stale after 7 days of inactivity and will be closed after another 7 days of further inactivity. If this PR should be kept open, just add a comment, remove the stale label or push new commits to it. |
…itano/terraform-provider-stackit into mp/cdn/feature-parity
The blocked_ips attribute is Optional+Computed without a default, so it can be unknown at plan time. Decoding it into a *[]string field failed with 'Received unknown value, however the target type cannot handle unknown values'. Change the BlockedIps field in distributionConfig from *[]string to types.List and guard reads with utils.IsUndefined before converting elements via ElementsAs.
| configPatch.DefaultCacheDuration = *cdnSdk.NewNullableString(conversion.StringValueToPointer(configModel.DefaultCacheDuration)) | ||
| } | ||
| if !utils.IsUndefined(configModel.MonthlyLimitBytes) { | ||
| configPatch.MonthlyLimitBytes = *cdnSdk.NewNullableInt64(conversion.Int64ValueToPointer(configModel.MonthlyLimitBytes)) |
There was a problem hiding this comment.
example config:
resource "stackit_cdn_distribution" "example-distribution" {
project_id = var.project_id
config = {
backend = {
type = "http"
origin_url = "https://example.com"
}
regions = ["EU"]
default_cache_duration = "PT2H"
monthly_limit_bytes = 104857600
}
}run terraform apply then remove default_cache_duration and monthly_limit_bytes.
Then run apply again.
snippet from state:
default_cache_duration = "PT2H"
forward_host_header = false
monthly_limit_bytes = 104857600
I'd expect that the state contains the same values as when a distribution is created without these two values in the config:
default_cache_duration = "P1D"
and monthly_limit_bytes missing completely from state.
| var defaultCacheDuration types.String | ||
| if distribution.Config.DefaultCacheDuration.IsSet() { | ||
| defaultCacheDuration = types.StringPointerValue(distribution.Config.DefaultCacheDuration.Get()) | ||
| } else { | ||
| defaultCacheDuration = types.StringNull() | ||
| } |
There was a problem hiding this comment.
Nitpick: could be simplified
| var defaultCacheDuration types.String | |
| if distribution.Config.DefaultCacheDuration.IsSet() { | |
| defaultCacheDuration = types.StringPointerValue(distribution.Config.DefaultCacheDuration.Get()) | |
| } else { | |
| defaultCacheDuration = types.StringNull() | |
| } | |
| defaultCacheDuration := types.StringPointerValue(distribution.Config.DefultCacheDuration.Get()) |
These NullableStringTypes are a bit unintuitive, Get() is always save to call, it will just return nil. When passed to types.StringPointerValue() this would result in a StringNull:
func TestNullableStringToTerraformString(t *testing.T) {
uninitialized := cdnSdk.NullableString{}
setNil := cdnSdk.NullableString{}
setNil.Set(nil)
uninitializedValue := types.StringPointerValue(uninitialized.Get())
setNilValue := types.StringPointerValue(setNil.Get())
if diff := cmp.Diff(types.StringNull(), uninitializedValue); diff != "" {
t.Fatalf("uninitialized NullableString converted unexpectedly (-want +got):\n%s", diff)
}
if diff := cmp.Diff(uninitializedValue, setNilValue); diff != "" {
t.Fatalf("uninitialized and nil NullableString conversions differ (-uninitialized +nil):\n%s", diff)
}
}| var monthlyLimitBytes types.Int64 | ||
| if distribution.Config.MonthlyLimitBytes.IsSet() { | ||
| monthlyLimitBytes = types.Int64PointerValue(distribution.Config.MonthlyLimitBytes.Get()) | ||
| } else { | ||
| monthlyLimitBytes = types.Int64Null() | ||
| } |
| var defaultCacheDuration types.String | ||
| if distribution.Config.DefaultCacheDuration.IsSet() { | ||
| defaultCacheDuration = types.StringPointerValue(distribution.Config.DefaultCacheDuration.Get()) | ||
| } else { | ||
| defaultCacheDuration = types.StringNull() | ||
| } | ||
|
|
||
| var monthlyLimitBytes types.Int64 | ||
| if distribution.Config.MonthlyLimitBytes.IsSet() { | ||
| monthlyLimitBytes = types.Int64PointerValue(distribution.Config.MonthlyLimitBytes.Get()) | ||
| } else { | ||
| monthlyLimitBytes = types.Int64Null() | ||
| } |
There was a problem hiding this comment.
see resource for nitpick suggestion, but these aren't a merge blocker from my side
Description
(https://jira.schwarz/browse/STACKITCDN-1451)
Checklist
make fmtexamples/directory)make generate-docs(will be checked by CI)make test(will be checked by CI)make lint(will be checked by CI)