Skip to content

Commit 460c18c

Browse files
authored
fix(observability/instance): adjust drift (#1044)
fixes #1003
1 parent 81e8d48 commit 460c18c

File tree

1 file changed

+53
-2
lines changed
  • stackit/internal/services/observability/instance

1 file changed

+53
-2
lines changed

stackit/internal/services/observability/instance/resource.go

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"strings"
99

1010
"github.com/google/go-cmp/cmp"
11+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/int64planmodifier"
1112
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
1213

1314
observabilityUtils "github.com/stackitcloud/terraform-provider-stackit/stackit/internal/services/observability/utils"
@@ -528,16 +529,25 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
528529
Description: "Specifies for how many days the raw metrics are kept. Default is set to `90`.",
529530
Optional: true,
530531
Computed: true,
532+
PlanModifiers: []planmodifier.Int64{
533+
int64planmodifier.UseStateForUnknown(),
534+
},
531535
},
532536
"metrics_retention_days_5m_downsampling": schema.Int64Attribute{
533537
Description: "Specifies for how many days the 5m downsampled metrics are kept. must be less than the value of the general retention. Default is set to `90`.",
534538
Optional: true,
535539
Computed: true,
540+
PlanModifiers: []planmodifier.Int64{
541+
int64planmodifier.UseStateForUnknown(),
542+
},
536543
},
537544
"metrics_retention_days_1h_downsampling": schema.Int64Attribute{
538545
Description: "Specifies for how many days the 1h downsampled metrics are kept. must be less than the value of the 5m downsampling retention. Default is set to `90`.",
539546
Optional: true,
540547
Computed: true,
548+
PlanModifiers: []planmodifier.Int64{
549+
int64planmodifier.UseStateForUnknown(),
550+
},
541551
},
542552
"metrics_url": schema.StringAttribute{
543553
Description: "Specifies metrics URL.",
@@ -659,6 +669,8 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
659669
"send_resolved": schema.BoolAttribute{
660670
Description: "Whether to notify about resolved alerts.",
661671
Optional: true,
672+
Computed: true,
673+
Default: booldefault.StaticBool(true),
662674
},
663675
"smart_host": schema.StringAttribute{
664676
Description: "The SMTP host through which emails are sent.",
@@ -698,6 +710,8 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
698710
"send_resolved": schema.BoolAttribute{
699711
Description: "Whether to notify about resolved alerts.",
700712
Optional: true,
713+
Computed: true,
714+
Default: booldefault.StaticBool(true),
701715
},
702716
},
703717
},
@@ -733,6 +747,8 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
733747
"send_resolved": schema.BoolAttribute{
734748
Description: "Whether to notify about resolved alerts.",
735749
Optional: true,
750+
Computed: true,
751+
Default: booldefault.StaticBool(true),
736752
},
737753
},
738754
},
@@ -789,10 +805,18 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
789805
Description: "The API key for OpsGenie.",
790806
Optional: true,
791807
Sensitive: true,
808+
Computed: true,
809+
PlanModifiers: []planmodifier.String{
810+
stringplanmodifier.UseStateForUnknown(),
811+
},
792812
},
793813
"opsgenie_api_url": schema.StringAttribute{
794814
Description: "The host to send OpsGenie API requests to. Must be a valid URL",
795815
Optional: true,
816+
Computed: true,
817+
PlanModifiers: []planmodifier.String{
818+
stringplanmodifier.UseStateForUnknown(),
819+
},
796820
},
797821
"resolve_timeout": schema.StringAttribute{
798822
Description: "The default value used by alertmanager if the alert does not include EndsAt. After this time passes, it can declare the alert as resolved if it has not been updated. This has no impact on alerts from Prometheus, as they always include EndsAt.",
@@ -805,24 +829,43 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
805829
"smtp_auth_identity": schema.StringAttribute{
806830
Description: "SMTP authentication information. Must be a valid email address",
807831
Optional: true,
832+
Computed: true,
833+
PlanModifiers: []planmodifier.String{
834+
stringplanmodifier.UseStateForUnknown(),
835+
},
808836
},
809837
"smtp_auth_password": schema.StringAttribute{
810838
Description: "SMTP Auth using LOGIN and PLAIN.",
811839
Optional: true,
812840
Sensitive: true,
841+
Computed: true,
842+
PlanModifiers: []planmodifier.String{
843+
stringplanmodifier.UseStateForUnknown(),
844+
},
813845
},
814846
"smtp_auth_username": schema.StringAttribute{
815847
Description: "SMTP Auth using CRAM-MD5, LOGIN and PLAIN. If empty, Alertmanager doesn't authenticate to the SMTP server.",
816848
Optional: true,
849+
Computed: true,
850+
PlanModifiers: []planmodifier.String{
851+
stringplanmodifier.UseStateForUnknown(),
852+
},
817853
},
818854
"smtp_from": schema.StringAttribute{
819855
Description: "The default SMTP From header field. Must be a valid email address",
820856
Optional: true,
821857
Computed: true,
858+
PlanModifiers: []planmodifier.String{
859+
stringplanmodifier.UseStateForUnknown(),
860+
},
822861
},
823862
"smtp_smart_host": schema.StringAttribute{
824863
Description: "The default SMTP smarthost used for sending emails, including port number in format `host:port` (eg. `smtp.example.com:587`). Port number usually is 25, or 587 for SMTP over TLS (sometimes referred to as STARTTLS).",
825864
Optional: true,
865+
Computed: true,
866+
PlanModifiers: []planmodifier.String{
867+
stringplanmodifier.UseStateForUnknown(),
868+
},
826869
},
827870
},
828871
},
@@ -1798,6 +1841,8 @@ func mapGlobalConfigToAttributes(respGlobalConfigs *observability.Global, global
17981841
smtpAuthIdentity := respGlobalConfigs.SmtpAuthIdentity
17991842
smtpAuthPassword := respGlobalConfigs.SmtpAuthPassword
18001843
smtpAuthUsername := respGlobalConfigs.SmtpAuthUsername
1844+
opsgenieApiKey := respGlobalConfigs.OpsgenieApiKey
1845+
opsgenieApiUrl := respGlobalConfigs.OpsgenieApiUrl
18011846
if globalConfigsTF != nil {
18021847
if respGlobalConfigs.SmtpSmarthost == nil &&
18031848
!globalConfigsTF.SmtpSmartHost.IsNull() && !globalConfigsTF.SmtpSmartHost.IsUnknown() {
@@ -1815,11 +1860,17 @@ func mapGlobalConfigToAttributes(respGlobalConfigs *observability.Global, global
18151860
!globalConfigsTF.SmtpAuthUsername.IsNull() && !globalConfigsTF.SmtpAuthUsername.IsUnknown() {
18161861
smtpAuthUsername = sdkUtils.Ptr(globalConfigsTF.SmtpAuthUsername.ValueString())
18171862
}
1863+
if respGlobalConfigs.OpsgenieApiKey == nil {
1864+
opsgenieApiKey = sdkUtils.Ptr(globalConfigsTF.OpsgenieApiKey.ValueString())
1865+
}
1866+
if respGlobalConfigs.OpsgenieApiUrl == nil {
1867+
opsgenieApiUrl = sdkUtils.Ptr(globalConfigsTF.OpsgenieApiUrl.ValueString())
1868+
}
18181869
}
18191870

18201871
globalConfigObject, diags := types.ObjectValue(globalConfigurationTypes, map[string]attr.Value{
1821-
"opsgenie_api_key": types.StringPointerValue(respGlobalConfigs.OpsgenieApiKey),
1822-
"opsgenie_api_url": types.StringPointerValue(respGlobalConfigs.OpsgenieApiUrl),
1872+
"opsgenie_api_key": types.StringPointerValue(opsgenieApiKey),
1873+
"opsgenie_api_url": types.StringPointerValue(opsgenieApiUrl),
18231874
"resolve_timeout": types.StringPointerValue(respGlobalConfigs.ResolveTimeout),
18241875
"smtp_from": types.StringPointerValue(respGlobalConfigs.SmtpFrom),
18251876
"smtp_auth_identity": types.StringPointerValue(smtpAuthIdentity),

0 commit comments

Comments
 (0)