-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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_server
: fix for administrator_login_password
not being able to be updated
#25182
base: main
Are you sure you want to change the base?
Conversation
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.
Thanks very much for your PR. I'm not really familiar with this codebase, but I wanted to review to the best of my ability.
version = "12.0" | ||
|
||
administrator_login = "missadministrator" | ||
administrator_login_password = "thisIsKat11" |
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.
I'm not sure if having azuread_authentication_only = true
and administrator_login_password
present is a feasible state. My bug report's initial state is aad auth is true and there is no additional administrator_login setting.
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.
I assume that it is possible because in the Terraform documentation it is stated that When true, the administrator_login and administrator_login_password properties can be omitted.
. I assuming this means omitted
means azure authentication only, not omitted
means both. Also, the test case TestAccMsSqlServer_passwordUpdate
passed.
@@ -762,6 +784,72 @@ resource "azurerm_mssql_server" "test" { | |||
`, data.RandomInteger, data.Locations.Primary) | |||
} | |||
|
|||
func (MsSqlServerResource) password(data acceptance.TestData) string { |
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.
Not knowing much about the code styling of this repositiry, I think this function naming could be improved to something like mssqlServerResourceWithAadAuthOnly
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.
Thanks, changed to aadAdminWithAADAuthOnlyWithPassword
.
`, data.RandomInteger, data.Locations.Primary) | ||
} | ||
|
||
func (MsSqlServerResource) passwordUpdate(data acceptance.TestData) string { |
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.
Similarly would rename to something like mssqServerResourceWithAdminLogin
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.
Thanks, changed to aadAdminWithAADAuthOnlyWithPasswordUpdate
.
@@ -177,6 +177,28 @@ func TestAccMsSqlServer_azureadAdmin(t *testing.T) { | |||
}) | |||
} | |||
|
|||
func TestAccMsSqlServer_passwordUpdate(t *testing.T) { |
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.
Might prefer rename to be more precise (see comments below)
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.
Maybe the TestAccMsSqlServer_azureadAdminWithAADAuthOnlyWithPasswordUpdate
would be more appropriate.
aadOnlyAuthentictionsEnabled := expandMsSqlServerAADOnlyAuthentictions(d.Get("azuread_administrator").([]interface{})) | ||
if _, ok := d.GetOk("administrator_login_password"); ok && aadOnlyAuthentictionsEnabled && d.HasChange("administrator_login_password") { | ||
return fmt.Errorf("`administrator_login_password` cannot be changed when `azuread_administrator.0.azuread_authentication_only = true`") |
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.
Authentiction typos?
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.
Thanks for the correction.
Properties: &serverazureadonlyauthentications.AzureADOnlyAuthProperties{ | ||
AzureADOnlyAuthentication: aadOnlyAuthentictionsEnabled, | ||
}, | ||
if payload := existing.Model; payload != nil { |
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.
Sorry this may be a silly question but was there a reason for moving this part of the code?
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.
Moving this part of the code is key to solving issue #25116, where the Azure Rest API does not allow administrator_login_password
updates when azuread_authentication_only = true
. Because the API has such limitations, the correct behavior of TF should be to first update azuread_authentication_only = false
(specified by the user), and then update administrator_login_password
, so that the update can be successful.
Hi @AtakanColak thanks for your time and feedback. |
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.
Thanks for looking at this @sinbai. Isn't the problem here due to azuread_authentication_only
being optional + computed? If we make this not computed, the validation should pass as-is?
@@ -319,6 +317,11 @@ func resourceMsSqlServerUpdate(d *pluginsdk.ResourceData, meta interface{}) erro | |||
ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) | |||
defer cancel() | |||
|
|||
aadOnlyAuthenticationsEnabled := expandMsSqlServerAADOnlyAuthentictions(d.Get("azuread_administrator").([]interface{})) |
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.
(typo)
aadOnlyAuthenticationsEnabled := expandMsSqlServerAADOnlyAuthentictions(d.Get("azuread_administrator").([]interface{})) | |
aadOnlyAuthenticationsEnabled := expandMsSqlServerAADOnlyAuthentications(d.Get("azuread_administrator").([]interface{})) |
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.
Fixed.
@@ -443,18 +388,80 @@ func resourceMsSqlServerUpdate(d *pluginsdk.ResourceData, meta interface{}) erro | |||
return fmt.Errorf("deleting Azure Active Directory Administrator %s: %+v", id, err) | |||
} | |||
} | |||
|
|||
if aadOnlyAuthenticationsEnabled { | |||
aadOnlyAuthentictionsProps := serverazureadonlyauthentications.ServerAzureADOnlyAuthentication{ |
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.
(typo)
aadOnlyAuthentictionsProps := serverazureadonlyauthentications.ServerAzureADOnlyAuthentication{ | |
aadOnlyAuthenticationsProps := serverazureadonlyauthentications.ServerAzureADOnlyAuthentication{ |
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.
Fixed.
Hi @manicminer thanks for your time and feedback. I assume that even if we make
Therefore, I removed the validation and adjusted the update order in 2. to fix #25116. Please let me know if you have any feedback. Thanks in advance. |
0713f79
to
e52def6
Compare
azurerm_mssql_server
:Therefore, I removed the validation in code, and adjusted the update order in 2. to fix #25116.
Test results: