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_virtual_machine: fix tests and persistent diff, use relative expiry for service principal password #10125

Merged
merged 5 commits into from Jan 14, 2021

Conversation

manicminer
Copy link
Member

No description provided.

@manicminer manicminer added service/mssql Microsoft SQL Server tests labels Jan 11, 2021
@manicminer manicminer requested a review from a team January 11, 2021 06:39
@ghost ghost added the size/XS label Jan 11, 2021
@manicminer manicminer force-pushed the test/mssql-vm-sp-password branch 2 times, most recently from a23c07e to 8d676fc Compare January 11, 2021 07:11
Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Thanks @manicminer - LGTM 👍

@manicminer
Copy link
Member Author

manicminer commented Jan 11, 2021

The test still doesn't pass, there's a persistent diff affecting a few tests. Fix incoming.

    === CONT  TestAccMsSqlVirtualMachine_withKeyVault
        testing.go:684: Step 0 error: After applying this step, the plan was not empty:
            
            DIFF:
            
            UPDATE: azurerm_mssql_virtual_machine.test
              auto_patching.#:                                 "0" => "0"
              id:                                              "/subscriptions/*******/resourceGroups/acctestRG-mssql-210111071526852118/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/acctest-VM-210111071526852118" => "/subscriptions/*******/resourceGroups/acctestRG-mssql-210111071526852118/providers/Microsoft.SqlVirtualMachine/sqlVirtualMachines/acctest-VM-210111071526852118"
              key_vault_credential.#:                          "1" => "1"
              key_vault_credential.0.key_vault_url:            "https://acckv-210111071526852118.vault.azure.net/keys/key-210111071526852118/dd21fd1eba9f42e091936a9fb93494cb" => "https://acckv-210111071526852118.vault.azure.net/keys/key-210111071526852118/dd21fd1eba9f42e091936a9fb93494cb"
              key_vault_credential.0.name:                     "acckv-210111071526852118:acctestkv" => "acckv-210111071526852118:acctestkv"
              key_vault_credential.0.service_principal_name:   "acctestspa210111071526852118" => "acctestspa210111071526852118"
              key_vault_credential.0.service_principal_secret: "d78b538b-c58e-46ac-57d4-247a1afd04a8" => "d78b538b-c58e-46ac-57d4-247a1afd04a8"
              r_services_enabled:                              "false" => "false"
              sql_connectivity_port:                           "1433" => "1433"
              sql_connectivity_type:                           "PRIVATE" => "PRIVATE"
              sql_license_type:                                "PAYG" => "PAYG"
              storage_configuration.#:                         "1" => "0"
              storage_configuration.0.data_settings.#:         "0" => ""
              storage_configuration.0.disk_type:               "" => ""
              storage_configuration.0.log_settings.#:          "0" => ""
              storage_configuration.0.storage_workload_type:   "" => ""
              storage_configuration.0.temp_db_settings.#:      "0" => ""
              virtual_machine_id:                              "/subscriptions/*******/resourceGroups/acctestRG-mssql-210111071526852118/providers/Microsoft.Compute/virtualMachines/acctest-VM-210111071526852118" => "/subscriptions/*******/resourceGroups/acctestRG-mssql-210111071526852118/providers/Microsoft.Compute/virtualMachines/acctest-VM-210111071526852118"

@ghost ghost added size/S and removed size/XS labels Jan 11, 2021
@manicminer manicminer changed the title mssql: fix test, use relative expiry for service principal password mssql: fix tests and persistent diff, use relative expiry for service principal password Jan 11, 2021
@manicminer
Copy link
Member Author

Tests pass with one unrelated destroy failure:

Screenshot 2021-01-11 at 23 34 55

Copy link
Member

@jackofallops jackofallops left a comment

Choose a reason for hiding this comment

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

Thanks @manicminer - Just a couple questions / comments in-line, otherwise LGTM 👍

@@ -510,10 +528,10 @@ func expandSqlVirtualMachineDataStorageSettings(input []interface{}) *sqlvirtual
}

func expandSqlVirtualMachineStorageSettingsLuns(input []interface{}) *[]int32 {
expandedLuns := make([]int32, len(input))
expandedLuns := make([]int32, 0, len(input))
Copy link
Member

Choose a reason for hiding this comment

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

Not sure we need the capacity arg here since we're ranging over input?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK cool, yeah it works without it too.

Comment on lines 495 to 497
if storageWorkloadType != "" {
output["storage_workload_type"] = storageWorkloadType
}
Copy link
Member

Choose a reason for hiding this comment

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

this possibly wants setting as an empty string so there's always a value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately the problem is that Terraform shows state drift if the containing list has any elements when there are none in the config. It looks like the API has started returning an array having zero values instead of omitting it from the response, which is why I've made it try and detect that. Is there is a better way to avoid state drift in such circumstances?

Copy link
Member

Choose a reason for hiding this comment

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

agreed we should track an empty string in the state in all cases - but if the nested object is returned as an empty object (e.g. all fields are empty) then we'd need to do conditionally return an empty object rather than the nested object - and presumably raise an API bug for that?

Copy link
Member Author

Choose a reason for hiding this comment

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

@tombuildsstuff Yep an empty object is exactly what's being returned. I'll raise an API bug today and adjust the logic so that an empty string is saved if the other attributes are present and non-zero.

Copy link
Member

Choose a reason for hiding this comment

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

given this affects the entire block - presuming we're using intermediate variables, we should be able to conditionally check the set and conditionally return the nested object, e.g.:

foo := ""
if props.Foo != nil { foo = *props.Foo }

bar := ""
if props.Bar != nil { bar = *props.Bar }

if foo == "" && bar == "" {  return []interface{}{} }

return []interface{}{
  map[string]interface{}{
    "foo": foo,
    "bar": bar,
  },
}

(we've a few instances of this of late)

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, makes sense. Have adjusted it to always set all attributes [in the block], but return an empty slice if they all have zero values.

@katbyte katbyte changed the title mssql: fix tests and persistent diff, use relative expiry for service principal password azurerm_mssql_virtual_machine: fix tests and persistent diff, use relative expiry for service principal password Jan 14, 2021
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 @manicminer - LGTM 👍

@katbyte katbyte added this to the v2.43.0 milestone Jan 14, 2021
@katbyte katbyte merged commit ce46f33 into master Jan 14, 2021
@katbyte katbyte deleted the test/mssql-vm-sp-password branch January 14, 2021 01:09
katbyte added a commit that referenced this pull request Jan 14, 2021
@ghost
Copy link

ghost commented Jan 14, 2021

This has been released in version 2.43.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.43.0"
}
# ... other configuration ...

@ghost
Copy link

ghost commented Feb 13, 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 Feb 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants