provider/azurerm: Fix an issue with `azurerm_virtual_machine` ssh_keys
ssh_keys were throwing an error similar to this: ``` * azurerm_virtual_machine.test: [DEBUG] Error setting Virtual Machine * Storage OS Profile Linux Configuration: &errors.errorString{s:"Invalid * address to set: []string{\"os_profile_linux_config\", \"0\", * \"ssh_keys\"}"} ``` This was because of nesting of Set within a Set in the schema. By changing this to a List within a Set, the schema works as expected. This means we can now set SSH Keys on VMs. This has been tested using a remote-exec and a connection block with the ssh key ``` azurerm_virtual_machine.test: Still creating... (2m10s elapsed) azurerm_virtual_machine.test (remote-exec): Connected! azurerm_virtual_machine.test (remote-exec): CONNECTED! ```
This commit is contained in:
parent
1c3fff19d0
commit
712fc83a20
|
@ -277,7 +277,7 @@ func resourceArmVirtualMachine() *schema.Resource {
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
"ssh_keys": &schema.Schema{
|
"ssh_keys": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeList,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
Elem: &schema.Resource{
|
Elem: &schema.Resource{
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
@ -291,7 +291,6 @@ func resourceArmVirtualMachine() *schema.Resource {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Set: resourceArmVirtualMachineStorageOsProfileLinuxConfigSshKeyHash,
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -491,7 +490,7 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Properties.OsProfile.LinuxConfiguration != nil {
|
if resp.Properties.OsProfile.LinuxConfiguration != nil {
|
||||||
if err := d.Set("os_profile_linux_config", schema.NewSet(resourceArmVirtualMachineStorageOsProfileLinuxConfigHash, flattenAzureRmVirtualMachineOsProfileLinuxConfiguration(resp.Properties.OsProfile.LinuxConfiguration))); err != nil {
|
if err := d.Set("os_profile_linux_config", flattenAzureRmVirtualMachineOsProfileLinuxConfiguration(resp.Properties.OsProfile.LinuxConfiguration)); err != nil {
|
||||||
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage OS Profile Linux Configuration: %#v", err)
|
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Storage OS Profile Linux Configuration: %#v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -586,17 +585,6 @@ func resourceArmVirtualMachineStorageOsDiskHash(v interface{}) int {
|
||||||
return hashcode.String(buf.String())
|
return hashcode.String(buf.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func resourceArmVirtualMachineStorageOsProfileLinuxConfigSshKeyHash(v interface{}) int {
|
|
||||||
var buf bytes.Buffer
|
|
||||||
m := v.(map[string]interface{})
|
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["path"].(string)))
|
|
||||||
if m["key_data"] != nil {
|
|
||||||
buf.WriteString(fmt.Sprintf("%s-", m["key_data"].(string)))
|
|
||||||
}
|
|
||||||
|
|
||||||
return hashcode.String(buf.String())
|
|
||||||
}
|
|
||||||
|
|
||||||
func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int {
|
func resourceArmVirtualMachineStorageOsProfileLinuxConfigHash(v interface{}) int {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
m := v.(map[string]interface{})
|
m := v.(map[string]interface{})
|
||||||
|
@ -747,15 +735,15 @@ func flattenAzureRmVirtualMachineOsProfileWindowsConfiguration(config *compute.W
|
||||||
}
|
}
|
||||||
|
|
||||||
func flattenAzureRmVirtualMachineOsProfileLinuxConfiguration(config *compute.LinuxConfiguration) []interface{} {
|
func flattenAzureRmVirtualMachineOsProfileLinuxConfiguration(config *compute.LinuxConfiguration) []interface{} {
|
||||||
result := map[string]interface{}{
|
|
||||||
"disable_password_authentication": *config.DisablePasswordAuthentication,
|
result := make(map[string]interface{})
|
||||||
}
|
result["disable_password_authentication"] = *config.DisablePasswordAuthentication
|
||||||
|
|
||||||
if config.SSH != nil && len(*config.SSH.PublicKeys) > 0 {
|
if config.SSH != nil && len(*config.SSH.PublicKeys) > 0 {
|
||||||
ssh_keys := make([]map[string]interface{}, 0, len(*config.SSH.PublicKeys))
|
ssh_keys := make([]map[string]interface{}, len(*config.SSH.PublicKeys))
|
||||||
for _, i := range *config.SSH.PublicKeys {
|
for _, i := range *config.SSH.PublicKeys {
|
||||||
key := make(map[string]interface{})
|
key := make(map[string]interface{})
|
||||||
key["name"] = *i.Path
|
key["path"] = *i.Path
|
||||||
|
|
||||||
if i.KeyData != nil {
|
if i.KeyData != nil {
|
||||||
key["key_data"] = *i.KeyData
|
key["key_data"] = *i.KeyData
|
||||||
|
@ -910,7 +898,7 @@ func expandAzureRmVirtualMachineOsProfileLinuxConfig(d *schema.ResourceData) (*c
|
||||||
DisablePasswordAuthentication: &disablePasswordAuth,
|
DisablePasswordAuthentication: &disablePasswordAuth,
|
||||||
}
|
}
|
||||||
|
|
||||||
linuxKeys := linuxConfig["ssh_keys"].(*schema.Set).List()
|
linuxKeys := linuxConfig["ssh_keys"].([]interface{})
|
||||||
sshPublicKeys := make([]compute.SSHPublicKey, 0, len(linuxKeys))
|
sshPublicKeys := make([]compute.SSHPublicKey, 0, len(linuxKeys))
|
||||||
for _, key := range linuxKeys {
|
for _, key := range linuxKeys {
|
||||||
sshKey := key.(map[string]interface{})
|
sshKey := key.(map[string]interface{})
|
||||||
|
|
|
@ -177,6 +177,8 @@ For more information on the different example configurations, please check out t
|
||||||
* `disable_password_authentication` - (Required) Specifies whether password authentication should be disabled.
|
* `disable_password_authentication` - (Required) Specifies whether password authentication should be disabled.
|
||||||
* `ssh_keys` - (Optional) Specifies a collection of `path` and `key_data` to be placed on the virtual machine.
|
* `ssh_keys` - (Optional) Specifies a collection of `path` and `key_data` to be placed on the virtual machine.
|
||||||
|
|
||||||
|
~> **Note:** Please note that the only allowed `path` is `/home/<username>/.ssh/authorized_keys` due to a limitation of Azure_
|
||||||
|
|
||||||
`os_profile_secrets` supports the following:
|
`os_profile_secrets` supports the following:
|
||||||
|
|
||||||
* `source_vault_id` - (Required) Specifies the key vault to use.
|
* `source_vault_id` - (Required) Specifies the key vault to use.
|
||||||
|
|
Loading…
Reference in New Issue