Skip to content

Commit a280ddd

Browse files
authored
Fix Org Settings + Org LDAP destroy issues (#61)
Signed-off-by: abarreiro <abarreiro@vmware.com>
1 parent f67cc2a commit a280ddd

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

.changes/v1.0.0/26-features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
- **New Resource:** `vcfa_org_ldap` to manage LDAP settings of Organizations [GH-26, GH-28, GH-50]
2-
- **New Data Source:** `vcfa_org_ldap` to read LDAP settings of Organizations [GH-26, GH-28, GH-50]
1+
- **New Resource:** `vcfa_org_ldap` to manage LDAP settings of Organizations [GH-26, GH-28, GH-50, GH-61]
2+
- **New Data Source:** `vcfa_org_ldap` to read LDAP settings of Organizations [GH-26, GH-28, GH-50, GH-61]
33
- **New Resource:** `vcfa_provider_ldap` to manage global Provider LDAP settings [GH-28]
44
- **New Data Source:** `vcfa_provider_ldap` to read global Provider LDAP settings [GH-28]

.changes/v1.0.0/50-features.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
- **New Resource:** `vcfa_org_settings` to manage Organization general settings [GH-50]
2-
- **New Data Source:** `vcfa_org_settings` to read Organization general settings [GH-50]
1+
- **New Resource:** `vcfa_org_settings` to manage Organization general settings [GH-50, GH-61]
2+
- **New Data Source:** `vcfa_org_settings` to read Organization general settings [GH-50, GH-61]

vcfa/resource_vcfa_org_ldap.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,18 @@ func resourceVcfaOrgLdap() *schema.Resource {
242242
}
243243

244244
func resourceVcfaOrgLdapCreateOrUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}, origin string) diag.Diagnostics {
245+
// Lock the Organization to serialize create/update operation and prevent side effects like bricked Organizations when
246+
// vcfa_org_settings is updated at the same time
247+
orgId := d.Get("org_id").(string)
248+
vcfa.kvLock(orgId)
249+
defer vcfa.kvUnlock(orgId)
250+
245251
settings, err := fillOrgLdapSettings(d)
246252
if err != nil {
247253
return diag.Errorf("[Org LDAP %s] error collecting settings values: %s", origin, err)
248254
}
249255

250256
tmClient := meta.(ClientContainer).tmClient
251-
orgId := d.Get("org_id").(string)
252257
org, err := tmClient.GetTmOrgById(orgId)
253258
if err != nil {
254259
return diag.Errorf("[Org LDAP %s] error searching for Org %s: %s", origin, orgId, err)
@@ -350,8 +355,13 @@ func resourceVcfaOrgLdapUpdate(ctx context.Context, d *schema.ResourceData, meta
350355
}
351356

352357
func resourceVcfaOrgLdapDelete(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
353-
tmClient := meta.(ClientContainer).tmClient
358+
// Lock the Organization to serialize delete operation and prevent side effects like bricked Organizations when
359+
// vcfa_org_settings is deleted at the same time
354360
orgId := d.Get("org_id").(string)
361+
vcfa.kvLock(orgId)
362+
defer vcfa.kvUnlock(orgId)
363+
364+
tmClient := meta.(ClientContainer).tmClient
355365

356366
tmOrg, err := tmClient.GetTmOrgById(orgId)
357367
if err != nil {

vcfa/resource_vcfa_org_settings.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ func resourceVcfaOrgSettings() *schema.Resource {
4444
}
4545

4646
func resourceVcfaOrgSettingsCreateUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
47+
// Lock the Organization to serialize create/update operation and prevent side effects like bricked Organizations when
48+
// vcfa_org_ldap is updated at the same time
49+
orgId := d.Get("org_id").(string)
50+
vcfa.kvLock(orgId)
51+
defer vcfa.kvUnlock(orgId)
52+
4753
tmClient := meta.(ClientContainer).tmClient
4854

49-
org, err := tmClient.GetTmOrgById(d.Get("org_id").(string))
55+
org, err := tmClient.GetTmOrgById(orgId)
5056
if err != nil {
51-
return diag.Errorf("error retrieving %s: %s", labelVcfaOrg, err)
57+
return diag.Errorf("error retrieving %s '%s' : %s", labelVcfaOrg, orgId, err)
5258
}
5359

5460
d.SetId(org.TmOrg.ID)
@@ -95,10 +101,16 @@ func resourceVcfaOrgSettingsRead(ctx context.Context, d *schema.ResourceData, me
95101
}
96102

97103
func resourceVcfaOrgSettingsDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
104+
// Lock the Organization to serialize delete operation and prevent side effects like bricked Organizations when
105+
// vcfa_org_ldap is deleted at the same time
106+
orgId := d.Get("org_id").(string)
107+
vcfa.kvLock(orgId)
108+
defer vcfa.kvUnlock(orgId)
109+
98110
tmClient := meta.(ClientContainer).tmClient
99-
org, err := tmClient.GetTmOrgById(d.Get("org_id").(string))
111+
org, err := tmClient.GetTmOrgById(orgId)
100112
if err != nil {
101-
return diag.Errorf("error retrieving %s: %s", labelVcfaOrg, err)
113+
return diag.Errorf("error retrieving %s '%s': %s", labelVcfaOrg, orgId, err)
102114
}
103115

104116
// reset settings

0 commit comments

Comments
 (0)