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 device_type_linux to workspace_access_properties #20462

Merged
merged 14 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changelog/20462.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
```release-note:enhancement
data-source/aws_workspaces_directory: Add `workspace_access_properties.device_type_linux` attribute
```

```release-note:enhancement
resource/aws_workspaces_directory: Add `workspace_access_properties.device_type_linux` argument
```
16 changes: 8 additions & 8 deletions aws/data_source_aws_workspaces_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceAwsWorkspaceBundle_basic(t *testing.T) {
func testAccDataSourceAwsWorkspaceBundle_basic(t *testing.T) {
dataSourceName := "data.aws_workspaces_bundle.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, workspaces.EndpointsID),
Providers: testAccProviders,
Expand All @@ -37,10 +37,10 @@ func TestAccDataSourceAwsWorkspaceBundle_basic(t *testing.T) {
})
}

func TestAccDataSourceAwsWorkspaceBundle_byOwnerName(t *testing.T) {
func testAccDataSourceAwsWorkspaceBundle_byOwnerName(t *testing.T) {
dataSourceName := "data.aws_workspaces_bundle.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, workspaces.EndpointsID),
Providers: testAccProviders,
Expand All @@ -64,8 +64,8 @@ func TestAccDataSourceAwsWorkspaceBundle_byOwnerName(t *testing.T) {
})
}

func TestAccDataSourceAwsWorkspaceBundle_bundleIDAndNameConflict(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
func testAccDataSourceAwsWorkspaceBundle_bundleIDAndNameConflict(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ErrorCheck: testAccErrorCheck(t, workspaces.EndpointsID),
Providers: testAccProviders,
Expand All @@ -78,11 +78,11 @@ func TestAccDataSourceAwsWorkspaceBundle_bundleIDAndNameConflict(t *testing.T) {
})
}

func TestAccDataSourceAwsWorkspaceBundle_privateOwner(t *testing.T) {
func testAccDataSourceAwsWorkspaceBundle_privateOwner(t *testing.T) {
dataSourceName := "data.aws_workspaces_bundle.test"
bundleName := os.Getenv("AWS_WORKSPACES_BUNDLE_NAME")

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccWorkspacesBundlePreCheck(t)
Expand Down
4 changes: 4 additions & 0 deletions aws/data_source_aws_workspaces_directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func dataSourceAwsWorkspacesDirectory() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"device_type_linux": {
Type: schema.TypeString,
Computed: true,
},
"device_type_osx": {
Type: schema.TypeString,
Computed: true,
Expand Down
6 changes: 4 additions & 2 deletions aws/data_source_aws_workspaces_directory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceAwsWorkspacesDirectory_basic(t *testing.T) {
func testAccDataSourceAwsWorkspacesDirectory_basic(t *testing.T) {
rName := acctest.RandString(8)
domain := testAccRandomDomainName()

resourceName := "aws_workspaces_directory.test"
dataSourceName := "data.aws_workspaces_directory.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckWorkspacesDirectory(t)
Expand Down Expand Up @@ -47,6 +47,7 @@ func TestAccDataSourceAwsWorkspacesDirectory_basic(t *testing.T) {
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_access_properties.0.device_type_android", resourceName, "workspace_access_properties.0.device_type_android"),
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_access_properties.0.device_type_chromeos", resourceName, "workspace_access_properties.0.device_type_chromeos"),
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_access_properties.0.device_type_ios", resourceName, "workspace_access_properties.0.device_type_ios"),
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_access_properties.0.device_type_linux", resourceName, "workspace_access_properties.0.device_type_linux"),
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_access_properties.0.device_type_osx", resourceName, "workspace_access_properties.0.device_type_osx"),
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_access_properties.0.device_type_web", resourceName, "workspace_access_properties.0.device_type_web"),
resource.TestCheckResourceAttrPair(dataSourceName, "workspace_access_properties.0.device_type_windows", resourceName, "workspace_access_properties.0.device_type_windows"),
Expand Down Expand Up @@ -94,6 +95,7 @@ resource "aws_workspaces_directory" "test" {
device_type_android = "ALLOW"
device_type_chromeos = "ALLOW"
device_type_ios = "ALLOW"
device_type_linux = "DENY"
device_type_osx = "ALLOW"
device_type_web = "DENY"
device_type_windows = "DENY"
Expand Down
4 changes: 2 additions & 2 deletions aws/data_source_aws_workspaces_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccDataSourceAwsWorkspacesImage_basic(t *testing.T) {
func testAccDataSourceAwsWorkspacesImage_basic(t *testing.T) {
var image workspaces.WorkspaceImage
imageID := os.Getenv("AWS_WORKSPACES_IMAGE_ID")
dataSourceName := "data.aws_workspaces_image.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccWorkspacesImagePreCheck(t)
Expand Down
39 changes: 39 additions & 0 deletions aws/data_source_aws_workspaces_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package aws

import (
"testing"
)

func TestAccDataSourceAwsWorkspaces_serial(t *testing.T) {
testCases := map[string]map[string]func(t *testing.T){
"Bundle": {
"basic": testAccDataSourceAwsWorkspaceBundle_basic,
"bundleIDAndNameConflict": testAccDataSourceAwsWorkspaceBundle_bundleIDAndNameConflict,
"byOwnerName": testAccDataSourceAwsWorkspaceBundle_byOwnerName,
"privateOwner": testAccDataSourceAwsWorkspaceBundle_privateOwner,
},
"Directory": {
"basic": testAccDataSourceAwsWorkspacesDirectory_basic,
},
"Image": {
"basic": testAccDataSourceAwsWorkspacesImage_basic,
},
"Workspace": {
"byWorkspaceID": testAccDataSourceAwsWorkspacesWorkspace_byWorkspaceID,
"byDirectoryID_userName": testAccDataSourceAwsWorkspacesWorkspace_byDirectoryID_userName,
"workspaceIDAndDirectoryIDConflict": testAccDataSourceAwsWorkspacesWorkspace_workspaceIDAndDirectoryIDConflict,
},
}

for group, m := range testCases {
m := m
t.Run(group, func(t *testing.T) {
for name, tc := range m {
tc := tc
t.Run(name, func(t *testing.T) {
tc(t)
})
}
})
}
}
12 changes: 6 additions & 6 deletions aws/data_source_aws_workspaces_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func TestAccDataSourceAwsWorkspacesWorkspace_byWorkspaceID(t *testing.T) {
func testAccDataSourceAwsWorkspacesWorkspace_byWorkspaceID(t *testing.T) {
rName := acctest.RandString(8)
domain := testAccRandomDomainName()

dataSourceName := "data.aws_workspaces_workspace.test"
resourceName := "aws_workspaces_workspace.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckHasIAMRole(t, "workspaces_DefaultRole") },
ErrorCheck: testAccErrorCheck(t, workspaces.EndpointsID),
Providers: testAccProviders,
Expand Down Expand Up @@ -44,14 +44,14 @@ func TestAccDataSourceAwsWorkspacesWorkspace_byWorkspaceID(t *testing.T) {
})
}

func TestAccDataSourceAwsWorkspacesWorkspace_byDirectoryID_userName(t *testing.T) {
func testAccDataSourceAwsWorkspacesWorkspace_byDirectoryID_userName(t *testing.T) {
rName := acctest.RandString(8)
domain := testAccRandomDomainName()

dataSourceName := "data.aws_workspaces_workspace.test"
resourceName := "aws_workspaces_workspace.test"

resource.ParallelTest(t, resource.TestCase{
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckHasIAMRole(t, "workspaces_DefaultRole") },
ErrorCheck: testAccErrorCheck(t, workspaces.EndpointsID),
Providers: testAccProviders,
Expand Down Expand Up @@ -79,8 +79,8 @@ func TestAccDataSourceAwsWorkspacesWorkspace_byDirectoryID_userName(t *testing.T
})
}

func TestAccDataSourceAwsWorkspacesWorkspace_workspaceIDAndDirectoryIDConflict(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
func testAccDataSourceAwsWorkspacesWorkspace_workspaceIDAndDirectoryIDConflict(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t); testAccPreCheckHasIAMRole(t, "workspaces_DefaultRole") },
ErrorCheck: testAccErrorCheck(t, workspaces.EndpointsID),
Providers: testAccProviders,
Expand Down
40 changes: 40 additions & 0 deletions aws/internal/service/workspaces/finder/finder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package finder

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/workspaces"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)

func DirectoryByID(conn *workspaces.WorkSpaces, id string) (*workspaces.WorkspaceDirectory, error) {
input := &workspaces.DescribeWorkspaceDirectoriesInput{
DirectoryIds: aws.StringSlice([]string{id}),
}

output, err := conn.DescribeWorkspaceDirectories(input)

if err != nil {
return nil, err
}

if output == nil || len(output.Directories) == 0 || output.Directories[0] == nil {
return nil, &resource.NotFoundError{
Message: "Empty result",
LastRequest: input,
}
}

// TODO Check for multiple results.
// TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613.

directory := output.Directories[0]

if state := aws.StringValue(directory.State); state == workspaces.WorkspaceDirectoryStateDeregistered {
return nil, &resource.NotFoundError{
Message: state,
LastRequest: input,
}
}

return directory, nil
}
3 changes: 3 additions & 0 deletions aws/internal/service/workspaces/lister/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//go:generate go run ../../../generators/listpages/main.go -function=DescribeIpGroups -paginator=NextToken github.com/aws/aws-sdk-go/service/workspaces

package lister
31 changes: 31 additions & 0 deletions aws/internal/service/workspaces/lister/list_pages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions aws/internal/service/workspaces/waiter/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/workspaces"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/service/workspaces/finder"
"github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
)

func DirectoryState(conn *workspaces.WorkSpaces, directoryID string) resource.StateRefreshFunc {
func DirectoryState(conn *workspaces.WorkSpaces, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
output, err := conn.DescribeWorkspaceDirectories(&workspaces.DescribeWorkspaceDirectoriesInput{
DirectoryIds: aws.StringSlice([]string{directoryID}),
})
if err != nil {
return nil, workspaces.WorkspaceDirectoryStateError, err
output, err := finder.DirectoryByID(conn, id)

if tfresource.NotFound(err) {
return nil, "", nil
}

if len(output.Directories) == 0 {
return output, workspaces.WorkspaceDirectoryStateDeregistered, nil
if err != nil {
return nil, "", err
}

directory := output.Directories[0]
return directory, aws.StringValue(directory.State), nil
return output, aws.StringValue(output.State), nil
}
}

Expand Down
11 changes: 5 additions & 6 deletions aws/internal/service/workspaces/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
)

const (
DirectoryDeregisterInvalidResourceStateTimeout = 2 * time.Minute
DirectoryRegisterInvalidResourceStateTimeout = 2 * time.Minute

// Maximum amount of time to wait for a Directory to return Registered
DirectoryRegisteredTimeout = 10 * time.Minute

Expand All @@ -29,9 +32,7 @@ const (

func DirectoryRegistered(conn *workspaces.WorkSpaces, directoryID string) (*workspaces.WorkspaceDirectory, error) {
stateConf := &resource.StateChangeConf{
Pending: []string{
workspaces.WorkspaceDirectoryStateRegistering,
},
Pending: []string{workspaces.WorkspaceDirectoryStateRegistering},
Target: []string{workspaces.WorkspaceDirectoryStateRegistered},
Refresh: DirectoryState(conn, directoryID),
Timeout: DirectoryRegisteredTimeout,
Expand All @@ -53,9 +54,7 @@ func DirectoryDeregistered(conn *workspaces.WorkSpaces, directoryID string) (*wo
workspaces.WorkspaceDirectoryStateRegistered,
workspaces.WorkspaceDirectoryStateDeregistering,
},
Target: []string{
workspaces.WorkspaceDirectoryStateDeregistered,
},
Target: []string{},
Refresh: DirectoryState(conn, directoryID),
Timeout: DirectoryDeregisteredTimeout,
}
Expand Down
Loading