aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2023-09-25 00:06:41 +0200
committerJulien Dessaux2023-09-25 00:13:49 +0200
commit68326c685fb6257220845195fd9cb5cbb3907f06 (patch)
tree93ffe1bbf10371e95fd46d02b3b5e531001f4622
parentFixed various documentation entries (diff)
downloadterraform-provider-eventline-68326c685fb6257220845195fd9cb5cbb3907f06.tar.gz
terraform-provider-eventline-68326c685fb6257220845195fd9cb5cbb3907f06.tar.bz2
terraform-provider-eventline-68326c685fb6257220845195fd9cb5cbb3907f06.zip
Fixed identity resource RawData idempotency
-rw-r--r--CHANGELOG.md4
-rw-r--r--docs/resources/identity.md4
-rw-r--r--examples/resources/eventline_identity/resource.tf4
-rw-r--r--internal/provider/identity_resource.go9
-rw-r--r--internal/provider/utils.go17
5 files changed, 33 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 329063a..72c4301 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 0.1.1 - 2023-09-25
+### Features
+* Fixed identity resource RawData idempotency
+
## 0.1.0 - 2023-09-24
### Features
* Add identity resource
diff --git a/docs/resources/identity.md b/docs/resources/identity.md
index 9cfb965..664a2a4 100644
--- a/docs/resources/identity.md
+++ b/docs/resources/identity.md
@@ -19,10 +19,10 @@ data "eventline_project" "main" {
resource "eventline_identity" "example" {
name = "example"
- project_id = data.project.main.id
+ project_id = data.eventline_project.main.id
connector = "eventline"
- data = "{\n \"key\": \"test\"\n }"
+ data = jsonencode({ "key" = "test" })
type = "api_key"
}
```
diff --git a/examples/resources/eventline_identity/resource.tf b/examples/resources/eventline_identity/resource.tf
index 3ed68d0..436be20 100644
--- a/examples/resources/eventline_identity/resource.tf
+++ b/examples/resources/eventline_identity/resource.tf
@@ -4,9 +4,9 @@ data "eventline_project" "main" {
resource "eventline_identity" "example" {
name = "example"
- project_id = data.project.main.id
+ project_id = data.eventline_project.main.id
connector = "eventline"
- data = "{\n \"key\": \"test\"\n }"
+ data = jsonencode({ "key" = "test" })
type = "api_key"
}
diff --git a/internal/provider/identity_resource.go b/internal/provider/identity_resource.go
index 8804f54..4df4219 100644
--- a/internal/provider/identity_resource.go
+++ b/internal/provider/identity_resource.go
@@ -143,7 +143,14 @@ func (r *IdentityResource) Read(ctx context.Context, req resource.ReadRequest, r
data.Connector = types.StringValue(identity.Connector)
data.Id = types.StringValue(identity.Id.String())
data.Name = types.StringValue(identity.Name)
- data.RawData = types.StringValue(string(identity.RawData))
+ rawDataEquals, err := JSONRawDataEqual(identity.RawData, json.RawMessage(data.RawData.ValueString()))
+ if err != nil {
+ resp.Diagnostics.AddError("JSONRawDataequal", fmt.Sprintf("Unable to compare identities RawData, got error: %s", err))
+ return
+ }
+ if !rawDataEquals {
+ data.RawData = types.StringValue(string(identity.RawData))
+ }
data.Status = types.StringValue(string(identity.Status))
data.Type = types.StringValue(identity.Type)
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
diff --git a/internal/provider/utils.go b/internal/provider/utils.go
new file mode 100644
index 0000000..3b1b665
--- /dev/null
+++ b/internal/provider/utils.go
@@ -0,0 +1,17 @@
+package provider
+
+import (
+ "encoding/json"
+ "reflect"
+)
+
+func JSONRawDataEqual(a, b json.RawMessage) (bool, error) {
+ var j, j2 interface{}
+ if err := json.Unmarshal([]byte(a), &j); err != nil {
+ return false, err
+ }
+ if err := json.Unmarshal([]byte(b), &j2); err != nil {
+ return false, err
+ }
+ return reflect.DeepEqual(j2, j), nil
+}