Skip to content

Commit f9a775d

Browse files
authored
fix: Sets org_id on import of mongodbatlas_organization resource (#3513)
* test checks org_id on import * changelog * set org_id on read
1 parent c36522d commit f9a775d

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

.changelog/3513.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
resource/mongodbatlas_organization: Sets org_id on import
3+
```

internal/service/organization/resource_organization.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@ func resourceCreate(ctx context.Context, d *schema.ResourceData, meta any) diag.
139139
d.SetId("")
140140
return diag.FromErr(fmt.Errorf("an error occurred when updating Organization settings: %s", err))
141141
}
142-
if err := d.Set("org_id", orgID); err != nil {
143-
return diag.FromErr(fmt.Errorf("error setting `org_id`: %s", err))
144-
}
145142
d.SetId(conversion.EncodeStateID(map[string]string{
146143
"org_id": orgID,
147144
}))
@@ -169,6 +166,9 @@ func resourceRead(ctx context.Context, d *schema.ResourceData, meta any) diag.Di
169166
if err := d.Set("skip_default_alerts_settings", organization.SkipDefaultAlertsSettings); err != nil {
170167
return diag.Errorf("error setting `skip_default_alerts_settings` for organization (%s): %s", orgID, err)
171168
}
169+
if err := d.Set("org_id", orgID); err != nil {
170+
return diag.FromErr(fmt.Errorf("error setting `org_id`: %s", err))
171+
}
172172

173173
settings, _, err := conn.OrganizationsApi.GetOrganizationSettings(ctx, orgID).Execute()
174174
if err != nil {

internal/service/organization/resource_organization_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,11 @@ func TestAccConfigRSOrganization_import(t *testing.T) {
220220
Config: configImportSet(orgID, orgName), // Use import so a new organization is not created, the resource must exist in a step before import state is verified.
221221
},
222222
{
223-
ResourceName: resourceName,
224-
ImportStateId: orgID,
225-
ImportState: true, // Do the import check.
226-
ImportStateVerify: true,
223+
ResourceName: resourceName,
224+
ImportStateId: orgID,
225+
ImportState: true, // Do the import check.
226+
ImportStateVerify: true,
227+
ImportStateVerifyIdentifierAttribute: "org_id",
227228
},
228229
{
229230
// Use removed block so the organization is not deleted.

0 commit comments

Comments
 (0)