From 6fc6df8d91e9724b26644bf729fc626225bd1a20 Mon Sep 17 00:00:00 2001 From: Integralist Date: Fri, 15 Mar 2024 16:21:48 +0000 Subject: [PATCH] feat(scalyr): add project_id --- fastly/block_fastly_service_logging_scalyr.go | 15 +++++++++++++++ .../block_fastly_service_logging_scalyr_test.go | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/fastly/block_fastly_service_logging_scalyr.go b/fastly/block_fastly_service_logging_scalyr.go index 85c8f8abc..8d8f19402 100644 --- a/fastly/block_fastly_service_logging_scalyr.go +++ b/fastly/block_fastly_service_logging_scalyr.go @@ -37,6 +37,11 @@ func (h *ScalyrServiceAttributeHandler) GetSchema() *schema.Schema { Required: true, Description: "The unique name of the Scalyr logging endpoint. It is important to note that changing this attribute will delete and recreate the resource", }, + "project_id": { + Type: schema.TypeString, + Optional: true, + Description: "The name of the logfile field sent to Scalyr", + }, "region": { Type: schema.TypeString, Optional: true, @@ -151,6 +156,9 @@ func (h *ScalyrServiceAttributeHandler) Update(_ context.Context, d *schema.Reso if v, ok := modified["placement"]; ok { opts.Placement = gofastly.ToPointer(v.(string)) } + if v, ok := modified["project_id"]; ok { + opts.ProjectID = gofastly.ToPointer(v.(string)) + } log.Printf("[DEBUG] Update Scalyr Opts: %#v", opts) _, err := conn.UpdateScalyr(&opts) @@ -216,6 +224,9 @@ func flattenScalyr(remoteState []*gofastly.Scalyr) []map[string]any { if resource.FormatVersion != nil { data["format_version"] = *resource.FormatVersion } + if resource.ProjectID != nil { + data["project_id"] = *resource.ProjectID + } // Prune any empty values that come from the default string value in structs. for k, v := range data { @@ -244,6 +255,10 @@ func (h *ScalyrServiceAttributeHandler) buildCreate(scalyrMap any, serviceID str Token: gofastly.ToPointer(resource["token"].(string)), } + if v := resource["project_id"].(string); v != "" { + opts.ProjectID = gofastly.ToPointer(v) + } + // WARNING: The following fields shouldn't have an empty string passed. // As it will cause the Fastly API to return an error. // This is because go-fastly v7+ will not 'omitempty' due to pointer type. diff --git a/fastly/block_fastly_service_logging_scalyr_test.go b/fastly/block_fastly_service_logging_scalyr_test.go index 6f639d27a..931a5a08e 100644 --- a/fastly/block_fastly_service_logging_scalyr_test.go +++ b/fastly/block_fastly_service_logging_scalyr_test.go @@ -28,6 +28,7 @@ func TestResourceFastlyFlattenScalyr(t *testing.T) { Format: gofastly.ToPointer(`%a %l %u %t %m %U%q %H %>s %b %T`), FormatVersion: gofastly.ToPointer(2), Placement: gofastly.ToPointer("none"), + ProjectID: gofastly.ToPointer("example-project"), }, }, local: []map[string]any{ @@ -39,6 +40,7 @@ func TestResourceFastlyFlattenScalyr(t *testing.T) { "format": `%a %l %u %t %m %U%q %H %>s %b %T`, "placement": "none", "format_version": 2, + "project_id": "example-project", }, }, }, @@ -77,6 +79,7 @@ func TestAccFastlyServiceVCL_scalyrlogging_basic(t *testing.T) { ResponseCondition: gofastly.ToPointer("response_condition_test"), ServiceVersion: gofastly.ToPointer(1), Token: gofastly.ToPointer("newtkn"), + ProjectID: gofastly.ToPointer("example-project"), } log2 := gofastly.Scalyr{ @@ -307,6 +310,7 @@ resource "fastly_service_vcl" "foo" { format_version = 2 response_condition = "response_condition_test" placement = "waf_debug" + project_id = "example-project" } logging_scalyr {