Skip to content

Commit

Permalink
INTMDB-160: Resetting an encryption at rest (#380)
Browse files Browse the repository at this point in the history
* fix: fixes error when it wans to re apply it re-create(destroy and create) instad of only changes

* refactor: added validation for parameters and rever back role id

Co-authored-by: Edgar López <[email protected]>
  • Loading branch information
coderGo93 and Edgar López authored Jan 15, 2021
1 parent aebb60c commit da751dc
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions mongodbatlas/resource_mongodbatlas_encryption_at_rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,47 @@ func resourceMongoDBAtlasEncryptionAtRest() *schema.Resource {
Schema: map[string]*schema.Schema{
"enabled": {
Type: schema.TypeBool,
Required: true,
Optional: true,
},
"access_key_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
Sensitive: true,
},
"secret_access_key": {
Type: schema.TypeString,
Required: true,
Optional: true,
Sensitive: true,
},
"customer_master_key_id": {
Type: schema.TypeString,
Required: true,
Optional: true,
Sensitive: true,
},
"region": {
Type: schema.TypeString,
Required: true,
Optional: true,
},
"role_id": {
Type: schema.TypeString,
Optional: true,
},
},
},
ValidateFunc: func(val interface{}, key string) (warns []string, errs []error) {
v := val.(map[string]interface{})

_, akOk := v["access_key_id"]
_, saOk := v["secret_access_key"]
_, rOk := v["role_id"]

if (akOk && saOk && rOk) || (akOk && rOk) || (saOk && rOk) {
errs = append(errs, fmt.Errorf("%q For credentials: `access_key_id` and `secret_access_key` are allowed but not `role_id`."+
" For roles: `access_key_id` and `secret_access_key` are not allowed but `role_id` is allowed", key))
}

return
},
},
"azure_key_vault": {
Type: schema.TypeMap,
Expand Down Expand Up @@ -170,10 +184,6 @@ func resourceMongoDBAtlasEncryptionAtRestRead(d *schema.ResourceData, meta inter
return fmt.Errorf(errorReadEncryptionAtRest, err)
}

if err := d.Set("project_id", resp.GroupID); err != nil {
return fmt.Errorf(errorAlertEncryptionAtRestSetting, "project_id", d.Id(), err)
}

if err := d.Set("aws_kms", flattenAWSKMS(&resp.AwsKms)); err != nil {
return fmt.Errorf(errorAlertEncryptionAtRestSetting, "aws_kms", d.Id(), err)
}
Expand Down Expand Up @@ -271,7 +281,6 @@ func flattenAWSKMS(m *matlas.AwsKms) map[string]interface{} {
return map[string]interface{}{
"enabled": cast.ToString(m.Enabled),
"access_key_id": m.AccessKeyID,
"secret_access_key": m.SecretAccessKey,
"customer_master_key_id": m.CustomerMasterKeyID,
"region": m.Region,
"role_id": m.RoleID,
Expand Down

0 comments on commit da751dc

Please sign in to comment.