Skip to content

Commit 58ba07a

Browse files
doc: Clarifies lack of support for import statement in organization resource (#1806)
* docs: fix organization resource attributes * docs: Clarifies lack of support for import statement in organization resource * Update internal/service/organization/resource_organization.go Co-authored-by: Andrea Angiolillo <[email protected]> --------- Co-authored-by: Andrea Angiolillo <[email protected]>
1 parent d9b3092 commit 58ba07a

File tree

3 files changed

+5
-79
lines changed

3 files changed

+5
-79
lines changed

internal/service/organization/resource_organization.go

+1-27
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ func Resource() *schema.Resource {
2020
ReadContext: resourceMongoDBAtlasOrganizationRead,
2121
UpdateContext: resourceMongoDBAtlasOrganizationUpdate,
2222
DeleteContext: resourceMongoDBAtlasOrganizationDelete,
23-
Importer: &schema.ResourceImporter{
24-
StateContext: resourceMongoDBAtlasOrganizationImportState,
25-
},
23+
Importer: nil, // import is not supported. See CLOUDP-215155
2624
Schema: map[string]*schema.Schema{
2725
"org_owner_id": {
2826
Type: schema.TypeString,
@@ -168,30 +166,6 @@ func resourceMongoDBAtlasOrganizationDelete(ctx context.Context, d *schema.Resou
168166
return nil
169167
}
170168

171-
func resourceMongoDBAtlasOrganizationImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
172-
conn := meta.(*config.MongoDBClient).Atlas
173-
orgID := d.Id()
174-
175-
r, _, err := conn.Organizations.Get(ctx, orgID)
176-
if err != nil {
177-
return nil, fmt.Errorf("couldn't import organization %s , error: %s", orgID, err)
178-
}
179-
180-
if err := d.Set("name", r.Name); err != nil {
181-
return nil, fmt.Errorf("error setting `name`: %s", err)
182-
}
183-
184-
if err := d.Set("org_id", r.ID); err != nil {
185-
return nil, fmt.Errorf("error setting `org_id`: %s", err)
186-
}
187-
188-
d.SetId(conversion.EncodeStateID(map[string]string{
189-
"org_id": orgID,
190-
}))
191-
192-
return []*schema.ResourceData{d}, nil
193-
}
194-
195169
func newCreateOrganizationRequest(d *schema.ResourceData) *matlas.CreateOrganizationRequest {
196170
createRequest := &matlas.CreateOrganizationRequest{
197171
Name: d.Get("name").(string),

internal/service/organization/resource_organization_test.go

-39
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,6 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) {
4343
})
4444
}
4545

46-
func TestAccConfigRSOrganization_importBasic(t *testing.T) {
47-
acc.SkipTestForCI(t)
48-
var (
49-
resourceName = "mongodbatlas_organization.test"
50-
orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID")
51-
name = fmt.Sprintf("test-acc-import-organization-%s", acctest.RandString(5))
52-
description = "test Key for Acceptance tests"
53-
roleName = "ORG_OWNER"
54-
)
55-
56-
resource.Test(t, resource.TestCase{
57-
PreCheck: func() { acc.PreCheck(t) },
58-
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
59-
CheckDestroy: testAccCheckMongoDBAtlasOrganizationDestroy,
60-
Steps: []resource.TestStep{
61-
{
62-
Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, roleName),
63-
},
64-
{
65-
ResourceName: resourceName,
66-
ImportStateIdFunc: testAccCheckMongoDBAtlasOrganizationImportStateIDFunc(resourceName),
67-
ImportState: true,
68-
ImportStateVerify: false,
69-
},
70-
},
71-
})
72-
}
73-
7446
func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.TestCheckFunc {
7547
return func(s *terraform.State) error {
7648
conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas
@@ -126,17 +98,6 @@ func testAccCheckMongoDBAtlasOrganizationDestroy(s *terraform.State) error {
12698
return nil
12799
}
128100

129-
func testAccCheckMongoDBAtlasOrganizationImportStateIDFunc(resourceName string) resource.ImportStateIdFunc {
130-
return func(s *terraform.State) (string, error) {
131-
rs, ok := s.RootModule().Resources[resourceName]
132-
if !ok {
133-
return "", fmt.Errorf("not found: %s", resourceName)
134-
}
135-
136-
return rs.Primary.Attributes["org_id"], nil
137-
}
138-
}
139-
140101
func testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, roleNames string) string {
141102
return fmt.Sprintf(`
142103
resource "mongodbatlas_organization" "test" {

website/docs/r/organization.html.markdown

+4-13
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ description: |-
1212

1313
~> **IMPORTANT NOTE:** When you establish an Atlas organization using this resource, it automatically generates a set of initial public and private Programmatic API Keys. These key values are vital to store because you'll need to use them to grant access to the newly created Atlas organization.
1414

15+
~> **NOTE** Import command is currently not supported for this resource.
1516

1617
## Example Usage
1718

@@ -28,30 +29,20 @@ resource "mongodbatlas_organization" "test" {
2829

2930
* `name` - (Required) The name of the organization you want to create. (Cannot be changed via this Provider after creation.)
3031
* `org_owner_id` - (Required) Unique 24-hexadecimal digit string that identifies the Atlas user that you want to assign the Organization Owner role. This user must be a member of the same organization as the calling API key. This is only required when authenticating with Programmatic API Keys. [MongoDB Atlas Admin API - Get User By Username](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/MongoDB-Cloud-Users/operation/getUserByUsername)
31-
* `description` - Programmatic API Key description
32+
* `description` - (Required) Programmatic API Key description
3233

3334
~> **NOTE:** Creating an organization will return a new API Key pair that can be used to authenticate and manage the new organization with MongoDB Atlas Terraform modules/blueprints. You cannot use the newly created API key pair to manage the newly created organization in the same Terraform module/blueprint that the organization is created in.
3435

35-
3636
* `role_names` - (Required) List of Organization roles that the Programmatic API key needs to have. Ensure that you provide at least one role and ensure all roles are valid for the Organization. You must specify an array even if you are only associating a single role with the Programmatic API key. The [MongoDB Documentation](https://www.mongodb.com/docs/atlas/reference/user-roles/#organization-roles) describes the roles that you can assign to a Programmatic API key.
37-
38-
37+
* `federation_settings_id` - (Optional) Unique 24-hexadecimal digit string that identifies the federation to link the newly created organization to. If specified, the proposed Organization Owner of the new organization must have the Organization Owner role in an organization associated with the federation.
38+
3939
## Attributes Reference
4040

4141
In addition to all arguments above, the following attributes are exported:
4242

4343
* `org_id` - The organization id.
4444
* `public_key` - Public API key value set for the specified organization API key.
4545
* `private_key` - Redacted private key returned for this organization API key. This key displays unredacted when first created and is saved within the Terraform state file.
46-
* `isDeleted` - (computed) Flag that indicates whether this organization has been deleted.
47-
* `federation_settings_id` - (Optional) Unique 24-hexadecimal digit string that identifies the federation to link the newly created organization to. If specified, the proposed Organization Owner of the new organization must have the Organization Owner role in an organization associated with the federation.
4846

4947

50-
## Import
51-
52-
Organization must be imported using organization ID, e.g.
53-
54-
```
55-
$ terraform import mongodbatlas_organization.my_org 5d09d6a59ccf6445652a444a
56-
```
5748
For more information see: [MongoDB Atlas Admin API Organization](https://www.mongodb.com/docs/atlas/reference/api-resources-spec/#tag/Organizations/operation/createOrganization) Documentation for more information.

0 commit comments

Comments
 (0)