Skip to content

Commit 1fc2a27

Browse files
committed
feat(observability/instance): add PlanModifiers Computed and Opsgenie nil handler
1 parent c552a35 commit 1fc2a27

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"
@@ -459,6 +460,9 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
459460
Validators: []validator.String{
460461
validate.UUID(),
461462
},
463+
PlanModifiers: []planmodifier.String{
464+
stringplanmodifier.UseStateForUnknown(),
465+
},
462466
},
463467
"parameters": schema.MapAttribute{
464468
Description: "Additional parameters.",
@@ -516,16 +520,25 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
516520
Description: "Specifies for how many days the raw metrics are kept. Default is set to `90`.",
517521
Optional: true,
518522
Computed: true,
523+
PlanModifiers: []planmodifier.Int64{
524+
int64planmodifier.UseStateForUnknown(),
525+
},
519526
},
520527
"metrics_retention_days_5m_downsampling": schema.Int64Attribute{
521528
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`.",
522529
Optional: true,
523530
Computed: true,
531+
PlanModifiers: []planmodifier.Int64{
532+
int64planmodifier.UseStateForUnknown(),
533+
},
524534
},
525535
"metrics_retention_days_1h_downsampling": schema.Int64Attribute{
526536
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`.",
527537
Optional: true,
528538
Computed: true,
539+
PlanModifiers: []planmodifier.Int64{
540+
int64planmodifier.UseStateForUnknown(),
541+
},
529542
},
530543
"metrics_url": schema.StringAttribute{
531544
Description: "Specifies metrics URL.",
@@ -777,10 +790,18 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
777790
Description: "The API key for OpsGenie.",
778791
Optional: true,
779792
Sensitive: true,
793+
Computed: true,
794+
PlanModifiers: []planmodifier.String{
795+
stringplanmodifier.UseStateForUnknown(),
796+
},
780797
},
781798
"opsgenie_api_url": schema.StringAttribute{
782799
Description: "The host to send OpsGenie API requests to. Must be a valid URL",
783800
Optional: true,
801+
Computed: true,
802+
PlanModifiers: []planmodifier.String{
803+
stringplanmodifier.UseStateForUnknown(),
804+
},
784805
},
785806
"resolve_timeout": schema.StringAttribute{
786807
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.",
@@ -793,24 +814,43 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
793814
"smtp_auth_identity": schema.StringAttribute{
794815
Description: "SMTP authentication information. Must be a valid email address",
795816
Optional: true,
817+
Computed: true,
818+
PlanModifiers: []planmodifier.String{
819+
stringplanmodifier.UseStateForUnknown(),
820+
},
796821
},
797822
"smtp_auth_password": schema.StringAttribute{
798823
Description: "SMTP Auth using LOGIN and PLAIN.",
799824
Optional: true,
800825
Sensitive: true,
826+
Computed: true,
827+
PlanModifiers: []planmodifier.String{
828+
stringplanmodifier.UseStateForUnknown(),
829+
},
801830
},
802831
"smtp_auth_username": schema.StringAttribute{
803832
Description: "SMTP Auth using CRAM-MD5, LOGIN and PLAIN. If empty, Alertmanager doesn't authenticate to the SMTP server.",
804833
Optional: true,
834+
Computed: true,
835+
PlanModifiers: []planmodifier.String{
836+
stringplanmodifier.UseStateForUnknown(),
837+
},
805838
},
806839
"smtp_from": schema.StringAttribute{
807840
Description: "The default SMTP From header field. Must be a valid email address",
808841
Optional: true,
809842
Computed: true,
843+
PlanModifiers: []planmodifier.String{
844+
stringplanmodifier.UseStateForUnknown(),
845+
},
810846
},
811847
"smtp_smart_host": schema.StringAttribute{
812848
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).",
813849
Optional: true,
850+
Computed: true,
851+
PlanModifiers: []planmodifier.String{
852+
stringplanmodifier.UseStateForUnknown(),
853+
},
814854
},
815855
},
816856
},
@@ -1619,10 +1659,21 @@ func mapGlobalConfigToAttributes(respGlobalConfigs *observability.Global, global
16191659
smtpAuthUsername = sdkUtils.Ptr(globalConfigsTF.SmtpAuthUsername.ValueString())
16201660
}
16211661
}
1662+
//handle nil value from api
1663+
opsgenieApiKey := respGlobalConfigs.OpsgenieApiKey
1664+
opsgenieApiUrl := respGlobalConfigs.OpsgenieApiUrl
1665+
if globalConfigsTF != nil {
1666+
if respGlobalConfigs.OpsgenieApiKey == nil {
1667+
opsgenieApiKey = sdkUtils.Ptr(globalConfigsTF.OpsgenieApiKey.ValueString())
1668+
}
1669+
if respGlobalConfigs.OpsgenieApiUrl == nil {
1670+
opsgenieApiUrl = sdkUtils.Ptr(globalConfigsTF.OpsgenieApiUrl.ValueString())
1671+
}
1672+
}
16221673

16231674
globalConfigObject, diags := types.ObjectValue(globalConfigurationTypes, map[string]attr.Value{
1624-
"opsgenie_api_key": types.StringPointerValue(respGlobalConfigs.OpsgenieApiKey),
1625-
"opsgenie_api_url": types.StringPointerValue(respGlobalConfigs.OpsgenieApiUrl),
1675+
"opsgenie_api_key": types.StringPointerValue(opsgenieApiKey),
1676+
"opsgenie_api_url": types.StringPointerValue(opsgenieApiUrl),
16261677
"resolve_timeout": types.StringPointerValue(respGlobalConfigs.ResolveTimeout),
16271678
"smtp_from": types.StringPointerValue(respGlobalConfigs.SmtpFrom),
16281679
"smtp_auth_identity": types.StringPointerValue(smtpAuthIdentity),

0 commit comments

Comments
 (0)