-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
New Data Source: aws_workspaces_bundle #3243
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/workspaces" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsWorkspaceBundle() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsWorkspaceBundleRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"bundle_id": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
"description": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"owner": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"compute_type": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"user_storage": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"capacity": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
"root_storage": { | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"capacity": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsWorkspaceBundleRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).wsconn | ||
|
||
bundleID := d.Get("bundle_id").(string) | ||
input := &workspaces.DescribeWorkspaceBundlesInput{ | ||
BundleIds: []*string{aws.String(bundleID)}, | ||
} | ||
|
||
resp, err := conn.DescribeWorkspaceBundles(input) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if len(resp.Bundles) != 1 { | ||
return fmt.Errorf("The number of Workspace Bundle (%s) should be 1, but %d", bundleID, len(resp.Bundles)) | ||
} | ||
|
||
bundle := resp.Bundles[0] | ||
d.SetId(bundleID) | ||
d.Set("description", bundle.Description) | ||
d.Set("name", bundle.Name) | ||
d.Set("owner", bundle.Owner) | ||
if bundle.ComputeType != nil { | ||
r := map[string]interface{}{ | ||
"name": *bundle.ComputeType.Name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To prevent potential panics, we should prefer to use the SDK provided function for dereferencing values (e.g. This needs to be repeated for |
||
} | ||
ct := []map[string]interface{}{r} | ||
d.Set("compute_type", ct) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When using if err := d.Set("compute_type", ct); err != nil {
return fmt.Errorf("error setting compute_type: %s", err)
} This also needs to be repeated for |
||
} | ||
if bundle.RootStorage != nil { | ||
r := map[string]interface{}{ | ||
"capacity": *bundle.RootStorage.Capacity, | ||
} | ||
rs := []map[string]interface{}{r} | ||
d.Set("root_storage", rs) | ||
} | ||
if bundle.UserStorage != nil { | ||
r := map[string]interface{}{ | ||
"capacity": *bundle.UserStorage.Capacity, | ||
} | ||
us := []map[string]interface{}{r} | ||
d.Set("user_storage", us) | ||
} | ||
|
||
return nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package aws | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceAwsWorkspaceBundle_basic(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
resource.TestStep{ | ||
Config: testAccDataSourceAwsWorkspaceBundleConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr("data.aws_workspaces_bundle.test", "bundle_id", "wsb-b0s22j3d7"), | ||
resource.TestCheckResourceAttrSet( | ||
"data.aws_workspaces_bundle.test", "name"), | ||
resource.TestCheckResourceAttrSet( | ||
"data.aws_workspaces_bundle.test", "owner"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
const testAccDataSourceAwsWorkspaceBundleConfig = ` | ||
data "aws_workspaces_bundle" "test" { | ||
bundle_id = "wsb-b0s22j3d7" | ||
} | ||
` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_workspaces_bundle" | ||
sidebar_current: "docs-aws-datasource-workspaces-bundle" | ||
description: |- | ||
Get information on a Workspaces Bundle. | ||
--- | ||
|
||
# aws_workspaces_bundle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most likely a change that occurred after the creation of this pull request, but can you please prepend the title with |
||
|
||
Use this data source to get information about a Workspaces Bundle. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "aws_workspaces_bundle" "example" { | ||
bundle_id = "wsb-b0s22j3d7" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `bundle_id` – (Required, ForceNew) The ID of the bundle. | ||
|
||
## Attributes Reference | ||
|
||
The following attributes are exported: | ||
|
||
* `description` – The description of the bundle. | ||
* `name` – The name of the bundle. | ||
* `owner` – The owner of the bundle. | ||
* `compute_type` – The compute type. See supported fields below. | ||
* `root_storage` – The root volume. See supported fields below. | ||
* `user_storage` – The user storage. See supported fields below. | ||
|
||
### `compute_type` | ||
|
||
* `name` - The name of the compute type. | ||
|
||
### `root_storage` | ||
|
||
* `capacity` - The size of the root volume. | ||
|
||
### `user_storage` | ||
|
||
* `capacity` - The size of the user storage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nitpick: to prevent any confusion with other services, we should probably name this
workspacesconn