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

azurerm_api_management_diagnostic add additional options, fix log_client_ip #10325

Merged

Conversation

slynickel
Copy link
Contributor

@slynickel slynickel commented Jan 27, 2021

This looks larger then it is.

Fixes the remaining request in #9196 by adding additional options to azurerm_api_management_diagnostic. The heavy lifting was done by recent PRs for azure_api_management_api_diagnostic as the Go SDK uses the same struct for both diagnostics apimangement.DiagnosticContract. This allowed the code to be completely reused.

Fixes #10322 which was found while testing this PR. Update to only checking if the input variable is nil as the ok value from GetOk does a Zero check which fails to work correctly with a Boolean variable. There could be some other ramifications of this I'm not aware of but I couldn't find a test case for this resource that was an issue.

question (non-blocking): the new options to azurerm_api_management_diagnostic reuse the functions expandApiManagementApiDiagnosticHTTPMessageDiagnostic and flattenApiManagementApiDiagnosticHTTPMessageDiagnostic should I rename these? I didn't because I wasn't sure it mattered.

Previously when log_client_ip was true on the resource and there was
desire to set to false a apply loop would occur as the value wasn't
being updated. This is now fixed.
@slynickel
Copy link
Contributor Author

New acceptance test pass (as first submitter to this repository the README is out of date with how to run the acceptance tests). The _complete acceptance test validates #10322 is fixed.

~/go/src/github.com/terraform-providers/terraform-provider-azurerm(fix-9196-api_management_diagnostic)
$ TF_ACC=1 go test -v -timeout 120m -run '^(TestAccApiManagementDiagnostic_basic|TestAccApiManagementDiagnostic_update|TestAccApiManagementDiagnostic_requiresImport|TestAccApiManagementDiagnostic_complete)$' github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement  -ldflags="-X=github.com/terraform-providers/terraform-provider-azurerm/version.ProviderVersion=acc"
=== RUN   TestAccApiManagementDiagnostic_basic
=== PAUSE TestAccApiManagementDiagnostic_basic
=== RUN   TestAccApiManagementDiagnostic_update
=== PAUSE TestAccApiManagementDiagnostic_update
=== RUN   TestAccApiManagementDiagnostic_requiresImport
=== PAUSE TestAccApiManagementDiagnostic_requiresImport
=== RUN   TestAccApiManagementDiagnostic_complete
=== PAUSE TestAccApiManagementDiagnostic_complete
=== CONT  TestAccApiManagementDiagnostic_basic
=== CONT  TestAccApiManagementDiagnostic_complete
=== CONT  TestAccApiManagementDiagnostic_requiresImport
=== CONT  TestAccApiManagementDiagnostic_update
--- PASS: TestAccApiManagementDiagnostic_requiresImport (2276.90s)
--- PASS: TestAccApiManagementDiagnostic_complete (2370.21s)
--- PASS: TestAccApiManagementDiagnostic_basic (2385.37s)
--- PASS: TestAccApiManagementDiagnostic_update (2403.43s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/apimanagement       2403.466s

Copy link
Collaborator

@katbyte katbyte left a comment

Choose a reason for hiding this comment

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

Thanks @slynickel - overall this looks good, i've left two small comments and once they are addressed this should be good to merge 🙂

@tombuildsstuff tombuildsstuff modified the milestones: v2.45.0, v2.46.0 Jan 28, 2021
Remove switch statements for http_correlation_protocol and verbosity to
instead use the azure sdk for go built in enumeration functions
@slynickel
Copy link
Contributor Author

@katbyte back to you. Thanks for the quick response time.

Comment on lines 188 to 191
logClientIP, _ := d.GetOk("log_client_ip")
if logClientIP != nil {
parameters.LogClientIP = utils.Bool(logClientIP.(bool))
}
Copy link
Member

Choose a reason for hiding this comment

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

Hi @slynickel, many thanks for the PR.

Because this attribute is optional+computed, it would be best to use GetOkExists() which tells you if the attribute is configured, but bypasses the zero value check so you can detect an explicit false value.

Suggested change
logClientIP, _ := d.GetOk("log_client_ip")
if logClientIP != nil {
parameters.LogClientIP = utils.Bool(logClientIP.(bool))
}
if logClientIP, exists := d.GetOkExists("log_client_ip"); exists {
parameters.LogClientIP = utils.Bool(logClientIP.(bool))
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@manicminer Isn't that function being deprecated though? ResourceData.GetOkayExist()

GetOkExists can check if TypeBool attributes that are Optional with no Default value have been set.

Deprecated: usage is discouraged due to undefined behaviors and may be removed in a future version of the SDK

My light review of the terraform-plugin-sdk is that some sections are pretty old, though the deprecation warning is within the last year.

Copy link
Member

Choose a reason for hiding this comment

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

@slynickel I checked with the team and although it's marked as deprecated in the SDK, in a context like this (specifically optional+computed booleans) there's little alternative and it's ok to use it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

Make sense, thanks for context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@manicminer I'm assuming the failed golint check as a result of GetOkExist can be ignored?

Copy link
Member

Choose a reason for hiding this comment

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

@slynickel we can add a nolint comment to suppress that, i've pushed that whilst I run the acceptance tests

slynickel and others added 2 commits January 28, 2021 20:48
GetOkayExists while deprecated is the best option for boolean optional
computed variables
@manicminer
Copy link
Member

Test results

Screenshot 2021-01-29 at 15 22 33

@manicminer
Copy link
Member

@slynickel Thanks again for the contribution :)

@manicminer manicminer merged commit d814b04 into hashicorp:master Jan 29, 2021
manicminer added a commit that referenced this pull request Jan 29, 2021
@ghost
Copy link

ghost commented Feb 5, 2021

This has been released in version 2.46.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:

provider "azurerm" {
    version = "~> 2.46.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Mar 1, 2021

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. If you feel I made an error 🤖 🙉 , please reach out to my human friends 👉 hashibot-feedback@hashicorp.com. Thanks!

@hashicorp hashicorp locked as resolved and limited conversation to collaborators Mar 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

azurerm_api_management_api_diagnostic.log_client_ip cannot be set to false
4 participants