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

New Data Source: aws_workspaces_image #11428

Merged
merged 3 commits into from
Sep 24, 2020

Conversation

Tensho
Copy link
Contributor

@Tensho Tensho commented Dec 27, 2019

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Release note for CHANGELOG:

New Data Source: aws_workspaces_image (#11428)

Example

data "aws_workspaces_image" "example" {
  image_id = "wsi-ten5h0y19"
}

TODO

  • Create aws_workspaces_image resource before inspecting it with the described data source

Acceptance Tests

$ AWS_WORKSPACES_IMAGE_ID=wsi-vwtykwqyx AWS_DEFAULT_REGION=us-east-1 make testacc TEST=./aws TESTARGS='-run=TestAccDataSourceAwsWorkspacesImage_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccDataSourceAwsWorkspacesImage_basic -timeout 120m
=== RUN   TestAccDataSourceAwsWorkspacesImage_basic
=== PAUSE TestAccDataSourceAwsWorkspacesImage_basic
=== CONT  TestAccDataSourceAwsWorkspacesImage_basic
--- PASS: TestAccDataSourceAwsWorkspacesImage_basic (30.84s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	34.844s

References

@Tensho Tensho requested a review from a team December 27, 2019 12:35
@ghost ghost added needs-triage Waiting for first response or review from a maintainer. size/M Managed by automation to categorize the size of a PR. provider Pertains to the provider itself, rather than any interaction with AWS. service/workspaces Issues and PRs that pertain to the workspaces service. documentation Introduces or discusses updates to documentation. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels Dec 27, 2019
@Tensho
Copy link
Contributor Author

Tensho commented Dec 27, 2019

Unfortunately, it's not possible to create an image with the API at the moment, I've requested corresponding API action with AWS Support ticket.
The current test passes for the manually created image in AWS Web Management Console.

resp, err := conn.DescribeWorkspaceImages(input)
if err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will probably want to check len(resp.Images) > 0 here.
See #11837.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will add

@Tensho Tensho force-pushed the d-workspaces-image branch 3 times, most recently from 51ca002 to dc2f918 Compare May 28, 2020 08:25
@gdavison gdavison self-assigned this Jun 3, 2020
@gdavison gdavison removed the needs-triage Waiting for first response or review from a maintainer. label Jun 4, 2020
Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, @Tensho. A couple changes to make.

aws/data_source_aws_workspaces_image.go Show resolved Hide resolved
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAwsWorkspacesImageConfig("wsi-vwtykwqyx"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't pass in our testing environments, since the image is owned by your account.

We could add an environment variable for the image ID and have a pre-check function that checks for the environment variable. Alternatively, there are API functions to import AMIs as Workspace images.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea with environment variable, will add the pre-check for now. Unfortunately, ImportWorkspaceImage API works only with Windows. I've submitted respective feature request to AWS Support last year. Is it OK to create aws_workspace_image Terraform resource only for Windows, while AWS supports Linux images too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do that. We'll just need to document that it only supports Windows images because of the AWS API

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, even Windows images could be imported only with BYOL, which looks like a totally separate feature.

@ghost ghost added size/L Managed by automation to categorize the size of a PR. and removed size/M Managed by automation to categorize the size of a PR. labels Jun 5, 2020
@Tensho
Copy link
Contributor Author

Tensho commented Jun 5, 2020

@gdavison Thank you, I've added fixes according to your review, please let me know if I can do anything else here 🙇

Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test will need to be updated to handle arbitrary image ids

Comment on lines 24 to 29
resource.TestCheckResourceAttr(dataSourceName, "image_id", "wsi-vwtykwqyx"),
resource.TestCheckResourceAttr(dataSourceName, "name", "Windows10Baseline"),
resource.TestCheckResourceAttr(dataSourceName, "description", "Google Chrome AWS WorkDocs Drive CrowdStrike Falcon Russian/Ukrainian Language Pack"),
resource.TestCheckResourceAttr(dataSourceName, "os", "WINDOWS"),
resource.TestCheckResourceAttr(dataSourceName, "required_tenancy", "DEFAULT"),
resource.TestCheckResourceAttr(dataSourceName, "state", "AVAILABLE"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we're retrieving a WorkSpaces Image using an arbitrary ID, we won't know these values beforehand. You might be able to test this by retrieving the API resource by ID, and then comparing the values in the Terraform resource state. testAccCheckEfsMountTarget() is an example of the approach you could take

Copy link
Contributor Author

@Tensho Tensho Jun 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testAccCheckEfsMountTarget() retrieves actual resource attributes within AWS API, but doesn't test them against state 😄 But I got the idea, you meant item 2 at Anatomy of an Acceptance TesttestAccCheckCloudWatchDashboardExists().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


func testAccWorkspacesImagePreCheck(t *testing.T) {
if os.Getenv("AWS_WORKSPACES_IMAGE_ID") == "" {
t.Fatal("AWS_WORKSPACES_IMAGE_ID env var must be set for AWS WorkSpaces image acceptance tests. This is required until AWS provides ubiquitous (Windows, Linux) import image API.")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the environment variable isn't set, this should skip the test instead of failing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@gdavison gdavison added the waiting-response Maintainers are waiting on response from community or contributor. label Jun 18, 2020
@Tensho Tensho force-pushed the d-workspaces-image branch 2 times, most recently from 4bf7c79 to bc6e5a5 Compare June 21, 2020 21:57
@Tensho
Copy link
Contributor Author

Tensho commented Jun 21, 2020

@gdavison FIxed, check it out again.

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Jun 21, 2020
Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. It will need to be rebased, and I have a few suggested changes.

aws/data_source_aws_workspaces_image_test.go Outdated Show resolved Hide resolved
aws/data_source_aws_workspaces_image_test.go Outdated Show resolved Hide resolved
aws/data_source_aws_workspaces_image.go Outdated Show resolved Hide resolved
Comment on lines +36 to +39
"state": {
Type: schema.TypeString,
Computed: true,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove the state attribute, since it is more of a run-time property, not a configuration property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is a data source, not a resource. Don't we need to get info about any possible attribute there?

aws/data_source_aws_workspaces_image.go Outdated Show resolved Hide resolved
@Tensho
Copy link
Contributor Author

Tensho commented Jul 15, 2020

@gdavison Adjusted according to your comments. Please let me know if you need anything else 🙇

I also work on aws_workspaces_workspace data source, but I've stuck with one test. If you have some time to look there, please could you guide me the right direction 🙇

@Tensho
Copy link
Contributor Author

Tensho commented Aug 25, 2020

@gdavison @ewbankkit Hi ^_^ Please could you check it again?

Copy link
Contributor

@gdavison gdavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

--- PASS: TestAccDataSourceAwsWorkspacesImage_basic (54.32s)

@gdavison gdavison added this to the v3.8.0 milestone Sep 17, 2020
@Tensho
Copy link
Contributor Author

Tensho commented Sep 18, 2020

@gdavison Thank you 🙇

@gdavison gdavison merged commit c7d40f2 into hashicorp:master Sep 24, 2020
gdavison added a commit that referenced this pull request Sep 24, 2020
@ghost
Copy link

ghost commented Sep 24, 2020

This has been released in version 3.8.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@ghost
Copy link

ghost commented Oct 25, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Oct 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. service/workspaces Issues and PRs that pertain to the workspaces service. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants