Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add edition parameter for MS AD #3421

Merged
merged 9 commits into from
Feb 20, 2018
23 changes: 23 additions & 0 deletions aws/resource_aws_directory_service_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ func resourceAwsDirectoryServiceDirectory() *schema.Resource {
return
},
},
"edition": {
Type: schema.TypeString,
Optional: true,
Default: "Enterprise",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Can you please use the SDK provided constant here? directoryservice.DirectoryEditionEnterprise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be simplified to the below 😄

ValidateFunc: validation.StringInSlice([]string{
	directoryservice.DirectoryEditionEnterprise,
	directoryservice.DirectoryEditionStandard,
}, false),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked around the code to find something similar, but ended up stealing the validation from another attribute. This is much better. Thanks for that

validTypes := []string{"Enterprise", "Standard"}
value := v.(string)
for _, validType := range validTypes {
if validType == value {
return
}
}
es = append(es, fmt.Errorf("%q must be one of %q", k, validTypes))
return
},
},
},
}
}
Expand Down Expand Up @@ -295,6 +312,9 @@ func createActiveDirectoryService(dsconn *directoryservice.DirectoryService, d *
if v, ok := d.GetOk("short_name"); ok {
input.ShortName = aws.String(v.(string))
}
if v, ok := d.GetOk("edition"); ok {
input.Edition = aws.String(v.(string))
}

input.VpcSettings, err = buildVpcSettings(d)
if err != nil {
Expand Down Expand Up @@ -445,6 +465,9 @@ func resourceAwsDirectoryServiceDirectoryRead(d *schema.ResourceData, meta inter
if dir.Size != nil {
d.Set("size", *dir.Size)
}
if dir.Edition != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally this check wouldn't be necessary, however I think because we the SDK handles both SimpleAD and MicrosoftAD directory types that in fact we do want to keep this nil check in here. 👍

d.Set("edition", *dir.Edition)
}
d.Set("type", *dir.Type)
d.Set("vpc_settings", flattenDSVpcSettings(dir.VpcSettings))
d.Set("connect_settings", flattenDSConnectSettings(dir.DnsIpAddrs, dir.ConnectSettings))
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/directory_service_directory.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ The following arguments are supported:
* `alias` - (Optional) The alias for the directory (must be unique amongst all aliases in AWS). Required for `enable_sso`.
* `description` - (Optional) A textual description for the directory.
* `short_name` - (Optional) The short name of the directory, such as `CORP`.
* `edition` - (Optional) The AWS Directory Service for Microsoft Active Directory edition type (`Standard` or `Enterprise`). Defaults to `Enterprise`.
* `enable_sso` - (Optional) Whether to enable single-sign on for the directory. Requires `alias`. Defaults to `false`.
* `type` (Optional) - The directory type (`SimpleAD` or `MicrosoftAD` are accepted values). Defaults to `SimpleAD`.
* `tags` - (Optional) A mapping of tags to assign to the resource.
Expand Down