Skip to content

Commit

Permalink
Merge pull request hashicorp#1732 from stack72/b-aws-ds-import-1709
Browse files Browse the repository at this point in the history
resource/aws_directory_service_directory: Support Import functionality
  • Loading branch information
tombuildsstuff authored Sep 25, 2017
2 parents 2367f4e + 376eb73 commit 2920d8b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
39 changes: 21 additions & 18 deletions aws/resource_aws_directory_service_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,113 +25,116 @@ func resourceAwsDirectoryServiceDirectory() *schema.Resource {
Read: resourceAwsDirectoryServiceDirectoryRead,
Update: resourceAwsDirectoryServiceDirectoryUpdate,
Delete: resourceAwsDirectoryServiceDirectoryDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"password": &schema.Schema{
"password": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Sensitive: true,
},
"size": &schema.Schema{
"size": {
Type: schema.TypeString,
Optional: true,
Default: "Large",
ForceNew: true,
},
"alias": &schema.Schema{
"alias": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"description": &schema.Schema{
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"short_name": &schema.Schema{
"short_name": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
"tags": tagsSchema(),
"vpc_settings": &schema.Schema{
"vpc_settings": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"subnet_ids": &schema.Schema{
"subnet_ids": {
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"vpc_id": &schema.Schema{
"vpc_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
},
"connect_settings": &schema.Schema{
"connect_settings": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"customer_username": &schema.Schema{
"customer_username": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"customer_dns_ips": &schema.Schema{
"customer_dns_ips": {
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"subnet_ids": &schema.Schema{
"subnet_ids": {
Type: schema.TypeSet,
Required: true,
ForceNew: true,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
},
"vpc_id": &schema.Schema{
"vpc_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
},
"enable_sso": &schema.Schema{
"enable_sso": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"access_url": &schema.Schema{
"access_url": {
Type: schema.TypeString,
Computed: true,
},
"dns_ip_addresses": &schema.Schema{
"dns_ip_addresses": {
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Set: schema.HashString,
Computed: true,
},
"type": &schema.Schema{
"type": {
Type: schema.TypeString,
Optional: true,
Default: "SimpleAD",
Expand Down
37 changes: 30 additions & 7 deletions aws/resource_aws_directory_service_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,36 @@ func TestDiffTagsDirectoryService(t *testing.T) {
}
}

func TestAccAWSDirectoryServiceDirectory_importBasic(t *testing.T) {
resourceName := "aws_directory_service_directory.bar"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDirectoryServiceDirectoryDestroy,
Steps: []resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryConfig,
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{
"password",
},
},
},
})
}

func TestAccAWSDirectoryServiceDirectory_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckDirectoryServiceDirectoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceDirectoryExists("aws_directory_service_directory.bar"),
Expand All @@ -87,7 +110,7 @@ func TestAccAWSDirectoryServiceDirectory_tags(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckDirectoryServiceDirectoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryTagsConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceDirectoryExists("aws_directory_service_directory.bar"),
Expand All @@ -104,7 +127,7 @@ func TestAccAWSDirectoryServiceDirectory_microsoft(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckDirectoryServiceDirectoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryConfig_microsoft,
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceDirectoryExists("aws_directory_service_directory.bar"),
Expand All @@ -120,7 +143,7 @@ func TestAccAWSDirectoryServiceDirectory_connector(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckDirectoryServiceDirectoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryConfig_connector,
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceDirectoryExists("aws_directory_service_directory.connector"),
Expand All @@ -136,7 +159,7 @@ func TestAccAWSDirectoryServiceDirectory_withAliasAndSso(t *testing.T) {
Providers: testAccProviders,
CheckDestroy: testAccCheckDirectoryServiceDirectoryDestroy,
Steps: []resource.TestStep{
resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryConfig_withAlias,
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceDirectoryExists("aws_directory_service_directory.bar_a"),
Expand All @@ -145,7 +168,7 @@ func TestAccAWSDirectoryServiceDirectory_withAliasAndSso(t *testing.T) {
testAccCheckServiceDirectorySso("aws_directory_service_directory.bar_a", false),
),
},
resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryConfig_withSso,
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceDirectoryExists("aws_directory_service_directory.bar_a"),
Expand All @@ -154,7 +177,7 @@ func TestAccAWSDirectoryServiceDirectory_withAliasAndSso(t *testing.T) {
testAccCheckServiceDirectorySso("aws_directory_service_directory.bar_a", true),
),
},
resource.TestStep{
{
Config: testAccDirectoryServiceDirectoryConfig_withSso_modified,
Check: resource.ComposeTestCheckFunc(
testAccCheckServiceDirectoryExists("aws_directory_service_directory.bar_a"),
Expand Down
9 changes: 9 additions & 0 deletions website/docs/r/directory_service_directory.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,12 @@ The following attributes are exported:
* `id` - The directory identifier.
* `access_url` - The access URL for the directory, such as `http://alias.awsapps.com`.
* `dns_ip_addresses` - A list of IP addresses of the DNS servers for the directory or connector.


## Import

DirectoryService directories can be imported using the directory `id`, e.g.

```
$ terraform import aws_directory_service_directory.sample d-926724cf57
```

0 comments on commit 2920d8b

Please sign in to comment.