Skip to content

Commit 4ccf666

Browse files
authored
[datadog_observability_pipeline] make google auth optional (#3332)
datadog_observability_pipeline: make google auth optional update cassettes bump API client update docs update docs Co-authored-by: May Lee <[email protected]> update docs Co-authored-by: May Lee <[email protected]> correct docs Co-authored-by: vladimir.zhuk <[email protected]>
1 parent 0096ae9 commit 4ccf666

21 files changed

+728
-118
lines changed

datadog/fwprovider/resource_datadog_observability_pipeline.go

Lines changed: 73 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ type gcsDestinationModel struct {
458458
KeyPrefix types.String `tfsdk:"key_prefix"`
459459
StorageClass types.String `tfsdk:"storage_class"`
460460
Acl types.String `tfsdk:"acl"`
461-
Auth gcpAuthModel `tfsdk:"auth"`
461+
Auth *gcpAuthModel `tfsdk:"auth"`
462462
Metadata []metadataEntry `tfsdk:"metadata"`
463463
}
464464

@@ -978,16 +978,8 @@ func (r *observabilityPipelineResource) Schema(_ context.Context, _ resource.Sch
978978
},
979979
},
980980
Blocks: map[string]schema.Block{
981-
"auth": schema.SingleNestedBlock{
982-
Description: "GCP credentials used to authenticate with Google Cloud Storage.",
983-
Attributes: map[string]schema.Attribute{
984-
"credentials_file": schema.StringAttribute{
985-
Required: true,
986-
Description: "Path to the GCP service account key file.",
987-
},
988-
},
989-
},
990-
"tls": tlsSchema(),
981+
"auth": gcpAuthSchema(),
982+
"tls": tlsSchema(),
991983
},
992984
},
993985
},
@@ -1893,20 +1885,12 @@ func (r *observabilityPipelineResource) Schema(_ context.Context, _ resource.Sch
18931885
Description: "Storage class used for objects stored in GCS.",
18941886
},
18951887
"acl": schema.StringAttribute{
1896-
Required: true,
1888+
Optional: true,
18971889
Description: "Access control list setting for objects written to the bucket.",
18981890
},
18991891
},
19001892
Blocks: map[string]schema.Block{
1901-
"auth": schema.SingleNestedBlock{
1902-
Description: "GCP credentials used to authenticate with Google Cloud Storage.",
1903-
Attributes: map[string]schema.Attribute{
1904-
"credentials_file": schema.StringAttribute{
1905-
Required: true,
1906-
Description: "Path to the GCP service account key file.",
1907-
},
1908-
},
1909-
},
1893+
"auth": gcpAuthSchema(),
19101894
"metadata": schema.ListNestedBlock{
19111895
Description: "Custom metadata key-value pairs added to each object.",
19121896
NestedObject: schema.NestedBlockObject{
@@ -1952,16 +1936,8 @@ func (r *observabilityPipelineResource) Schema(_ context.Context, _ resource.Sch
19521936
},
19531937
},
19541938
Blocks: map[string]schema.Block{
1955-
"auth": schema.SingleNestedBlock{
1956-
Description: "GCP credentials used to authenticate with Google Cloud Pub/Sub.",
1957-
Attributes: map[string]schema.Attribute{
1958-
"credentials_file": schema.StringAttribute{
1959-
Optional: true,
1960-
Description: "Path to the GCP service account key file.",
1961-
},
1962-
},
1963-
},
1964-
"tls": tlsSchema(),
1939+
"auth": gcpAuthSchema(),
1940+
"tls": tlsSchema(),
19651941
},
19661942
},
19671943
},
@@ -2265,15 +2241,7 @@ func (r *observabilityPipelineResource) Schema(_ context.Context, _ resource.Sch
22652241
},
22662242
},
22672243
Blocks: map[string]schema.Block{
2268-
"auth": schema.SingleNestedBlock{
2269-
Description: "GCP credentials used to authenticate with Google Cloud Storage.",
2270-
Attributes: map[string]schema.Attribute{
2271-
"credentials_file": schema.StringAttribute{
2272-
Optional: true,
2273-
Description: "Path to the GCP service account key file.",
2274-
},
2275-
},
2276-
},
2244+
"auth": gcpAuthSchema(),
22772245
},
22782246
},
22792247
},
@@ -2349,6 +2317,40 @@ func tlsSchema() schema.SingleNestedBlock {
23492317
}
23502318
}
23512319

2320+
func gcpAuthSchema() schema.SingleNestedBlock {
2321+
return schema.SingleNestedBlock{
2322+
Description: "GCP credentials used to authenticate with Google Cloud services.",
2323+
Attributes: map[string]schema.Attribute{
2324+
"credentials_file": schema.StringAttribute{
2325+
Optional: true,
2326+
Description: "Path to the GCP service account key file. Required when `auth` block is specified.",
2327+
},
2328+
},
2329+
}
2330+
}
2331+
2332+
func expandGcpAuth(auth *gcpAuthModel) *datadogV2.ObservabilityPipelineGcpAuth {
2333+
if auth == nil {
2334+
return nil
2335+
}
2336+
2337+
gcpAuth := &datadogV2.ObservabilityPipelineGcpAuth{}
2338+
if !auth.CredentialsFile.IsNull() {
2339+
gcpAuth.SetCredentialsFile(auth.CredentialsFile.ValueString())
2340+
}
2341+
return gcpAuth
2342+
}
2343+
2344+
func flattenGcpAuth(auth *datadogV2.ObservabilityPipelineGcpAuth) *gcpAuthModel {
2345+
if auth == nil {
2346+
return nil
2347+
}
2348+
2349+
return &gcpAuthModel{
2350+
CredentialsFile: types.StringValue(auth.CredentialsFile),
2351+
}
2352+
}
2353+
23522354
func (r *observabilityPipelineResource) ImportState(ctx context.Context, request resource.ImportStateRequest, response *resource.ImportStateResponse) {
23532355
resource.ImportStatePassthroughID(ctx, frameworkPath.Root("id"), request, response)
23542356
}
@@ -3534,15 +3536,18 @@ func expandGoogleCloudStorageDestination(ctx context.Context, d *gcsDestinationM
35343536
dest.SetId(d.Id.ValueString())
35353537
dest.SetBucket(d.Bucket.ValueString())
35363538
dest.SetStorageClass(datadogV2.ObservabilityPipelineGoogleCloudStorageDestinationStorageClass(d.StorageClass.ValueString()))
3537-
dest.SetAcl(datadogV2.ObservabilityPipelineGoogleCloudStorageDestinationAcl(d.Acl.ValueString()))
3539+
3540+
if !d.Acl.IsNull() {
3541+
dest.SetAcl(datadogV2.ObservabilityPipelineGoogleCloudStorageDestinationAcl(d.Acl.ValueString()))
3542+
}
35383543

35393544
if !d.KeyPrefix.IsNull() {
35403545
dest.SetKeyPrefix(d.KeyPrefix.ValueString())
35413546
}
35423547

3543-
dest.SetAuth(datadogV2.ObservabilityPipelineGcpAuth{
3544-
CredentialsFile: d.Auth.CredentialsFile.ValueString(),
3545-
})
3548+
if auth := expandGcpAuth(d.Auth); auth != nil {
3549+
dest.SetAuth(*auth)
3550+
}
35463551

35473552
var metadata []datadogV2.ObservabilityPipelineMetadataEntry
35483553
for _, m := range d.Metadata {
@@ -3577,18 +3582,24 @@ func flattenGoogleCloudStorageDestination(ctx context.Context, src *datadogV2.Ob
35773582
})
35783583
}
35793584

3580-
return &gcsDestinationModel{
3585+
out := &gcsDestinationModel{
35813586
Id: types.StringValue(src.GetId()),
35823587
Bucket: types.StringValue(src.GetBucket()),
35833588
KeyPrefix: types.StringPointerValue(src.KeyPrefix),
35843589
StorageClass: types.StringValue(string(src.GetStorageClass())),
3585-
Acl: types.StringValue(string(src.GetAcl())),
3586-
Auth: gcpAuthModel{
3587-
CredentialsFile: types.StringValue(src.Auth.CredentialsFile),
3588-
},
3589-
Metadata: metadata,
3590-
Inputs: inputs,
3590+
Metadata: metadata,
3591+
Inputs: inputs,
3592+
}
3593+
3594+
if acl, ok := src.GetAclOk(); ok {
3595+
out.Acl = types.StringValue(string(*acl))
35913596
}
3597+
3598+
if auth, ok := src.GetAuthOk(); ok {
3599+
out.Auth = flattenGcpAuth(auth)
3600+
}
3601+
3602+
return out
35923603
}
35933604

35943605
func expandGooglePubSubDestination(ctx context.Context, d *googlePubSubDestinationModel) datadogV2.ObservabilityPipelineConfigDestinationItem {
@@ -3601,10 +3612,8 @@ func expandGooglePubSubDestination(ctx context.Context, d *googlePubSubDestinati
36013612
dest.SetEncoding(datadogV2.ObservabilityPipelineGooglePubSubDestinationEncoding(d.Encoding.ValueString()))
36023613
}
36033614

3604-
if d.Auth != nil {
3605-
auth := datadogV2.ObservabilityPipelineGcpAuth{}
3606-
auth.SetCredentialsFile(d.Auth.CredentialsFile.ValueString())
3607-
dest.SetAuth(auth)
3615+
if auth := expandGcpAuth(d.Auth); auth != nil {
3616+
dest.SetAuth(*auth)
36083617
}
36093618

36103619
if d.Tls != nil {
@@ -3639,9 +3648,7 @@ func flattenGooglePubSubDestination(ctx context.Context, src *datadogV2.Observab
36393648
}
36403649

36413650
if auth, ok := src.GetAuthOk(); ok {
3642-
out.Auth = &gcpAuthModel{
3643-
CredentialsFile: types.StringValue(auth.CredentialsFile),
3644-
}
3651+
out.Auth = flattenGcpAuth(auth)
36453652
}
36463653

36473654
if src.Tls != nil {
@@ -4520,10 +4527,8 @@ func expandGooglePubSubSource(src *googlePubSubSourceModel) datadogV2.Observabil
45204527
pubsub.SetSubscription(src.Subscription.ValueString())
45214528
pubsub.SetDecoding(datadogV2.ObservabilityPipelineDecoding(src.Decoding.ValueString()))
45224529

4523-
if src.Auth != nil {
4524-
auth := datadogV2.ObservabilityPipelineGcpAuth{}
4525-
auth.SetCredentialsFile(src.Auth.CredentialsFile.ValueString())
4526-
pubsub.SetAuth(auth)
4530+
if auth := expandGcpAuth(src.Auth); auth != nil {
4531+
pubsub.SetAuth(*auth)
45274532
}
45284533

45294534
if src.Tls != nil {
@@ -4546,8 +4551,8 @@ func flattenGooglePubSubSource(src *datadogV2.ObservabilityPipelineGooglePubSubS
45464551
Decoding: types.StringValue(string(src.GetDecoding())),
45474552
}
45484553

4549-
out.Auth = &gcpAuthModel{
4550-
CredentialsFile: types.StringValue(src.Auth.CredentialsFile),
4554+
if auth, ok := src.GetAuthOk(); ok {
4555+
out.Auth = flattenGcpAuth(auth)
45514556
}
45524557

45534558
if src.Tls != nil {
@@ -4881,12 +4886,8 @@ func expandGoogleChronicleDestination(ctx context.Context, src *googleChronicleD
48814886
src.Inputs.ElementsAs(ctx, &inputs, false)
48824887
dest.SetInputs(inputs)
48834888

4884-
if src.Auth != nil {
4885-
auth := datadogV2.ObservabilityPipelineGcpAuth{}
4886-
if !src.Auth.CredentialsFile.IsNull() {
4887-
auth.SetCredentialsFile(src.Auth.CredentialsFile.ValueString())
4888-
}
4889-
dest.Auth = auth
4889+
if auth := expandGcpAuth(src.Auth); auth != nil {
4890+
dest.SetAuth(*auth)
48904891
}
48914892

48924893
if !src.CustomerId.IsNull() {
@@ -4919,8 +4920,8 @@ func flattenGoogleChronicleDestination(ctx context.Context, src *datadogV2.Obser
49194920
LogType: types.StringValue(src.GetLogType()),
49204921
}
49214922

4922-
out.Auth = &gcpAuthModel{
4923-
CredentialsFile: types.StringValue(src.Auth.CredentialsFile),
4923+
if auth, ok := src.GetAuthOk(); ok {
4924+
out.Auth = flattenGcpAuth(auth)
49244925
}
49254926

49264927
return out
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2025-04-29T12:01:31.171761+02:00
1+
2025-11-19T17:16:41.161176+01:00

datadog/tests/cassettes/TestAccDatadogObservabilityPipeline_googleChronicleDestination.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ interactions:
3131
content_length: 431
3232
uncompressed: false
3333
body: |
34-
{"data":{"id":"f1690c06-24e0-11f0-92e2-da7ad0900002","type":"pipelines","attributes":{"name":"chronicle pipeline","config":{"destinations":[{"auth":{"credentials_file":"/secrets/gcp.json"},"customer_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6","encoding":"json","id":"chronicle-dest-1","inputs":["source-1"],"log_type":"nginx_logs","type":"google_chronicle"}],"processors":[],"sources":[{"id":"source-1","type":"datadog_agent"}]}}}}
34+
{"data":{"id":"226cb6b8-c563-11f0-bd66-da7ad0900002","type":"pipelines","attributes":{"name":"chronicle pipeline","config":{"destinations":[{"auth":{"credentials_file":"/secrets/gcp.json"},"customer_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6","encoding":"json","id":"chronicle-dest-1","inputs":["source-1"],"log_type":"nginx_logs","type":"google_chronicle"}],"processors":[],"sources":[{"id":"source-1","type":"datadog_agent"}]}}}}
3535
headers:
3636
Content-Type:
3737
- application/json
3838
status: 201 Created
3939
code: 201
40-
duration: 666.372958ms
40+
duration: 518.496334ms
4141
- id: 1
4242
request:
4343
proto: HTTP/1.1
@@ -54,7 +54,7 @@ interactions:
5454
headers:
5555
Accept:
5656
- application/json
57-
url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/f1690c06-24e0-11f0-92e2-da7ad0900002
57+
url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/226cb6b8-c563-11f0-bd66-da7ad0900002
5858
method: GET
5959
response:
6060
proto: HTTP/1.1
@@ -65,13 +65,13 @@ interactions:
6565
content_length: 431
6666
uncompressed: false
6767
body: |
68-
{"data":{"id":"f1690c06-24e0-11f0-92e2-da7ad0900002","type":"pipelines","attributes":{"name":"chronicle pipeline","config":{"destinations":[{"auth":{"credentials_file":"/secrets/gcp.json"},"customer_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6","encoding":"json","id":"chronicle-dest-1","inputs":["source-1"],"log_type":"nginx_logs","type":"google_chronicle"}],"processors":[],"sources":[{"id":"source-1","type":"datadog_agent"}]}}}}
68+
{"data":{"id":"226cb6b8-c563-11f0-bd66-da7ad0900002","type":"pipelines","attributes":{"name":"chronicle pipeline","config":{"destinations":[{"auth":{"credentials_file":"/secrets/gcp.json"},"customer_id":"3fa85f64-5717-4562-b3fc-2c963f66afa6","encoding":"json","id":"chronicle-dest-1","inputs":["source-1"],"log_type":"nginx_logs","type":"google_chronicle"}],"processors":[],"sources":[{"id":"source-1","type":"datadog_agent"}]}}}}
6969
headers:
7070
Content-Type:
7171
- application/json
7272
status: 200 OK
7373
code: 200
74-
duration: 326.566625ms
74+
duration: 244.281667ms
7575
- id: 2
7676
request:
7777
proto: HTTP/1.1
@@ -88,7 +88,7 @@ interactions:
8888
headers:
8989
Accept:
9090
- '*/*'
91-
url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/f1690c06-24e0-11f0-92e2-da7ad0900002
91+
url: https://api.datadoghq.com/api/v2/remote_config/products/obs_pipelines/pipelines/226cb6b8-c563-11f0-bd66-da7ad0900002
9292
method: DELETE
9393
response:
9494
proto: HTTP/1.1
@@ -104,4 +104,4 @@ interactions:
104104
- application/json
105105
status: 204 No Content
106106
code: 204
107-
duration: 457.401125ms
107+
duration: 469.484542ms
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2025-11-19T17:16:43.764799+01:00

0 commit comments

Comments
 (0)