From e262fbddcaf22115c0eed0232d5c467437ee2243 Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Tue, 18 Feb 2025 15:40:36 -0500 Subject: [PATCH 1/8] Added MS Teams Workflows Webhooks Resource --- datadog/fwprovider/framework_provider.go | 1 + ...icrosoft_teams_workflows_webhook_handle.go | 201 ++++++++++++++++++ ...eams_microsoft_workflows_webhook_handle.md | 25 +++ 3 files changed, 227 insertions(+) create mode 100644 datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go create mode 100644 docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md diff --git a/datadog/fwprovider/framework_provider.go b/datadog/fwprovider/framework_provider.go index 9aa4c7e41..cd011e5ca 100644 --- a/datadog/fwprovider/framework_provider.go +++ b/datadog/fwprovider/framework_provider.go @@ -71,6 +71,7 @@ var Resources = []func() resource.Resource{ NewWebhookCustomVariableResource, NewLogsCustomDestinationResource, NewTenantBasedHandleResource, + NewWorkflowsWebhookHandleResource, } var Datasources = []func() datasource.DataSource{ diff --git a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go new file mode 100644 index 000000000..136e716ee --- /dev/null +++ b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go @@ -0,0 +1,201 @@ +package fwprovider + +import ( + "context" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" + frameworkPath "github.com/hashicorp/terraform-plugin-framework/path" + "github.com/hashicorp/terraform-plugin-framework/resource" + "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" +) + +var ( + _ resource.ResourceWithConfigure = &workflowsWebhookHandleResource{} + _ resource.ResourceWithImportState = &workflowsWebhookHandleResource{} +) + +type workflowsWebhookHandleResource struct { + Api *datadogV2.MicrosoftTeamsIntegrationApi + Auth context.Context +} + +type workflowsWebhookHandleModel struct { + ID types.String `tfsdk:"id"` + URL types.String `tfsdk:"url"` + Name types.String `tfsdk:"name"` +} + +func NewWorkflowsWebhookHandleResource() resource.Resource { + return &workflowsWebhookHandleResource{} +} + +func (r *workflowsWebhookHandleResource) Configure(_ context.Context, request resource.ConfigureRequest, response *resource.ConfigureResponse) { + providerData := request.ProviderData.(*FrameworkProvider) + r.Api = providerData.DatadogApiInstances.GetMicrosoftTeamsIntegrationApiV2() + r.Auth = providerData.Auth +} + +func (r *workflowsWebhookHandleResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { + response.TypeName = "integration_ms_teams_microsoft_workflows_webhook_handle" +} + +func (r *workflowsWebhookHandleResource) Schema(_ context.Context, _ resource.SchemaRequest, response *resource.SchemaResponse) { + response.Schema = schema.Schema{ + Description: "Resource for interacting with Datadog Microsoft Teams Integration Microsoft Workflows webhook handles.", + Attributes: map[string]schema.Attribute{ + "name": schema.StringAttribute{ + Required: true, + Description: "Your Microsoft Workflows webhook handle name.", + }, + "url": schema.StringAttribute{ + Description: "Your Microsoft Workflows webhook URL.", + Required: true, + }, + "id": utils.ResourceIDAttribute(), + }, + } +} + +func (r *workflowsWebhookHandleResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) { + resource.ImportStatePassthroughID(ctx, frameworkPath.Root("id"), request, response) +} + +func (r *workflowsWebhookHandleResource) Read(ctx context.Context, request resource.ReadRequest, response *resource.ReadResponse) { + var state workflowsWebhookHandleModel + response.Diagnostics.Append(request.State.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + id := state.ID.ValueString() + // Check if handle exists + resp, httpResp, err := r.Api.GetWorkflowsWebhookHandle(r.Auth, id) + if err != nil { + if httpResp != nil && httpResp.StatusCode == 404 { + response.State.RemoveResource(ctx) + return + } + response.Diagnostics.Append(utils.FrameworkErrorDiag(err, "error retrieving Microsoft Workflows webhook handle")) + return + } + if err := utils.CheckForUnparsed(resp); err != nil { + response.Diagnostics.AddError("response contains unparsedObject", err.Error()) + return + } + + r.updateState(ctx, &state, &resp) + + // Save data into Terraform state + response.Diagnostics.Append(response.State.Set(ctx, &state)...) +} + +func (r *workflowsWebhookHandleResource) Create(ctx context.Context, request resource.CreateRequest, response *resource.CreateResponse) { + var state workflowsWebhookHandleModel + response.Diagnostics.Append(request.Plan.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + body := r.buildWorkflowsWebhookHandleRequestBody(ctx, &state) + + resp, _, err := r.Api.CreateWorkflowsWebhookHandle(r.Auth, *body) + if err != nil { + response.Diagnostics.Append(utils.FrameworkErrorDiag(err, "error creating Microsoft Workflows webhook handle")) + return + } + if err := utils.CheckForUnparsed(resp); err != nil { + response.Diagnostics.AddError("response contains unparsedObject", err.Error()) + return + } + r.updateState(ctx, &state, &resp) + + // Save data into Terraform state + response.Diagnostics.Append(response.State.Set(ctx, &state)...) +} + +func (r *workflowsWebhookHandleResource) Update(ctx context.Context, request resource.UpdateRequest, response *resource.UpdateResponse) { + var state workflowsWebhookHandleModel + response.Diagnostics.Append(request.Plan.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + id := state.ID.ValueString() + + body := r.buildWorkflowsWebhookHandleUpdateRequestBody(ctx, &state) + + resp, _, err := r.Api.UpdateWorkflowsWebhookHandle(r.Auth, id, *body) + if err != nil { + response.Diagnostics.Append(utils.FrameworkErrorDiag(err, "error updating Microsoft Workflows webhook handle")) + return + } + if err := utils.CheckForUnparsed(resp); err != nil { + response.Diagnostics.AddError("response contains unparsedObject", err.Error()) + return + } + r.updateState(ctx, &state, &resp) + + // Save data into Terraform state + response.Diagnostics.Append(response.State.Set(ctx, &state)...) +} + +func (r *workflowsWebhookHandleResource) Delete(ctx context.Context, request resource.DeleteRequest, response *resource.DeleteResponse) { + var state workflowsWebhookHandleModel + response.Diagnostics.Append(request.State.Get(ctx, &state)...) + if response.Diagnostics.HasError() { + return + } + + id := state.ID.ValueString() + + httpResp, err := r.Api.DeleteWorkflowsWebhookHandle(r.Auth, id) + if err != nil { + if httpResp != nil && httpResp.StatusCode == 404 { + return + } + response.Diagnostics.Append(utils.FrameworkErrorDiag(err, "error deleting Microsoft Workflows webhook handle")) + return + } +} + +func (r *workflowsWebhookHandleResource) updateState(ctx context.Context, state *workflowsWebhookHandleModel, resp *datadogV2.MicrosoftTeamsWorkflowsWebhookHandleResponse) { + state.ID = types.StringValue(resp.Data.GetId()) + + attributes := resp.Data.Attributes + + if name, ok := attributes.GetNameOk(); ok && name != nil { + state.Name = types.StringValue(*name) + } + + state.URL = types.StringValue("") +} + +func (r *workflowsWebhookHandleResource) buildWorkflowsWebhookHandleRequestBody(ctx context.Context, state *workflowsWebhookHandleModel) *datadogV2.MicrosoftTeamsCreateWorkflowsWebhookHandleRequest { + attributes := datadogV2.NewMicrosoftTeamsWorkflowsWebhookHandleRequestAttributesWithDefaults() + + attributes.SetName(state.Name.ValueString()) + attributes.SetUrl(state.URL.ValueString()) + + req := datadogV2.NewMicrosoftTeamsCreateWorkflowsWebhookHandleRequestWithDefaults() + req.Data = *datadogV2.NewMicrosoftTeamsWorkflowsWebhookHandleRequestDataWithDefaults() + req.Data.SetAttributes(*attributes) + + return req +} + +func (r *workflowsWebhookHandleResource) buildWorkflowsWebhookHandleUpdateRequestBody(ctx context.Context, state *workflowsWebhookHandleModel) *datadogV2.MicrosoftTeamsUpdateWorkflowsWebhookHandleRequest { + attributes := datadogV2.NewMicrosoftTeamsWorkflowsWebhookHandleAttributesWithDefaults() + + attributes.SetName(state.Name.ValueString()) + if state.URL.ValueString() != "" { + attributes.SetUrl(state.URL.ValueString()) + } + + req := datadogV2.NewMicrosoftTeamsUpdateWorkflowsWebhookHandleRequestWithDefaults() + req.Data = *datadogV2.NewMicrosoftTeamsUpdateWorkflowsWebhookHandleRequestDataWithDefaults() + req.Data.SetAttributes(*attributes) + + return req +} diff --git a/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md b/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md new file mode 100644 index 000000000..31f1d81e7 --- /dev/null +++ b/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md @@ -0,0 +1,25 @@ +--- +# generated by https://github.com/hashicorp/terraform-plugin-docs +page_title: "datadog_integration_ms_teams_microsoft_workflows_webhook_handle Resource - terraform-provider-datadog" +subcategory: "" +description: |- + Resource for interacting with Datadog Microsoft Teams Integration Microsoft Workflows webhook handles. +--- + +# datadog_integration_ms_teams_microsoft_workflows_webhook_handle (Resource) + +Resource for interacting with Datadog Microsoft Teams Integration Microsoft Workflows webhook handles. + + + + +## Schema + +### Required + +- `name` (String) Your Microsoft Workflows webhook handle name. +- `url` (String) Your Microsoft Workflows webhook URL. + +### Read-Only + +- `id` (String) The ID of this resource. From 4895ed5461efe3fd793cac056fed5e555b13809e Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Tue, 18 Feb 2025 15:45:52 -0500 Subject: [PATCH 2/8] fmt --- ...tadog_integration_microsoft_teams_workflows_webhook_handle.go | 1 + 1 file changed, 1 insertion(+) diff --git a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go index 136e716ee..ea24b251d 100644 --- a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go +++ b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go @@ -2,6 +2,7 @@ package fwprovider import ( "context" + "github.com/DataDog/datadog-api-client-go/v2/api/datadogV2" frameworkPath "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" From 50e394645822738ff1f89302fa77c4fe3133f422 Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Wed, 19 Feb 2025 11:29:15 -0500 Subject: [PATCH 3/8] handle secret url --- ...tion_microsoft_teams_workflows_webhook_handle.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go index ea24b251d..61d7f03f7 100644 --- a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go +++ b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go @@ -12,6 +12,8 @@ import ( "github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" ) +const maskedSecret = "*****" + var ( _ resource.ResourceWithConfigure = &workflowsWebhookHandleResource{} _ resource.ResourceWithImportState = &workflowsWebhookHandleResource{} @@ -53,6 +55,7 @@ func (r *workflowsWebhookHandleResource) Schema(_ context.Context, _ resource.Sc "url": schema.StringAttribute{ Description: "Your Microsoft Workflows webhook URL.", Required: true, + Sensitive: true, }, "id": utils.ResourceIDAttribute(), }, @@ -170,7 +173,11 @@ func (r *workflowsWebhookHandleResource) updateState(ctx context.Context, state state.Name = types.StringValue(*name) } - state.URL = types.StringValue("") + // Only update URL if not set - the API endpoints never return + // the url, so this is how we recognize new values. + if state.URL.IsNull() { + state.URL = types.StringValue(maskedSecret) + } } func (r *workflowsWebhookHandleResource) buildWorkflowsWebhookHandleRequestBody(ctx context.Context, state *workflowsWebhookHandleModel) *datadogV2.MicrosoftTeamsCreateWorkflowsWebhookHandleRequest { @@ -190,9 +197,7 @@ func (r *workflowsWebhookHandleResource) buildWorkflowsWebhookHandleUpdateReques attributes := datadogV2.NewMicrosoftTeamsWorkflowsWebhookHandleAttributesWithDefaults() attributes.SetName(state.Name.ValueString()) - if state.URL.ValueString() != "" { - attributes.SetUrl(state.URL.ValueString()) - } + attributes.SetUrl(state.URL.ValueString()) req := datadogV2.NewMicrosoftTeamsUpdateWorkflowsWebhookHandleRequestWithDefaults() req.Data = *datadogV2.NewMicrosoftTeamsUpdateWorkflowsWebhookHandleRequestDataWithDefaults() From b8a666b00d58a80ce6df375ccd5b054192ed799a Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Wed, 19 Feb 2025 11:31:11 -0500 Subject: [PATCH 4/8] mk dcs --- .../integration_ms_teams_microsoft_workflows_webhook_handle.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md b/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md index 31f1d81e7..44f0662d2 100644 --- a/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md +++ b/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md @@ -18,7 +18,7 @@ Resource for interacting with Datadog Microsoft Teams Integration Microsoft Work ### Required - `name` (String) Your Microsoft Workflows webhook handle name. -- `url` (String) Your Microsoft Workflows webhook URL. +- `url` (String, Sensitive) Your Microsoft Workflows webhook URL. ### Read-Only From 597f923f47838d513ae58deb6e7d6db89ddeed61 Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Wed, 19 Feb 2025 13:34:08 -0500 Subject: [PATCH 5/8] tests added --- ...MSTeamsWorkflowsWebhookHandlesBasic.freeze | 1 + ...ccMSTeamsWorkflowsWebhookHandlesBasic.yaml | 205 ++++++++++++++++++ datadog/tests/provider_test.go | 1 + ...egration_ms_teams_workflows_handle_test.go | 128 +++++++++++ .../import.sh | 2 + .../resource.tf | 6 + 6 files changed, 343 insertions(+) create mode 100644 datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.freeze create mode 100644 datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.yaml create mode 100644 datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go create mode 100644 examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh create mode 100644 examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf diff --git a/datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.freeze b/datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.freeze new file mode 100644 index 000000000..8c874e18d --- /dev/null +++ b/datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.freeze @@ -0,0 +1 @@ +2025-02-19T13:30:48.039939-05:00 \ No newline at end of file diff --git a/datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.yaml b/datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.yaml new file mode 100644 index 000000000..4a384185c --- /dev/null +++ b/datadog/tests/cassettes/TestAccMSTeamsWorkflowsWebhookHandlesBasic.yaml @@ -0,0 +1,205 @@ +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 161 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"name":"tf-testaccmsteamsworkflowswebhookhandlesbasic-local-1739989848","url":"https://fake.url.com"},"type":"workflows-webhook-handle"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/integration/ms-teams/configuration/workflows-webhook-handles + method: POST + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 175 + uncompressed: false + body: '{"data":{"id":"bbeabb84-0fec-4af1-95cc-72f78795d8c9","type":"workflows-webhook-handle","attributes":{"name":"tf-testaccmsteamsworkflowswebhookhandlesbasic-local-1739989848"}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 201 Created + code: 201 + duration: 111.034333ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/integration/ms-teams/configuration/workflows-webhook-handles/bbeabb84-0fec-4af1-95cc-72f78795d8c9 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 175 + uncompressed: false + body: '{"data":{"id":"bbeabb84-0fec-4af1-95cc-72f78795d8c9","type":"workflows-webhook-handle","attributes":{"name":"tf-testaccmsteamsworkflowswebhookhandlesbasic-local-1739989848"}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 46.907208ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/integration/ms-teams/configuration/workflows-webhook-handles/bbeabb84-0fec-4af1-95cc-72f78795d8c9 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 175 + uncompressed: false + body: '{"data":{"id":"bbeabb84-0fec-4af1-95cc-72f78795d8c9","type":"workflows-webhook-handle","attributes":{"name":"tf-testaccmsteamsworkflowswebhookhandlesbasic-local-1739989848"}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 85.238083ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 169 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: | + {"data":{"attributes":{"name":"tf-testaccmsteamsworkflowswebhookhandlesbasic-local-1739989848-updated","url":"https://fake.url.com"},"type":"workflows-webhook-handle"}} + form: {} + headers: + Accept: + - application/json + Content-Type: + - application/json + url: https://api.datadoghq.com/api/v2/integration/ms-teams/configuration/workflows-webhook-handles/bbeabb84-0fec-4af1-95cc-72f78795d8c9 + method: PATCH + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 183 + uncompressed: false + body: '{"data":{"id":"bbeabb84-0fec-4af1-95cc-72f78795d8c9","type":"workflows-webhook-handle","attributes":{"name":"tf-testaccmsteamsworkflowswebhookhandlesbasic-local-1739989848-updated"}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 90.17375ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - application/json + url: https://api.datadoghq.com/api/v2/integration/ms-teams/configuration/workflows-webhook-handles/bbeabb84-0fec-4af1-95cc-72f78795d8c9 + method: GET + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 183 + uncompressed: false + body: '{"data":{"id":"bbeabb84-0fec-4af1-95cc-72f78795d8c9","type":"workflows-webhook-handle","attributes":{"name":"tf-testaccmsteamsworkflowswebhookhandlesbasic-local-1739989848-updated"}}}' + headers: + Content-Type: + - application/vnd.api+json + status: 200 OK + code: 200 + duration: 63.306792ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: api.datadoghq.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Accept: + - '*/*' + url: https://api.datadoghq.com/api/v2/integration/ms-teams/configuration/workflows-webhook-handles/bbeabb84-0fec-4af1-95cc-72f78795d8c9 + method: DELETE + response: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + transfer_encoding: [] + trailer: {} + content_length: 0 + uncompressed: false + body: "" + headers: {} + status: 204 No Content + code: 204 + duration: 49.938417ms diff --git a/datadog/tests/provider_test.go b/datadog/tests/provider_test.go index 8982be1c7..de685d5aa 100644 --- a/datadog/tests/provider_test.go +++ b/datadog/tests/provider_test.go @@ -200,6 +200,7 @@ var testFiles2EndpointTags = map[string]string{ "tests/resource_datadog_integration_gcp_sts_test": "integration-gcp", "tests/resource_datadog_integration_gcp_test": "integration-gcp", "tests/resource_datadog_integration_microsoft_teams_handle_test": "integration-microsoft-teams", + "tests/resource_datadog_integration_ms_teams_workflows_handle_test": "integration-microsoft-teams", "tests/resource_datadog_integration_opsgenie_service_object_test": "integration-opsgenie-service", "tests/resource_datadog_integration_pagerduty_service_object_test": "integration-pagerduty", "tests/resource_datadog_integration_pagerduty_test": "integration-pagerduty", diff --git a/datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go b/datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go new file mode 100644 index 000000000..5bc30e9ca --- /dev/null +++ b/datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go @@ -0,0 +1,128 @@ +package test + +import ( + "context" + "fmt" + "strings" + "testing" + + "github.com/hashicorp/terraform-plugin-testing/helper/resource" + "github.com/hashicorp/terraform-plugin-testing/terraform" + + "github.com/terraform-providers/terraform-provider-datadog/datadog/fwprovider" + "github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" +) + +func TestAccMSTeamsWorkflowsWebhookHandlesBasic(t *testing.T) { + t.Parallel() + ctx, providers, accProviders := testAccFrameworkMuxProviders(context.Background(), t) + uniq := strings.ToLower(uniqueEntityName(ctx, t)) + url := "https://fake.url.com" + + resource.Test(t, resource.TestCase{ + ProtoV5ProviderFactories: accProviders, + CheckDestroy: testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesDestroy(providers.frameworkProvider), + Steps: []resource.TestStep{ + { + Config: testAccCheckDatadogMSTeamsWorkflowsWebhookHandles(uniq, url), + Check: resource.ComposeTestCheckFunc( + testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesExists(providers.frameworkProvider), + resource.TestCheckResourceAttr( + "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "name", uniq), + resource.TestCheckResourceAttr( + "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "url", url), + ), + }, + { + Config: testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesUpdated(uniq, url), + Check: resource.ComposeTestCheckFunc( + testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesExists(providers.frameworkProvider), + resource.TestCheckResourceAttr( + "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "name", fmt.Sprintf("%s-updated", uniq)), + resource.TestCheckResourceAttr( + "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "url", url), + ), + }, + }, + }) +} + +func testAccCheckDatadogMSTeamsWorkflowsWebhookHandles(uniq string, url string) string { + return fmt.Sprintf(` +resource "datadog_integration_ms_teams_microsoft_workflows_webhook_handle" "foo" { + name = "%s" + url = "%s" +}`, uniq, url) +} + +func testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesUpdated(uniq string, url string) string { + return fmt.Sprintf(` +resource "datadog_integration_ms_teams_microsoft_workflows_webhook_handle" "foo" { + name = "%s-updated" + url = "%s" +}`, uniq, url) +} + +func testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesDestroy(accProvider *fwprovider.FrameworkProvider) func(*terraform.State) error { + return func(s *terraform.State) error { + apiInstances := accProvider.DatadogApiInstances + auth := accProvider.Auth + + if err := MSTeamsWorkflowsWebhookHandlesDestroyHelper(auth, s, apiInstances); err != nil { + return err + } + return nil + } +} + +func MSTeamsWorkflowsWebhookHandlesDestroyHelper(auth context.Context, s *terraform.State, apiInstances *utils.ApiInstances) error { + for _, r := range s.RootModule().Resources { + if r.Type != "resource_datadog_integration_ms_teams_microsoft_workflows_webhook_handle" { + continue + } + id := r.Primary.ID + + err := utils.Retry(2, 10, func() error { + _, httpResp, err := apiInstances.GetMicrosoftTeamsIntegrationApiV2().GetWorkflowsWebhookHandle(auth, id) + if err != nil { + if httpResp != nil && httpResp.StatusCode == 404 { + return nil + } + return &utils.RetryableError{Prob: fmt.Sprintf("received an error retrieving handle %s", err)} + } + return &utils.RetryableError{Prob: "Handle still exists"} + }) + + if err != nil { + return err + } + } + return nil +} + +func testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesExists(accProvider *fwprovider.FrameworkProvider) resource.TestCheckFunc { + return func(s *terraform.State) error { + apiInstances := accProvider.DatadogApiInstances + auth := accProvider.Auth + + if err := msTeamsWorkflowsWebhookHandlesExistsHelper(auth, s, apiInstances); err != nil { + return err + } + return nil + } +} + +func msTeamsWorkflowsWebhookHandlesExistsHelper(auth context.Context, s *terraform.State, apiInstances *utils.ApiInstances) error { + for _, r := range s.RootModule().Resources { + if r.Type != "resource_datadog_integration_ms_teams_microsoft_workflows_webhook_handle" { + continue + } + id := r.Primary.ID + + _, httpResp, err := apiInstances.GetMicrosoftTeamsIntegrationApiV2().GetWorkflowsWebhookHandle(auth, id) + if err != nil { + return utils.TranslateClientError(err, httpResp, "error retrieving handle") + } + } + return nil +} diff --git a/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh new file mode 100644 index 000000000..8ee8e5048 --- /dev/null +++ b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh @@ -0,0 +1,2 @@ +# Tenant Based Handles can be imported using UUID, e.g. +terraform import datadog_integration_ms_teams_microsoft_workflows_webhook_handle.testing_microsoft_workflows_webhook_handle "90646597-5fdb-4a17-a240-647003f8c028" diff --git a/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf new file mode 100644 index 000000000..2b26098e8 --- /dev/null +++ b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf @@ -0,0 +1,6 @@ +# Create a new integration_ms_teams_microsoft_workflows_webhook_handle resource + +resource "datadog_integration_ms_teams_microsoft_workflows_webhook_handle" "testing_microsoft_workflows_webhook_handle" { + name = "sample_handle_name" + url = "https://fake.url.com" +} From f08db9136b8518f0ca566d7817ec4914050d53e4 Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Thu, 20 Feb 2025 10:22:35 -0500 Subject: [PATCH 6/8] Int to int --- ...og_integration_microsoft_teams_workflows_webhook_handle.go | 2 +- ...integration_ms_teams_microsoft_workflows_webhook_handle.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go index 61d7f03f7..6711aa464 100644 --- a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go +++ b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go @@ -46,7 +46,7 @@ func (r *workflowsWebhookHandleResource) Metadata(_ context.Context, request res func (r *workflowsWebhookHandleResource) Schema(_ context.Context, _ resource.SchemaRequest, response *resource.SchemaResponse) { response.Schema = schema.Schema{ - Description: "Resource for interacting with Datadog Microsoft Teams Integration Microsoft Workflows webhook handles.", + Description: "Resource for interacting with Datadog Microsoft Teams integration Microsoft Workflows webhook handles.", Attributes: map[string]schema.Attribute{ "name": schema.StringAttribute{ Required: true, diff --git a/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md b/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md index 44f0662d2..e50fe3ab3 100644 --- a/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md +++ b/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md @@ -3,12 +3,12 @@ page_title: "datadog_integration_ms_teams_microsoft_workflows_webhook_handle Resource - terraform-provider-datadog" subcategory: "" description: |- - Resource for interacting with Datadog Microsoft Teams Integration Microsoft Workflows webhook handles. + Resource for interacting with Datadog Microsoft Teams integration Microsoft Workflows webhook handles. --- # datadog_integration_ms_teams_microsoft_workflows_webhook_handle (Resource) -Resource for interacting with Datadog Microsoft Teams Integration Microsoft Workflows webhook handles. +Resource for interacting with Datadog Microsoft Teams integration Microsoft Workflows webhook handles. From 3fc2a33ec9fa52d0c9a2f6a1a61d072120defee7 Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Tue, 25 Feb 2025 11:03:53 -0500 Subject: [PATCH 7/8] rename --- ...n_microsoft_teams_workflows_webhook_handle.go | 8 +------- ...integration_ms_teams_workflows_handle_test.go | 16 ++++++++-------- ...gration_ms_teams_workflows_webhook_handle.md} | 4 ++-- .../import.sh | 4 ++-- .../resource.tf | 4 ++-- 5 files changed, 15 insertions(+), 21 deletions(-) rename docs/resources/{integration_ms_teams_microsoft_workflows_webhook_handle.md => integration_ms_teams_workflows_webhook_handle.md} (74%) diff --git a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go index 6711aa464..670a7e2fc 100644 --- a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go +++ b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go @@ -41,7 +41,7 @@ func (r *workflowsWebhookHandleResource) Configure(_ context.Context, request re } func (r *workflowsWebhookHandleResource) Metadata(_ context.Context, request resource.MetadataRequest, response *resource.MetadataResponse) { - response.TypeName = "integration_ms_teams_microsoft_workflows_webhook_handle" + response.TypeName = "integration_ms_teams_workflows_webhook_handle" } func (r *workflowsWebhookHandleResource) Schema(_ context.Context, _ resource.SchemaRequest, response *resource.SchemaResponse) { @@ -172,12 +172,6 @@ func (r *workflowsWebhookHandleResource) updateState(ctx context.Context, state if name, ok := attributes.GetNameOk(); ok && name != nil { state.Name = types.StringValue(*name) } - - // Only update URL if not set - the API endpoints never return - // the url, so this is how we recognize new values. - if state.URL.IsNull() { - state.URL = types.StringValue(maskedSecret) - } } func (r *workflowsWebhookHandleResource) buildWorkflowsWebhookHandleRequestBody(ctx context.Context, state *workflowsWebhookHandleModel) *datadogV2.MicrosoftTeamsCreateWorkflowsWebhookHandleRequest { diff --git a/datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go b/datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go index 5bc30e9ca..df1d2d898 100644 --- a/datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go +++ b/datadog/tests/resource_datadog_integration_ms_teams_workflows_handle_test.go @@ -28,9 +28,9 @@ func TestAccMSTeamsWorkflowsWebhookHandlesBasic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesExists(providers.frameworkProvider), resource.TestCheckResourceAttr( - "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "name", uniq), + "datadog_integration_ms_teams_workflows_webhook_handle.foo", "name", uniq), resource.TestCheckResourceAttr( - "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "url", url), + "datadog_integration_ms_teams_workflows_webhook_handle.foo", "url", url), ), }, { @@ -38,9 +38,9 @@ func TestAccMSTeamsWorkflowsWebhookHandlesBasic(t *testing.T) { Check: resource.ComposeTestCheckFunc( testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesExists(providers.frameworkProvider), resource.TestCheckResourceAttr( - "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "name", fmt.Sprintf("%s-updated", uniq)), + "datadog_integration_ms_teams_workflows_webhook_handle.foo", "name", fmt.Sprintf("%s-updated", uniq)), resource.TestCheckResourceAttr( - "datadog_integration_ms_teams_microsoft_workflows_webhook_handle.foo", "url", url), + "datadog_integration_ms_teams_workflows_webhook_handle.foo", "url", url), ), }, }, @@ -49,7 +49,7 @@ func TestAccMSTeamsWorkflowsWebhookHandlesBasic(t *testing.T) { func testAccCheckDatadogMSTeamsWorkflowsWebhookHandles(uniq string, url string) string { return fmt.Sprintf(` -resource "datadog_integration_ms_teams_microsoft_workflows_webhook_handle" "foo" { +resource "datadog_integration_ms_teams_workflows_webhook_handle" "foo" { name = "%s" url = "%s" }`, uniq, url) @@ -57,7 +57,7 @@ resource "datadog_integration_ms_teams_microsoft_workflows_webhook_handle" "foo" func testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesUpdated(uniq string, url string) string { return fmt.Sprintf(` -resource "datadog_integration_ms_teams_microsoft_workflows_webhook_handle" "foo" { +resource "datadog_integration_ms_teams_workflows_webhook_handle" "foo" { name = "%s-updated" url = "%s" }`, uniq, url) @@ -77,7 +77,7 @@ func testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesDestroy(accProvider *fwpro func MSTeamsWorkflowsWebhookHandlesDestroyHelper(auth context.Context, s *terraform.State, apiInstances *utils.ApiInstances) error { for _, r := range s.RootModule().Resources { - if r.Type != "resource_datadog_integration_ms_teams_microsoft_workflows_webhook_handle" { + if r.Type != "resource_datadog_integration_ms_teams_workflows_webhook_handle" { continue } id := r.Primary.ID @@ -114,7 +114,7 @@ func testAccCheckDatadogMSTeamsWorkflowsWebhookHandlesExists(accProvider *fwprov func msTeamsWorkflowsWebhookHandlesExistsHelper(auth context.Context, s *terraform.State, apiInstances *utils.ApiInstances) error { for _, r := range s.RootModule().Resources { - if r.Type != "resource_datadog_integration_ms_teams_microsoft_workflows_webhook_handle" { + if r.Type != "resource_datadog_integration_ms_teams_workflows_webhook_handle" { continue } id := r.Primary.ID diff --git a/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md b/docs/resources/integration_ms_teams_workflows_webhook_handle.md similarity index 74% rename from docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md rename to docs/resources/integration_ms_teams_workflows_webhook_handle.md index e50fe3ab3..cb266bcae 100644 --- a/docs/resources/integration_ms_teams_microsoft_workflows_webhook_handle.md +++ b/docs/resources/integration_ms_teams_workflows_webhook_handle.md @@ -1,12 +1,12 @@ --- # generated by https://github.com/hashicorp/terraform-plugin-docs -page_title: "datadog_integration_ms_teams_microsoft_workflows_webhook_handle Resource - terraform-provider-datadog" +page_title: "datadog_integration_ms_teams_workflows_webhook_handle Resource - terraform-provider-datadog" subcategory: "" description: |- Resource for interacting with Datadog Microsoft Teams integration Microsoft Workflows webhook handles. --- -# datadog_integration_ms_teams_microsoft_workflows_webhook_handle (Resource) +# datadog_integration_ms_teams_workflows_webhook_handle (Resource) Resource for interacting with Datadog Microsoft Teams integration Microsoft Workflows webhook handles. diff --git a/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh index 8ee8e5048..76c70b43f 100644 --- a/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh +++ b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/import.sh @@ -1,2 +1,2 @@ -# Tenant Based Handles can be imported using UUID, e.g. -terraform import datadog_integration_ms_teams_microsoft_workflows_webhook_handle.testing_microsoft_workflows_webhook_handle "90646597-5fdb-4a17-a240-647003f8c028" +# Microsoft Workflows Webhook Handles can be imported using UUID, e.g. +terraform import datadog_integration_ms_teams_workflows_webhook_handle.testing_microsoft_workflows_webhook_handle "90646597-5fdb-4a17-a240-647003f8c028" diff --git a/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf index 2b26098e8..e8d83fd9c 100644 --- a/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf +++ b/examples/resources/datadog_integration_microsoft_teams_microsoft_workflows_webhook_handle/resource.tf @@ -1,6 +1,6 @@ -# Create a new integration_ms_teams_microsoft_workflows_webhook_handle resource +# Create a new integration_ms_teams_workflows_webhook_handle resource -resource "datadog_integration_ms_teams_microsoft_workflows_webhook_handle" "testing_microsoft_workflows_webhook_handle" { +resource "datadog_integration_ms_teams_workflows_webhook_handle" "testing_microsoft_workflows_webhook_handle" { name = "sample_handle_name" url = "https://fake.url.com" } From 2a72797ecab20261c6a42554d47b6ad2b6950cd9 Mon Sep 17 00:00:00 2001 From: Kalil Black Date: Tue, 25 Feb 2025 11:08:18 -0500 Subject: [PATCH 8/8] remove const --- ...adog_integration_microsoft_teams_workflows_webhook_handle.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go index 670a7e2fc..b40d97027 100644 --- a/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go +++ b/datadog/fwprovider/resource_datadog_integration_microsoft_teams_workflows_webhook_handle.go @@ -12,8 +12,6 @@ import ( "github.com/terraform-providers/terraform-provider-datadog/datadog/internal/utils" ) -const maskedSecret = "*****" - var ( _ resource.ResourceWithConfigure = &workflowsWebhookHandleResource{} _ resource.ResourceWithImportState = &workflowsWebhookHandleResource{}