Skip to content

Commit

Permalink
feat(scalyr): add project_id
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Mar 15, 2024
1 parent 5653c35 commit 6fc6df8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
15 changes: 15 additions & 0 deletions fastly/block_fastly_service_logging_scalyr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions fastly/block_fastly_service_logging_scalyr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
},
},
},
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6fc6df8

Please sign in to comment.