Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added parameter scopes in datasource of database user and update docs
Browse files Browse the repository at this point in the history
coderGo93 committed Sep 4, 2020
1 parent 49a914d commit 8ebd846
Showing 6 changed files with 57 additions and 0 deletions.
20 changes: 20 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_database_user.go
Original file line number Diff line number Diff line change
@@ -77,6 +77,22 @@ func dataSourceMongoDBAtlasDatabaseUser() *schema.Resource {
},
},
},
"scopes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
}
}
@@ -136,6 +152,10 @@ func dataSourceMongoDBAtlasDatabaseUserRead(d *schema.ResourceData, meta interfa
return fmt.Errorf("error setting `labels` for database user (%s): %s", d.Id(), err)
}

if err := d.Set("scopes", flattenScopes(dbUser.Scopes)); err != nil {
return fmt.Errorf("error setting `scopes` for database user (%s): %s", d.Id(), err)
}

d.SetId(encodeStateID(map[string]string{
"project_id": projectID,
"username": username,
17 changes: 17 additions & 0 deletions mongodbatlas/data_source_mongodbatlas_database_users.go
Original file line number Diff line number Diff line change
@@ -81,6 +81,22 @@ func dataSourceMongoDBAtlasDatabaseUsers() *schema.Resource {
},
},
},
"scopes": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Computed: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
},
},
},
@@ -123,6 +139,7 @@ func flattenDBUsers(dbUsers []matlas.DatabaseUser) []map[string]interface{} {
"x509_type": dbUsers[i].X509Type,
"aws_iam_type": dbUsers[i].AWSIAMType,
"labels": flattenLabels(dbUsers[i].Labels),
"scopes": flattenScopes(dbUsers[i].Scopes),
}
}
}
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ func TestAccDataSourceMongoDBAtlasDatabaseUsers_basic(t *testing.T) {
resource.TestCheckResourceAttrSet(resourceName, "results.0.x509_type"),
resource.TestCheckResourceAttrSet(resourceName, "results.0.username"),
resource.TestCheckResourceAttrSet(resourceName, "results.0.roles.#"),
resource.TestCheckResourceAttrSet(resourceName, "results.0.scopes.#"),
),
},
},
3 changes: 3 additions & 0 deletions website/docs/d/database_user.html.markdown
Original file line number Diff line number Diff line change
@@ -63,6 +63,9 @@ In addition to all arguments above, the following attributes are exported:
* `roles` - List of user’s roles and the databases / collections on which the roles apply. A role allows the user to perform particular actions on the specified database. A role on the admin database can include privileges that apply to the other databases as well. See [Roles](#roles) below for more details.
* `x509_type` - X.509 method by which the provided username is authenticated.
* `aws_iam_type` - The new database user authenticates with AWS IAM credentials. Default is `NONE`, `USER` means user has AWS IAM user credentials, `ROLE` - means user has credentials associated with an AWS IAM role.
* `scopes` - Array of clusters and Atlas Data Lakes that this user has access to.
* `name` - Name of the cluster or Atlas Data Lake that the user has access to.
* `type` - Type of resource that the user has access to. Valid values are: `CLUSTER` and `DATA_LAKE`

### Roles

3 changes: 3 additions & 0 deletions website/docs/d/database_users.html.markdown
Original file line number Diff line number Diff line change
@@ -74,6 +74,9 @@ Possible values include:

* `x509_type` - X.509 method by which the provided username is authenticated.
* `aws_iam_type` - The new database user authenticates with AWS IAM credentials. Default is `NONE`, `USER` means user has AWS IAM user credentials, `ROLE` - means user has credentials associated with an AWS IAM role.
* `scopes` - Array of clusters and Atlas Data Lakes that this user has access to.
* `name` - Name of the cluster or Atlas Data Lake that the user has access to.
* `type` - Type of resource that the user has access to. Valid values are: `CLUSTER` and `DATA_LAKE`

### Roles

13 changes: 13 additions & 0 deletions website/docs/r/database_user.html.markdown
Original file line number Diff line number Diff line change
@@ -39,6 +39,11 @@ resource "mongodbatlas_database_user" "test" {
key = "My Key"
value = "My Value"
}
scopes {
name = "My cluster name"
type = "CLUSTER"
}
}
```

@@ -59,6 +64,11 @@ resource "mongodbatlas_database_user" "test" {
key = "%s"
value = "%s"
}
scopes {
name = "My cluster name"
type = "CLUSTER"
}
}
```

@@ -74,6 +84,9 @@ Accepted values include:
* `roles` - (Required) List of user’s roles and the databases / collections on which the roles apply. A role allows the user to perform particular actions on the specified database. A role on the admin database can include privileges that apply to the other databases as well. See [Roles](#roles) below for more details.
* `username` - (Required) Username for authenticating to MongoDB.
* `password` - (Required) User's initial password. A value is required to create the database user, however the argument but may be removed from your Terraform configuration after user creation without impacting the user, password or Terraform management. IMPORTANT --- Passwords may show up in Terraform related logs and it will be stored in the Terraform state file as plain-text. Password can be changed after creation using your preferred method, e.g. via the MongoDB Atlas UI, to ensure security. If you do change management of the password to outside of Terraform be sure to remove the argument from the Terraform configuration so it is not inadvertently updated to the original password.
* `scopes` - (Optional) Array of clusters and Atlas Data Lakes that this user has access to. If omitted, Atlas grants the user access to all the clusters and Atlas Data Lakes in the project by default.
* `name` - (Required) Name of the cluster or Atlas Data Lake that the user has access to.
* `type` - (Required) Type of resource that the user has access to. Valid values are: `CLUSTER` and `DATA_LAKE`

* `x509_type` - (Optional) X.509 method by which the provided username is authenticated. If no value is given, Atlas uses the default value of NONE. The accepted types are:
* `NONE` - The user does not use X.509 authentication.

0 comments on commit 8ebd846

Please sign in to comment.