diff --git a/CHANGELOG.md b/CHANGELOG.md index f0edc20..5e9878b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [0.6.1] - 2024-06-11 + +### Fixed + +- rule script content udpate + ## [0.6.0] - 2024-06-11 ### Added diff --git a/VERSION b/VERSION index a918a2a..ee6cdce 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.6.0 +0.6.1 diff --git a/examples/resources/impart_monitor/resource.tf b/examples/resources/impart_monitor/resource.tf index 5bac7a2..e6bf0e1 100644 --- a/examples/resources/impart_monitor/resource.tf +++ b/examples/resources/impart_monitor/resource.tf @@ -2,7 +2,7 @@ resource "impart_monitor" "test_event" { name = "terraform_event_monitor" description = "test event monitor" - notification_template_ids = [resource.impart_notification_template.test.id] + notification_template_ids = [""] conditions = [ { threshold = 1, @@ -23,7 +23,7 @@ resource "impart_monitor" "test_event" { resource "impart_monitor" "test_metric" { name = "terraform_event_monitor" description = "test event monitor" - notification_template_ids = [resource.impart_notification_template.test.id] + notification_template_ids = [""] conditions = [ { threshold = 1, diff --git a/internal/provider/api_binding_resource_test.go b/internal/provider/api_binding_resource_test.go index 55f49a1..86881a7 100644 --- a/internal/provider/api_binding_resource_test.go +++ b/internal/provider/api_binding_resource_test.go @@ -7,8 +7,6 @@ import ( ) func TestAccApiBindingResource(t *testing.T) { - // Skipping for now until we find out why api bindings are not being generated correctly during tests - t.Skip() resource.Test(t, resource.TestCase{ ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, PreCheck: func() { testAccPreCheck(t) }, @@ -42,7 +40,7 @@ resource "impart_api_binding" "test" { }, // ImportState testing { - ResourceName: "impart_spec.test", + ResourceName: "impart_api_binding.test", ImportState: true, ImportStateVerify: true, }, @@ -64,9 +62,9 @@ resource "impart_api_binding" "test" { `, Check: resource.ComposeAggregateTestCheckFunc( resource.TestCheckResourceAttr("impart_api_binding.test", "name", "terraform_test_updated"), - resource.TestCheckResourceAttr("impart_api_binding.test", "port", "444"), - resource.TestCheckResourceAttr("impart_api_binding.test", "hostname", "example.net"), - resource.TestCheckResourceAttr("impart_api_binding.test", "base_path", "/"), + resource.TestCheckResourceAttr("impart_api_binding.test", "port", "445"), + resource.TestCheckResourceAttr("impart_api_binding.test", "hostname", "example2.net"), + resource.TestCheckResourceAttr("impart_api_binding.test", "base_path", "/example"), // Verify dynamic values have any value set in the state. resource.TestCheckResourceAttrSet("impart_api_binding.test", "spec_id"), resource.TestCheckResourceAttrSet("impart_api_binding.test", "id"), diff --git a/internal/provider/rule_script_resource.go b/internal/provider/rule_script_resource.go index 93deebc..253f888 100644 --- a/internal/provider/rule_script_resource.go +++ b/internal/provider/rule_script_resource.go @@ -295,15 +295,21 @@ func (r *ruleScriptResource) Update(ctx context.Context, req resource.UpdateRequ return } - rule, err := os.ReadFile(plan.SourceFile.ValueString()) - if err != nil { - resp.Diagnostics.AddError( - "Unable to read the rule script source file", - err.Error(), - ) - return + var ruleBytes []byte + if !plan.SourceFile.IsNull() { + bytes, err := os.ReadFile(plan.SourceFile.ValueString()) + if err != nil { + resp.Diagnostics.AddError( + "Unable to read the rule script source file", + err.Error(), + ) + return + } + ruleBytes = bytes + } else { + ruleBytes = []byte(plan.Content.ValueString()) } - ruleb64 := base64.StdEncoding.EncodeToString(rule) + ruleb64 := base64.StdEncoding.EncodeToString(ruleBytes) rulesScriptPostBody := openapiclient.RulesScriptPostBody{ Name: plan.Name.ValueString(), @@ -348,6 +354,19 @@ func (r *ruleScriptResource) Update(ctx context.Context, req resource.UpdateRequ state.Description = types.StringValue(ruleResponse.Description) } + // track only if content was set + if !plan.Content.IsNull() { + bytes, err := base64.StdEncoding.DecodeString(ruleResponse.Src) + if err != nil { + resp.Diagnostics.AddError( + "Unable to base64 decode the rule script", + err.Error(), + ) + } + + state.Content = types.StringValue(string(bytes)) + } + // Set refreshed state diags = resp.State.Set(ctx, state) resp.Diagnostics.Append(diags...)