Skip to content

Commit

Permalink
doc: Clarifies lack of support for import statement in organization r…
Browse files Browse the repository at this point in the history
…esource (#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 <andrea.angiolillo@mongodb.com>

---------

Co-authored-by: Andrea Angiolillo <andrea.angiolillo@mongodb.com>
  • Loading branch information
AgustinBettati and andreaangiolillo committed Jan 5, 2024
1 parent d9b3092 commit 58ba07a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 79 deletions.
28 changes: 1 addition & 27 deletions internal/service/organization/resource_organization.go
Expand Up @@ -20,9 +20,7 @@ func Resource() *schema.Resource {
ReadContext: resourceMongoDBAtlasOrganizationRead,
UpdateContext: resourceMongoDBAtlasOrganizationUpdate,
DeleteContext: resourceMongoDBAtlasOrganizationDelete,
Importer: &schema.ResourceImporter{
StateContext: resourceMongoDBAtlasOrganizationImportState,
},
Importer: nil, // import is not supported. See CLOUDP-215155
Schema: map[string]*schema.Schema{
"org_owner_id": {
Type: schema.TypeString,
Expand Down Expand Up @@ -168,30 +166,6 @@ func resourceMongoDBAtlasOrganizationDelete(ctx context.Context, d *schema.Resou
return nil
}

func resourceMongoDBAtlasOrganizationImportState(ctx context.Context, d *schema.ResourceData, meta any) ([]*schema.ResourceData, error) {
conn := meta.(*config.MongoDBClient).Atlas
orgID := d.Id()

r, _, err := conn.Organizations.Get(ctx, orgID)
if err != nil {
return nil, fmt.Errorf("couldn't import organization %s , error: %s", orgID, err)
}

if err := d.Set("name", r.Name); err != nil {
return nil, fmt.Errorf("error setting `name`: %s", err)
}

if err := d.Set("org_id", r.ID); err != nil {
return nil, fmt.Errorf("error setting `org_id`: %s", err)
}

d.SetId(conversion.EncodeStateID(map[string]string{
"org_id": orgID,
}))

return []*schema.ResourceData{d}, nil
}

func newCreateOrganizationRequest(d *schema.ResourceData) *matlas.CreateOrganizationRequest {
createRequest := &matlas.CreateOrganizationRequest{
Name: d.Get("name").(string),
Expand Down
39 changes: 0 additions & 39 deletions internal/service/organization/resource_organization_test.go
Expand Up @@ -43,34 +43,6 @@ func TestAccConfigRSOrganization_Basic(t *testing.T) {
})
}

func TestAccConfigRSOrganization_importBasic(t *testing.T) {
acc.SkipTestForCI(t)
var (
resourceName = "mongodbatlas_organization.test"
orgOwnerID = os.Getenv("MONGODB_ATLAS_ORG_OWNER_ID")
name = fmt.Sprintf("test-acc-import-organization-%s", acctest.RandString(5))
description = "test Key for Acceptance tests"
roleName = "ORG_OWNER"
)

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.PreCheck(t) },
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
CheckDestroy: testAccCheckMongoDBAtlasOrganizationDestroy,
Steps: []resource.TestStep{
{
Config: testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, roleName),
},
{
ResourceName: resourceName,
ImportStateIdFunc: testAccCheckMongoDBAtlasOrganizationImportStateIDFunc(resourceName),
ImportState: true,
ImportStateVerify: false,
},
},
})
}

func testAccCheckMongoDBAtlasOrganizationExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
conn := acc.TestAccProviderSdkV2.Meta().(*config.MongoDBClient).Atlas
Expand Down Expand Up @@ -126,17 +98,6 @@ func testAccCheckMongoDBAtlasOrganizationDestroy(s *terraform.State) error {
return nil
}

func testAccCheckMongoDBAtlasOrganizationImportStateIDFunc(resourceName string) resource.ImportStateIdFunc {
return func(s *terraform.State) (string, error) {
rs, ok := s.RootModule().Resources[resourceName]
if !ok {
return "", fmt.Errorf("not found: %s", resourceName)
}

return rs.Primary.Attributes["org_id"], nil
}
}

func testAccMongoDBAtlasOrganizationConfigBasic(orgOwnerID, name, description, roleNames string) string {
return fmt.Sprintf(`
resource "mongodbatlas_organization" "test" {
Expand Down
17 changes: 4 additions & 13 deletions website/docs/r/organization.html.markdown
Expand Up @@ -12,6 +12,7 @@ description: |-

~> **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.

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

## Example Usage

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

* `name` - (Required) The name of the organization you want to create. (Cannot be changed via this Provider after creation.)
* `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)
* `description` - Programmatic API Key description
* `description` - (Required) Programmatic API Key description

~> **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.


* `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.
* `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.

## Attributes Reference

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

* `org_id` - The organization id.
* `public_key` - Public API key value set for the specified organization API key.
* `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.
* `isDeleted` - (computed) Flag that indicates whether this organization has been deleted.
* `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.


## Import

Organization must be imported using organization ID, e.g.

```
$ terraform import mongodbatlas_organization.my_org 5d09d6a59ccf6445652a444a
```
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 comments on commit 58ba07a

Please sign in to comment.