Fixed identity resource RawData idempotency
This commit is contained in:
parent
6302c173a8
commit
68326c685f
5 changed files with 33 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
```
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
|
@ -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)...)
|
||||
|
|
17
internal/provider/utils.go
Normal file
17
internal/provider/utils.go
Normal file
|
@ -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
|
||||
}
|
Loading…
Add table
Reference in a new issue