Skip to content

Commit

Permalink
Merge pull request #14535 from Tensho/workspaces-empty-bundle-owner
Browse files Browse the repository at this point in the history
aws_workspaces_bundle: Fix empty (private) owner
  • Loading branch information
breathingdust authored Nov 10, 2020
2 parents be8eff2 + 9617777 commit 7d387a2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
9 changes: 6 additions & 3 deletions aws/data_source_aws_workspaces_bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,13 @@ func dataSourceAwsWorkspaceBundleRead(d *schema.ResourceData, meta interface{})
}

if name, ok := d.GetOk("name"); ok {
name := name.(string)
input := &workspaces.DescribeWorkspaceBundlesInput{
Owner: aws.String(d.Get("owner").(string)),
input := &workspaces.DescribeWorkspaceBundlesInput{}

if owner, ok := d.GetOk("owner"); ok {
input.Owner = aws.String(owner.(string))
}

name := name.(string)
err := conn.DescribeWorkspaceBundlesPages(input, func(out *workspaces.DescribeWorkspaceBundlesOutput, lastPage bool) bool {
for _, b := range out.Bundles {
if aws.StringValue(b.Name) == name {
Expand Down
36 changes: 36 additions & 0 deletions aws/data_source_aws_workspaces_bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"os"
"regexp"
"testing"

Expand Down Expand Up @@ -73,6 +74,33 @@ func TestAccDataSourceAwsWorkspaceBundle_bundleIDAndNameConflict(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{
PreCheck: func() {
testAccPreCheck(t)
testAccWorkspacesBundlePreCheck(t)
},
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsWorkspaceBundleConfig_privateOwner(bundleName),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(dataSourceName, "name", bundleName),
),
},
},
})
}

func testAccWorkspacesBundlePreCheck(t *testing.T) {
if os.Getenv("AWS_WORKSPACES_BUNDLE_NAME") == "" {
t.Skip("AWS_WORKSPACES_BUNDLE_NAME env var must be set for AWS WorkSpaces private bundle acceptance test. This is required until AWS provides bundle creation API.")
}
}

func testAccDataSourceAwsWorkspaceBundleConfig(bundleID string) string {
return fmt.Sprintf(`
data "aws_workspaces_bundle" "test" {
Expand All @@ -99,3 +127,11 @@ data "aws_workspaces_bundle" "test" {
}
`, bundleID, owner, name)
}

func testAccDataSourceAwsWorkspaceBundleConfig_privateOwner(name string) string {
return fmt.Sprintf(`
data "aws_workspaces_bundle" "test" {
name = %q
}
`, name)
}
10 changes: 8 additions & 2 deletions website/docs/d/workspaces_bundle.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ Retrieve information about an AWS WorkSpaces bundle.

## Example Usage

### By ID

```hcl
data "aws_workspaces_bundle" "by_id" {
data "aws_workspaces_bundle" "example" {
bundle_id = "wsb-b0s22j3d7"
}
```

data "aws_workspaces_bundle" "by_owner_and_name" {
### By Owner & Name

```hcl
data "aws_workspaces_bundle" "example" {
owner = "AMAZON"
name = "Value with Windows 10 and Office 2016"
}
Expand Down

0 comments on commit 7d387a2

Please sign in to comment.