-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13529 from Tensho/d-workspaces-directory
New Data Source: aws_workspaces_directory
- Loading branch information
Showing
7 changed files
with
268 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/service/workspaces" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema" | ||
|
||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/keyvaluetags" | ||
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/workspaces/waiter" | ||
) | ||
|
||
func dataSourceAwsWorkspacesDirectory() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsWorkspacesDirectoryRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"directory_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"self_service_permissions": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"change_compute_type": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"increase_volume_size": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"rebuild_workspace": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"restart_workspace": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
"switch_running_mode": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"subnet_ids": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"workspace_security_group_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"iam_role_id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"registration_code": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"directory_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"directory_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"customer_user_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"alias": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"ip_group_ids": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"dns_ip_addresses": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
}, | ||
"tags": tagsSchema(), | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsWorkspacesDirectoryRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).workspacesconn | ||
ignoreTagsConfig := meta.(*AWSClient).IgnoreTagsConfig | ||
|
||
directoryID := d.Get("directory_id").(string) | ||
|
||
rawOutput, state, err := waiter.DirectoryState(conn, directoryID)() | ||
if err != nil { | ||
return fmt.Errorf("error getting WorkSpaces Directory (%s): %s", directoryID, err) | ||
} | ||
if state == workspaces.WorkspaceDirectoryStateDeregistered { | ||
return fmt.Errorf("WorkSpaces directory %s was not found", directoryID) | ||
} | ||
|
||
d.SetId(directoryID) | ||
|
||
directory := rawOutput.(*workspaces.WorkspaceDirectory) | ||
d.Set("directory_id", directory.DirectoryId) | ||
d.Set("workspace_security_group_id", directory.WorkspaceSecurityGroupId) | ||
d.Set("iam_role_id", directory.IamRoleId) | ||
d.Set("registration_code", directory.RegistrationCode) | ||
d.Set("directory_name", directory.DirectoryName) | ||
d.Set("directory_type", directory.DirectoryType) | ||
d.Set("alias", directory.Alias) | ||
|
||
if err := d.Set("subnet_ids", flattenStringSet(directory.SubnetIds)); err != nil { | ||
return fmt.Errorf("error setting subnet_ids: %s", err) | ||
} | ||
|
||
if err := d.Set("self_service_permissions", flattenSelfServicePermissions(directory.SelfservicePermissions)); err != nil { | ||
return fmt.Errorf("error setting self_service_permissions: %s", err) | ||
} | ||
|
||
if err := d.Set("ip_group_ids", flattenStringSet(directory.IpGroupIds)); err != nil { | ||
return fmt.Errorf("error setting ip_group_ids: %s", err) | ||
} | ||
|
||
if err := d.Set("dns_ip_addresses", flattenStringSet(directory.DnsIpAddresses)); err != nil { | ||
return fmt.Errorf("error setting dns_ip_addresses: %s", err) | ||
} | ||
|
||
tags, err := keyvaluetags.WorkspacesListTags(conn, d.Id()) | ||
if err != nil { | ||
return fmt.Errorf("error listing tags: %s", err) | ||
} | ||
if err := d.Set("tags", tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
return fmt.Errorf("error setting tags: %s", err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsWorkspacesDirectory_basic(t *testing.T) { | ||
rName := acctest.RandString(8) | ||
|
||
resourceName := "aws_workspaces_directory.test" | ||
dataSourceName := "data.aws_workspaces_directory.test" | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t); testAccPreCheckHasIAMRole(t, "workspaces_DefaultRole") }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccDataSourceAwsWorkspacesDirectoryConfig(rName), | ||
Check: resource.ComposeAggregateTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(dataSourceName, "subnet_ids.#", resourceName, "subnet_ids.#"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "self_service_permissions.#", resourceName, "self_service_permissions.#"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "self_service_permissions.0.change_compute_type", resourceName, "self_service_permissions.0.change_compute_type"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "self_service_permissions.0.increase_volume_size", resourceName, "self_service_permissions.0.increase_volume_size"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "self_service_permissions.0.rebuild_workspace", resourceName, "self_service_permissions.0.rebuild_workspace"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "self_service_permissions.0.restart_workspace", resourceName, "self_service_permissions.0.restart_workspace"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "self_service_permissions.0.switch_running_mode", resourceName, "self_service_permissions.0.switch_running_mode"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "dns_ip_addresses.#", resourceName, "dns_ip_addresses.#"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "directory_type", resourceName, "directory_type"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "directory_name", resourceName, "directory_name"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "alias", resourceName, "alias"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "directory_id", resourceName, "directory_id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "iam_role_id", resourceName, "iam_role_id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_security_group_id", resourceName, "workspace_security_group_id"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "registration_code", resourceName, "registration_code"), | ||
resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccDataSourceAwsWorkspacesDirectoryConfig(rName string) string { | ||
return testAccAwsWorkspacesDirectoryConfig_Prerequisites(rName) + fmt.Sprintf(` | ||
resource "aws_workspaces_directory" "test" { | ||
directory_id = "${aws_directory_service_directory.main.id}" | ||
self_service_permissions { | ||
change_compute_type = false | ||
increase_volume_size = true | ||
rebuild_workspace = true | ||
restart_workspace = false | ||
switch_running_mode = true | ||
} | ||
} | ||
data "aws_workspaces_directory" "test" { | ||
directory_id = "${aws_workspaces_directory.test.id}" | ||
} | ||
data "aws_iam_role" "workspaces-default" { | ||
name = "workspaces_DefaultRole" | ||
} | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
subcategory: "WorkSpaces" | ||
layout: "aws" | ||
page_title: "AWS: aws_workspaces_directory" | ||
description: |- | ||
Retrieve information about an AWS WorkSpaces directory. | ||
--- | ||
|
||
# Data Source: aws_workspaces_directory | ||
|
||
Retrieve information about an AWS WorkSpaces directory. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_workspaces_directory" "example" { | ||
directory_id = "d-9067783251" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `directory_id` - (Required) The directory identifier for registration in WorkSpaces service. | ||
|
||
## Attributes Reference | ||
|
||
* `id` - The WorkSpaces directory identifier. | ||
* `subnet_ids` - The identifiers of the subnets where the directory resides. | ||
* `tags` – A map of tags assigned to the WorkSpaces directory. | ||
* `workspace_security_group_id` - The identifier of the security group that is assigned to new WorkSpaces. | ||
* `iam_role_id` - The identifier of the IAM role. This is the role that allows Amazon WorkSpaces to make calls to other services, such as Amazon EC2, on your behalf. | ||
* `registration_code` - The registration code for the directory. This is the code that users enter in their Amazon WorkSpaces client application to connect to the directory. | ||
* `directory_name` - The name of the directory. | ||
* `directory_type` - The directory type. | ||
* `customer_user_name` - The user name for the service account. | ||
* `alias` - The directory alias. | ||
* `ip_group_ids` - The identifiers of the IP access control groups associated with the directory. | ||
* `dns_ip_addresses` - The IP addresses of the DNS servers for the directory. | ||
* `self_service_permissions` – The permissions to enable or disable self-service capabilities. | ||
* `change_compute_type` – Whether WorkSpaces directory users can change the compute type (bundle) for their workspace. | ||
* `increase_volume_size` – Whether WorkSpaces directory users can increase the volume size of the drives on their workspace. | ||
* `rebuild_workspace` – Whether WorkSpaces directory users can rebuild the operating system of a workspace to its original state. | ||
* `restart_workspace` – Whether WorkSpaces directory users can restart their workspace. | ||
* `switch_running_mode` – Whether WorkSpaces directory users can switch the running mode of their workspace. |