Skip to content

Commit

Permalink
squash commits
Browse files Browse the repository at this point in the history
  • Loading branch information
embeaken committed Feb 4, 2025
1 parent b2a3175 commit 20b6d71
Show file tree
Hide file tree
Showing 12 changed files with 1,369 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ datadog/**/*datadog_synthetics_concurrency_cap* @DataDog/web-frameworks @DataDo
datadog/**/*datadog_team* @DataDog/web-frameworks @DataDog/core-app
datadog/**/*datadog_organization_settings* @DataDog/web-frameworks @DataDog/core-app @DataDog/trust-and-safety
datadog/**/*datadog_integration_microsoft_teams* @DataDog/web-frameworks @DataDog/chat-integrations
datadog/**/*datadog_connection* @DataDog/web-frameworks @DataDog/action-platform
171 changes: 171 additions & 0 deletions datadog/fwprovider/data_source_datadog_connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package fwprovider

import (
"context"

"github.com/DataDog/datadog-api-client-go/v2/api/datadogV2"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)

var _ datasource.DataSource = &connectionDatasource{}

type connectionDatasource struct {
Api *datadogV2.ActionConnectionApi
Auth context.Context
}

func NewDatadogConnectionDataSource() datasource.DataSource {
return &connectionDatasource{}
}

func (d *connectionDatasource) Configure(_ context.Context, request datasource.ConfigureRequest, response *datasource.ConfigureResponse) {
providerData := request.ProviderData.(*FrameworkProvider)
d.Api = providerData.DatadogApiInstances.GetActionConnectionApiV2()
d.Auth = providerData.Auth
}

func (d *connectionDatasource) Metadata(_ context.Context, request datasource.MetadataRequest, response *datasource.MetadataResponse) {
response.TypeName = "connection"
}

func (d *connectionDatasource) Schema(_ context.Context, request datasource.SchemaRequest, response *datasource.SchemaResponse) {
response.Schema = schema.Schema{
Description: "A connection that can be used in Actions, including in the Workflow Automation and App Builder products.",
Attributes: map[string]schema.Attribute{
"id": schema.StringAttribute{
Description: "ID for Connection.",
Required: true,
},
"name": schema.StringAttribute{
Computed: true,
Description: "Name of the connection",
},
},
Blocks: map[string]schema.Block{
"aws": schema.SingleNestedBlock{
Description: "Configuration for an AWS connection",
Blocks: map[string]schema.Block{
"assume_role": schema.SingleNestedBlock{
Description: "Configuration for an assume role AWS connection",
Attributes: map[string]schema.Attribute{
"external_id": schema.StringAttribute{
Description: "External ID that specifies which connection can be used to assume the role",
Computed: true,
},
"principal_id": schema.StringAttribute{
Description: "AWS account that will assume the role",
Computed: true,
},
"account_id": schema.StringAttribute{
Description: "AWS account that the connection is created for",
Computed: true,
},
"role": schema.StringAttribute{
Description: "Role to assume",
Computed: true,
},
},
},
},
},
"http": schema.SingleNestedBlock{
Description: "Configuration for an HTTP connection",
Attributes: map[string]schema.Attribute{
"base_url": schema.StringAttribute{
Description: "Base HTTP url for the integration",
Computed: true,
},
},
Blocks: map[string]schema.Block{
"token_auth": schema.SingleNestedBlock{
Description: "Configuration for an HTTP connection that uses token auth",
Blocks: map[string]schema.Block{
"token": schema.ListNestedBlock{
Description: "Token for HTTP authentication",
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"type": schema.StringAttribute{
Description: "Token type",
Computed: true,
},
"name": schema.StringAttribute{
Description: "Token name",
Computed: true,
},
"value": schema.StringAttribute{
Description: "Token value",
Computed: true,
Sensitive: true,
},
},
},
},
"header": schema.ListNestedBlock{
Description: "Header for HTTP authentication",
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: "Header name",
Computed: true,
},
"value": schema.StringAttribute{
Description: "",
Computed: true,
},
},
},
},
"url_parameter": schema.ListNestedBlock{
Description: "URL parameter for HTTP authentication",
NestedObject: schema.NestedBlockObject{
Attributes: map[string]schema.Attribute{
"name": schema.StringAttribute{
Description: "URL parameter name",
Computed: true,
},
"value": schema.StringAttribute{
Description: "URL parameter value",
Computed: true,
},
},
},
},
"body": schema.SingleNestedBlock{
Description: "Body for HTTP authentication",
Attributes: map[string]schema.Attribute{
"content_type": schema.StringAttribute{
Description: "Content type of the body",
Computed: true,
},
"content": schema.StringAttribute{
Description: "Serialized body content",
Computed: true,
},
},
},
},
},
},
},
},
}
}

func (d *connectionDatasource) Read(ctx context.Context, request datasource.ReadRequest, response *datasource.ReadResponse) {
var state connectionResourceModel
diags := request.Config.Get(ctx, &state)
response.Diagnostics.Append(diags...)
if response.Diagnostics.HasError() {
return
}

connModel, err := readConnection(d.Auth, d.Api, state.ID.ValueString(), state)
if err != nil {
response.Diagnostics.AddError("Could not read connection", err.Error())
return
}

diags = response.State.Set(ctx, connModel)
response.Diagnostics.Append(diags...)
}
2 changes: 2 additions & 0 deletions datadog/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ var Resources = []func() resource.Resource{
NewWebhookCustomVariableResource,
NewLogsCustomDestinationResource,
NewTenantBasedHandleResource,
NewConnectionResource,
}

var Datasources = []func() datasource.DataSource{
Expand All @@ -93,6 +94,7 @@ var Datasources = []func() datasource.DataSource{
NewSecurityMonitoringSuppressionDataSource,
NewCSMThreatsAgentRulesDataSource,
NewLogsPipelinesOrderDataSource,
NewDatadogConnectionDataSource,
}

// FrameworkProvider struct
Expand Down
Loading

0 comments on commit 20b6d71

Please sign in to comment.