Skip to content

Commit

Permalink
Update terraform provider
Browse files Browse the repository at this point in the history
  • Loading branch information
impart-security committed Jun 11, 2024
1 parent 09202d0 commit 4158b06
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.6.1] - 2024-06-11

### Fixed

- rule script content udpate

## [0.6.0] - 2024-06-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.6.1
4 changes: 2 additions & 2 deletions examples/resources/impart_monitor/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ["<notification_template_id>"]
conditions = [
{
threshold = 1,
Expand All @@ -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 = ["<notification_template_id>"]
conditions = [
{
threshold = 1,
Expand Down
10 changes: 4 additions & 6 deletions internal/provider/api_binding_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand Down Expand Up @@ -42,7 +40,7 @@ resource "impart_api_binding" "test" {
},
// ImportState testing
{
ResourceName: "impart_spec.test",
ResourceName: "impart_api_binding.test",
ImportState: true,
ImportStateVerify: true,
},
Expand All @@ -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"),
Expand Down
35 changes: 27 additions & 8 deletions internal/provider/rule_script_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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...)
Expand Down

0 comments on commit 4158b06

Please sign in to comment.