Skip to content

Commit e1a8880

Browse files
Fix FromReadBindings (#96)
1 parent 1af2b1c commit e1a8880

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

example/cloudconnection/main.tf

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ data "plural_user" "john_doe" {
4343
###############################################################################
4444

4545
# Group that will get read access to the cloud connection
46-
resource "plural_group" "cloud_admins" {
47-
name = "cloud-admins"
48-
description = "Group with access to cloud connections"
46+
47+
data "plural_group" "existing-cloud_admins" {
48+
name = "existing-cloud-admins"
4949
}
5050

5151
# Cloud-connection resource (AWS example)
@@ -63,16 +63,10 @@ resource "plural_cloud_connection" "aws" {
6363

6464
read_bindings = [
6565
{
66-
id = "1122"
67-
user_id = data.plural_user.john.id
68-
},
69-
{
70-
id = "2233"
71-
group_id = plural_group.cloud_admins.id
66+
user_id = data.plural_user.john_doe.id
7267
},
7368
{
74-
id = "4444"
75-
group_id = plural_group.cloud_admins.id
69+
group_id = data.plural_group.existing-cloud_admins.id
7670
}
7771
]
7872
}
@@ -93,6 +87,6 @@ output "cloud_connection_details" {
9387
}
9488

9589
output "group_id" {
96-
value = plural_group.cloud_admins.id
90+
value = data.plural_group.existing-cloud_admins.id
9791
description = "ID of the created group"
9892
}

internal/common/bindings.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ func bindingsFrom(bindings []*console.PolicyBindingFragment, config types.Set, c
9090
return setValue
9191
}
9292

93-
func BindingsFromReadOnly(bindings []*console.PolicyBindingFragment, ctx context.Context, d *diag.Diagnostics) types.Set {
93+
func BindingsFromReadOnly(bindings []*console.PolicyBindingFragment, planned types.Set, ctx context.Context, d *diag.Diagnostics) types.Set {
9494
if len(bindings) == 0 {
95-
return types.SetNull(types.ObjectType{AttrTypes: PolicyBindingAttrTypes})
95+
// Rewriting planned to state to avoid inconsistent result errors.
96+
// This could happen, for example, when sending "nil" to API and "[]" is returned as a result.
97+
return planned
9698
}
9799

98100
values := make([]attr.Value, len(bindings))

internal/model/cloud_connection.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,5 +100,4 @@ func (c *CloudConnection) From(cc *console.CloudConnectionFragment, ctx context.
100100
c.Id = types.StringValue(cc.ID)
101101
c.Name = types.StringValue(cc.Name)
102102
c.CloudProvider = types.StringValue(string(cc.Provider))
103-
c.ReadBindings = common.BindingsFromReadOnly(cc.ReadBindings, ctx, d)
104103
}

internal/resource/cloud_connection.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func (r *CloudConnectionResource) Schema(_ context.Context, _ resource.SchemaReq
8686
"id": schema.StringAttribute{Optional: true},
8787
},
8888
},
89-
PlanModifiers: []planmodifier.Set{setplanmodifier.UseStateForUnknown()},
89+
PlanModifiers: []planmodifier.Set{setplanmodifier.RequiresReplace()},
9090
},
9191
},
9292
}
@@ -109,7 +109,6 @@ func (r *CloudConnectionResource) gcpCloudConnectionAttrTypes() map[string]attr.
109109

110110
func (r *CloudConnectionResource) azureCloudConnectionAttrTypes() map[string]attr.Type {
111111
return map[string]attr.Type{
112-
113112
"subscription_id": types.StringType,
114113
"tenant_id": types.StringType,
115114
"client_id": types.StringType,

0 commit comments

Comments
 (0)