Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wip] Ilya/connections provider #2718

Draft
wants to merge 43 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8b59b79
scaffold connections resource
irubnich Dec 4, 2024
b5c2bce
scaffold data source
irubnich Dec 4, 2024
63afcfc
more DS scaffold
irubnich Dec 4, 2024
831ce32
focus on resource
irubnich Dec 4, 2024
9d577eb
add delete
irubnich Dec 4, 2024
16cf40c
add update
irubnich Dec 4, 2024
d337ca6
consistency
irubnich Dec 4, 2024
8eccf53
working schema
irubnich Dec 13, 2024
80275c7
optional to computed
irubnich Dec 16, 2024
0a5d7d7
flesh out model structs
irubnich Dec 17, 2024
1b4398a
validate exclusivity
irubnich Dec 17, 2024
278cf01
add descriptions for docs
irubnich Dec 19, 2024
54b33ba
docs update
irubnich Dec 19, 2024
9c0ab37
more complex validations
irubnich Dec 19, 2024
605e05a
mark token values sensitive to prevent appearing in output
irubnich Dec 19, 2024
5e21e97
slight fixes
irubnich Jan 3, 2025
a136978
flesh out data source
irubnich Jan 3, 2025
2237ad0
clean up naming
irubnich Jan 3, 2025
860fcc1
wire up actual client
irubnich Jan 6, 2025
6554e76
start wiring up data source
irubnich Jan 6, 2025
0ed1e3e
share read logic
irubnich Jan 6, 2025
0ff2089
wip
irubnich Jan 8, 2025
1623e3e
create AWS works
irubnich Jan 10, 2025
616cf5f
create HTTP working
irubnich Jan 10, 2025
e16333b
delete works
irubnich Jan 10, 2025
5969d9f
changes
irubnich Jan 10, 2025
1ad3835
trying to debug read after create
irubnich Jan 10, 2025
4bc26a9
fix some weirdness
irubnich Jan 15, 2025
efc218c
working update
irubnich Jan 16, 2025
5c93ca3
badly implement detection of deleted headers
irubnich Jan 16, 2025
6334338
extend deletion detection to url params and tokens
irubnich Jan 16, 2025
8481c44
move delete logic to separate method + cleanup
irubnich Jan 16, 2025
5bdb9b2
use generated client from git
irubnich Jan 17, 2025
15a03f2
move empty string validation into schema
irubnich Jan 17, 2025
8dddb33
simplify validation
irubnich Jan 17, 2025
75e8f40
cleanup between data source and resource
irubnich Jan 17, 2025
e415fc3
code quality
irubnich Jan 17, 2025
530412b
add action platform to codeowners of connection provider
irubnich Jan 17, 2025
30d267c
generate docs
irubnich Jan 17, 2025
12f9851
fix body deletion
irubnich Jan 22, 2025
fa8ca6b
data source test setup
irubnich Jan 23, 2025
cc64a2e
working data source test wow
irubnich Jan 24, 2025
a08c494
start resource test
irubnich Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/api-clients @DataDog/s
datadog/**/*datadog_team* @DataDog/api-clients @DataDog/core-app
datadog/**/*datadog_organization_settings* @DataDog/api-clients @DataDog/core-app @DataDog/trust-and-safety
datadog/**/*datadog_integration_microsoft_teams* @DataDog/api-clients @DataDog/chat-integrations
datadog/**/*datadog_connection* @DataDog/api-clients @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 used to scope 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 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 using 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
Loading