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_mssql_database_vulnerability_assessment_rule_baseline: fix the resource is being replaced every new tf apply issue #14759

Merged
merged 2 commits into from
Mar 22, 2022

Conversation

sinbai
Copy link
Contributor

@sinbai sinbai commented Dec 31, 2021

The purpose of this PR:

Fix Issue #14695. The issue is that the resource azurerm_mssql_database_vulnerability_assessment_rule_baseline is always created when the "terraform apply" runs every time, even if the tf config is not changed. The server_vulnerability_assessment_id property is ForceNew in terraform. So, when the value of the property is changed, the resource would be re-created. In this case, the root cause is that the DatabaseVulnerabilityAssessments API returns the VulnerabilityAssessmentName of id in uppercase, which changes the property value. So, I submitted this PR as a workaround for the issue. And I created an issue for Azure API to fix it completely. And this PR should be reverted after the API issue is fixed.

Test results:
PASS: TestAccMsSqlDatabaseVulnerabilityAssessmentRuleBaseline_basic (461.71s)
PASS: TestAccMsSqlDatabaseVulnerabilityAssessmentRuleBaseline_primary (550.76s)

Copy link
Contributor

@tombuildsstuff tombuildsstuff left a comment

Choose a reason for hiding this comment

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

hey @sinbai

Thanks for this PR - apologies for the delayed review here.

I've taken a look through and it appears this data can come from the ID being provided, as such we can use that casing here which should solve this.

Thanks!

@@ -153,7 +153,8 @@ func resourceMsSqlDatabaseVulnerabilityAssessmentRuleBaselineRead(d *pluginsdk.R
d.Set("rule_id", id.RuleName)
d.Set("baseline_name", id.BaselineName)

vulnerabilityAssessmentId := parse.NewServerVulnerabilityAssessmentID(id.SubscriptionId, id.ResourceGroup, id.ServerName, "default")
// TODO: replace "Default" with "default" after the issue(https://github.com/Azure/azure-rest-api-specs/issues/17192) is fixed.
vulnerabilityAssessmentId := parse.NewServerVulnerabilityAssessmentID(id.SubscriptionId, id.ResourceGroup, id.ServerName, "Default")
Copy link
Contributor

Choose a reason for hiding this comment

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

since this is coming from the user input we can make this:

Suggested change
vulnerabilityAssessmentId := parse.NewServerVulnerabilityAssessmentID(id.SubscriptionId, id.ResourceGroup, id.ServerName, "Default")
vulnerabilityAssessmentId := parse.NewServerVulnerabilityAssessmentID(id.SubscriptionId, id.ResourceGroup, id.ServerName, id.DatabaseName, id.VulnerabilityAssessmentName)

which'll make it consistent with how this is handled above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, Fixed.

@tombuildsstuff tombuildsstuff added this to the v3.0.0 milestone Mar 21, 2022
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 @sinbai - LGTM 🦀

@katbyte katbyte merged commit c7292fb into hashicorp:main Mar 22, 2022
katbyte added a commit that referenced this pull request Mar 22, 2022
@sinbai sinbai deleted the mssql/fix_resource_replaced_issue branch March 23, 2022 02:18
@github-actions
Copy link

This functionality has been released in v3.0.0 of the Terraform 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. Thank you!

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 24, 2022
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.

3 participants