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 edition parameter for MS AD #3421

Merged
merged 9 commits into from
Feb 20, 2018
Merged

Conversation

leibowitz
Copy link
Contributor

@leibowitz leibowitz commented Feb 16, 2018

@ghost ghost added the size/S Managed by automation to categorize the size of a PR. label Feb 16, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

@leibowitz thanks for this contribution! Can you check out my below comments and let me know if you have any questions please? We also should add an acceptance test to ensure that this does actually get set in the Terraform state.

e.g. in TestAccAWSDirectoryServiceDirectory_microsoft below the Exists check:

resource.TestCheckResourceAttr("aws_directory_service_discovery.bar", "edition", "Enterprise")

Preferably we'd also create a second acceptance test to ensure that setting Standard does in fact create a Standard edition directory.

Optional: true,
Default: "Enterprise",
ForceNew: true,
ValidateFunc: func(v interface{}, k string) (ws []string, es []error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be simplified to the below 😄

ValidateFunc: validation.StringInSlice([]string{
	directoryservice.DirectoryEditionEnterprise,
	directoryservice.DirectoryEditionStandard,
}, false),

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 looked around the code to find something similar, but ended up stealing the validation from another attribute. This is much better. Thanks for that

"edition": {
Type: schema.TypeString,
Optional: true,
Default: "Enterprise",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick: Can you please use the SDK provided constant here? directoryservice.DirectoryEditionEnterprise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -445,6 +465,9 @@ func resourceAwsDirectoryServiceDirectoryRead(d *schema.ResourceData, meta inter
if dir.Size != nil {
d.Set("size", *dir.Size)
}
if dir.Edition != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Normally this check wouldn't be necessary, however I think because we the SDK handles both SimpleAD and MicrosoftAD directory types that in fact we do want to keep this nil check in here. 👍

@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Feb 16, 2018
@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Feb 16, 2018
@ghost ghost added size/M Managed by automation to categorize the size of a PR. and removed size/S Managed by automation to categorize the size of a PR. labels Feb 16, 2018
@leibowitz
Copy link
Contributor Author

Test done

Thanks a lot for the tips 👍 You did it all 😄

@leibowitz
Copy link
Contributor Author

leibowitz commented Feb 16, 2018

What is the expected behaviour when edition is specified but the type isn't MicrosoftAD? Should it throw an error? I'm not 100% sure what will happen at the moment, if the AWS API will reject the request or not (probably will)
Update: just tried with SimpleAD, it seems to be ignored. Just like size is ignored when using MicrosoftAD

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Feb 19, 2018
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

Thanks for working through this @leibowitz! This LGTM with some minor changes that I have pushed in a followup commit (since it turns out this is much more nuanced than it looks):

  • Fixed typos in acceptance testing: Previously (notice _discovery not _directory)
=== RUN   TestAccAWSDirectoryServiceDirectory_microsoft
--- FAIL: TestAccAWSDirectoryServiceDirectory_microsoft (1688.08s)
    testing.go:513: Step 0 error: Check failed: Check 2/2 error: Not found: aws_directory_service_discovery.bar in [root]
=== RUN   TestAccAWSDirectoryServiceDirectory_microsoftStandard
--- FAIL: TestAccAWSDirectoryServiceDirectory_microsoftStandard (1639.87s)
    testing.go:513: Step 0 error: Check failed: Check 2/2 error: Not found: aws_directory_service_discovery.bar in [root]
  • Change the edition attribute Default: ... to Computed: true and always d.Set() in the state - this was required because when importing an aws_directory_service_directory, it did not know what the correct value was for SimpleAD type:
=== RUN   TestAccAWSDirectoryServiceDirectory_importBasic
--- FAIL: TestAccAWSDirectoryServiceDirectory_importBasic (472.82s)
	testing.go:513: Step 1 error: ImportStateVerify attributes not equivalent. Difference is shown below. Top is actual, bottom is expected.

		(map[string]string) {
		}


		(map[string]string) (len=1) {
		 (string) (len=7) "edition": (string) (len=10) "Enterprise"
		}
  • With edition = "Standard", the API was returning size as "Small", which does not play well with the Default: "Large" for that attribute. Like edition, I marked size as Computed: true without the default to match to existing Terraform and API documentation. Previously:
=== RUN   TestAccAWSDirectoryServiceDirectory_microsoftStandard
--- FAIL: TestAccAWSDirectoryServiceDirectory_microsoftStandard (1704.19s)
    testing.go:513: Step 0 error: After applying this step, the plan was not empty:
        
        DIFF:
        
        DESTROY/CREATE: aws_directory_service_directory.bar
          access_url:                           "d-92672652d7.awsapps.com" => "<computed>"
          alias:                                "d-92672652d7" => "<computed>"
          dns_ip_addresses.#:                   "2" => "<computed>"
          edition:                              "Standard" => "Standard"
          enable_sso:                           "false" => "false"
          name:                                 "corp.notexample.com" => "corp.notexample.com"
          password:                             "<sensitive>" => "<sensitive>" (attribute changed)
          security_group_id:                    "sg-4a3ba335" => "<computed>"
          short_name:                           "corp" => "<computed>"
          size:                                 "Small" => "Large" (forces new resource)
          type:                                 "MicrosoftAD" => "MicrosoftAD"
          vpc_settings.#:                       "1" => "1"
          vpc_settings.0.subnet_ids.#:          "2" => "2"
          vpc_settings.0.subnet_ids.106299362:  "subnet-2c1fde55" => "subnet-2c1fde55"
          vpc_settings.0.subnet_ids.3442655816: "subnet-1e53b355" => "subnet-1e53b355"
          vpc_settings.0.vpc_id:                "vpc-0177fd78" => "vpc-0177fd78"

Now passes everything:

Provider_-_*.log
=== RUN   TestAccAWSDirectoryServiceDirectory_importBasic
--- PASS: TestAccAWSDirectoryServiceDirectory_importBasic (458.95s)
=== RUN   TestAccAWSDirectoryServiceDirectory_tags
--- PASS: TestAccAWSDirectoryServiceDirectory_tags (533.45s)
=== RUN   TestAccAWSDirectoryServiceDirectory_basic
--- PASS: TestAccAWSDirectoryServiceDirectory_basic (567.34s)
=== RUN   TestAccAWSDirectoryServiceDirectory_withAliasAndSso
--- PASS: TestAccAWSDirectoryServiceDirectory_withAliasAndSso (583.32s)
=== RUN   TestAccAWSDirectoryServiceDirectory_connector
--- PASS: TestAccAWSDirectoryServiceDirectory_connector (861.61s)
=== RUN   TestAccAWSDirectoryServiceDirectory_microsoftStandard
--- PASS: TestAccAWSDirectoryServiceDirectory_microsoftStandard (1630.21s)
=== RUN   TestAccAWSDirectoryServiceDirectory_microsoft
--- PASS: TestAccAWSDirectoryServiceDirectory_microsoft (1690.35s)

@bflad bflad added this to the v1.10.0 milestone Feb 20, 2018
@bflad bflad merged commit cd21c8f into hashicorp:master Feb 20, 2018
bflad added a commit that referenced this pull request Feb 20, 2018
@leibowitz
Copy link
Contributor Author

Good catches! Sorry for the typo, not sure where that came from :| Also for the Computed and the problem with Size, plus the default value returned by the API, I'm glad you tested this properly. Really appreciate the work you've put into this!

Like I said before, you did most (if not all) of the work in the end. Thanks again

@bflad
Copy link
Contributor

bflad commented Feb 27, 2018

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

@ghost
Copy link

ghost commented Apr 7, 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 and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. size/M Managed by automation to categorize the size of a PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add edition option for aws_directory_service_directory resource Microsoft AD Size ignored
2 participants