@@ -20,6 +20,7 @@ import (
2020 "github.com/hashicorp/terraform-plugin-framework/path"
2121 "github.com/hashicorp/terraform-plugin-framework/resource"
2222 "github.com/hashicorp/terraform-plugin-framework/resource/schema"
23+ "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault"
2324 "github.com/hashicorp/terraform-plugin-framework/resource/schema/boolplanmodifier"
2425 "github.com/hashicorp/terraform-plugin-framework/resource/schema/mapplanmodifier"
2526 "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
@@ -202,13 +203,15 @@ var opsgenieConfigsTypes = map[string]attr.Type{
202203
203204// Struct corresponding to Model.AlertConfig.receivers.webHooksConfigs
204205type webHooksConfigsModel struct {
205- Url types.String `tfsdk:"url"`
206- MsTeams types.Bool `tfsdk:"ms_teams"`
206+ Url types.String `tfsdk:"url"`
207+ MsTeams types.Bool `tfsdk:"ms_teams"`
208+ GoogleChat types.Bool `tfsdk:"google_chat"`
207209}
208210
209211var webHooksConfigsTypes = map [string ]attr.Type {
210- "url" : types .StringType ,
211- "ms_teams" : types .BoolType ,
212+ "url" : types .StringType ,
213+ "ms_teams" : types .BoolType ,
214+ "google_chat" : types .BoolType ,
212215}
213216
214217var routeDescriptions = map [string ]string {
@@ -591,6 +594,7 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
591594 "auth_password" : schema.StringAttribute {
592595 Description : "SMTP authentication password." ,
593596 Optional : true ,
597+ Sensitive : true ,
594598 },
595599 "auth_username" : schema.StringAttribute {
596600 Description : "SMTP authentication username." ,
@@ -645,14 +649,26 @@ func (r *instanceResource) Schema(_ context.Context, _ resource.SchemaRequest, r
645649 listvalidator .SizeAtLeast (1 ),
646650 },
647651 NestedObject : schema.NestedAttributeObject {
652+ Validators : []validator.Object {
653+ WebhookConfigMutuallyExclusive (),
654+ },
648655 Attributes : map [string ]schema.Attribute {
649656 "url" : schema.StringAttribute {
650657 Description : "The endpoint to send HTTP POST requests to. Must be a valid URL" ,
651658 Optional : true ,
659+ Sensitive : true ,
652660 },
653661 "ms_teams" : schema.BoolAttribute {
654662 Description : "Microsoft Teams webhooks require special handling, set this to true if the webhook is for Microsoft Teams." ,
655663 Optional : true ,
664+ Computed : true ,
665+ Default : booldefault .StaticBool (false ),
666+ },
667+ "google_chat" : schema.BoolAttribute {
668+ Description : "Google Chat webhooks require special handling, set this to true if the webhook is for Google Chat." ,
669+ Optional : true ,
670+ Computed : true ,
671+ Default : booldefault .StaticBool (false ),
656672 },
657673 },
658674 },
@@ -1687,9 +1703,13 @@ func mapReceiversToAttributes(ctx context.Context, respReceivers *[]observabilit
16871703 webhooksConfigList := []attr.Value {}
16881704 if receiver .WebHookConfigs != nil {
16891705 for _ , webhookConfig := range * receiver .WebHookConfigs {
1706+ msTeamsValue := types .BoolPointerValue (webhookConfig .MsTeams )
1707+ googleChatValue := types .BoolPointerValue (webhookConfig .GoogleChat )
1708+
16901709 webHookConfigsMap := map [string ]attr.Value {
1691- "url" : types .StringPointerValue (webhookConfig .Url ),
1692- "ms_teams" : types .BoolPointerValue (webhookConfig .MsTeams ),
1710+ "url" : types .StringPointerValue (webhookConfig .Url ),
1711+ "ms_teams" : msTeamsValue ,
1712+ "google_chat" : googleChatValue ,
16931713 }
16941714 webHookConfigsModel , diags := types .ObjectValue (webHooksConfigsTypes , webHookConfigsMap )
16951715 if diags .HasError () {
@@ -2040,8 +2060,9 @@ func toReceiverPayload(ctx context.Context, model *alertConfigModel) (*[]observa
20402060 for i := range receiverWebHooksConfigs {
20412061 webHooksConfig := receiverWebHooksConfigs [i ]
20422062 payloadWebHooksConfigs = append (payloadWebHooksConfigs , observability.CreateAlertConfigReceiverPayloadWebHookConfigsInner {
2043- Url : conversion .StringValueToPointer (webHooksConfig .Url ),
2044- MsTeams : conversion .BoolValueToPointer (webHooksConfig .MsTeams ),
2063+ Url : conversion .StringValueToPointer (webHooksConfig .Url ),
2064+ MsTeams : conversion .BoolValueToPointer (webHooksConfig .MsTeams ),
2065+ GoogleChat : conversion .BoolValueToPointer (webHooksConfig .GoogleChat ),
20452066 })
20462067 }
20472068 receiverPayload .WebHookConfigs = & payloadWebHooksConfigs
@@ -2214,3 +2235,51 @@ func setMetricsRetentions(ctx context.Context, state *tfsdk.State, model *Model)
22142235func setAlertConfig (ctx context.Context , state * tfsdk.State , model * Model ) diag.Diagnostics {
22152236 return state .SetAttribute (ctx , path .Root ("alert_config" ), model .AlertConfig )
22162237}
2238+
2239+ type webhookConfigMutuallyExclusive struct {}
2240+
2241+ func (v webhookConfigMutuallyExclusive ) Description (_ context.Context ) string {
2242+ return "ms_teams and google_chat cannot both be true"
2243+ }
2244+
2245+ func (v webhookConfigMutuallyExclusive ) MarkdownDescription (ctx context.Context ) string {
2246+ return v .Description (ctx )
2247+ }
2248+
2249+ func (v webhookConfigMutuallyExclusive ) ValidateObject (_ context.Context , req validator.ObjectRequest , resp * validator.ObjectResponse ) { //nolint:gocritic // req parameter signature required by validator.Object interface
2250+ if req .ConfigValue .IsNull () || req .ConfigValue .IsUnknown () {
2251+ return
2252+ }
2253+
2254+ attributes := req .ConfigValue .Attributes ()
2255+
2256+ msTeamsAttr , msTeamsExists := attributes ["ms_teams" ]
2257+ googleChatAttr , googleChatExists := attributes ["google_chat" ]
2258+
2259+ if ! msTeamsExists || ! googleChatExists {
2260+ return
2261+ }
2262+
2263+ if msTeamsAttr .IsNull () || msTeamsAttr .IsUnknown () || googleChatAttr .IsNull () || googleChatAttr .IsUnknown () {
2264+ return
2265+ }
2266+
2267+ msTeamsValue , ok1 := msTeamsAttr .(types.Bool )
2268+ googleChatValue , ok2 := googleChatAttr .(types.Bool )
2269+
2270+ if ! ok1 || ! ok2 {
2271+ return
2272+ }
2273+
2274+ if msTeamsValue .ValueBool () && googleChatValue .ValueBool () {
2275+ resp .Diagnostics .AddAttributeError (
2276+ req .Path ,
2277+ "Invalid Webhook Configuration" ,
2278+ "Both ms_teams and google_chat cannot be set to true at the same time. Only one can be true." ,
2279+ )
2280+ }
2281+ }
2282+
2283+ func WebhookConfigMutuallyExclusive () validator.Object {
2284+ return webhookConfigMutuallyExclusive {}
2285+ }
0 commit comments