-
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
Add Managed Service Identity (MSI) support to VM Scale Sets #1018
Conversation
…tually identical to recent MSI support for stand-alone VMs
@@ -803,6 +835,22 @@ func resourceArmVirtualMachineScaleSetDelete(d *schema.ResourceData, meta interf | |||
return nil | |||
} | |||
|
|||
func flattenAzureRmVirtualMachineScaleSetIdentity(identity *compute.VirtualMachineScaleSetIdentity) []interface{} { | |||
log.Printf("[DEBUG] entered flattenAzureRmVirtualMachineScaleSetIdentity") |
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.
can we remove this debug line?
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.
Yep, will do.
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.
hey @dawg89
Thanks for this PR - I've taken a look through and left some comments inline but this is off to a good start; if we can fix up the minor issues and add an acceptance test then this should be good to merge :)
Thanks!
log.Printf("[DEBUG] attempting to enable MSI") | ||
scaleSetParams.Identity = expandAzureRmVirtualMachineScaleSetIdentity(d) | ||
} else { | ||
log.Printf("[DEBUG] MSI failed") |
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.
can we remove the unnecessary else statement here?
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.
done
@@ -639,6 +662,13 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf | |||
Zones: zones, | |||
} | |||
|
|||
if _, ok := d.GetOk("identity"); ok { | |||
log.Printf("[DEBUG] attempting to enable MSI") |
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.
could we remove this log message?
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.
done
type_handler_version = "1.0" | ||
auto_upgrade_minor_version = true | ||
settings = "{\"port\": 50342}" | ||
protected_settings = "{}" |
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 may be wrong, but I think we can omit this if it's empty?
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.
Tested and removed both auto_upgrade_minor_version & protected_settings.
@@ -270,6 +270,41 @@ The following arguments are supported: | |||
* `tier` - (Optional) Specifies the tier of virtual machines in a scale set. Possible values, `standard` or `basic`. | |||
* `capacity` - (Required) Specifies the number of virtual machines in the scale set. | |||
|
|||
`identity` supports the following: | |||
|
|||
* `type` - (Required) Specifies the identity type of the virtual machine. The only allowable value is `SystemAssigned`. To enable Managed Service Identity (MSI) on all machines in the scale set, an extension with the type "ManagedIdentityExtensionForWindows" or "ManagedIdentityExtensionForLinux" must also be added. The scale set's Service Principal ID (SPN) can be retrieved after the scale set has been created. |
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.
of the virtual machine
-> of the virtual machine scale set
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
@@ -37,6 +37,29 @@ func resourceArmVirtualMachineScaleSet() *schema.Resource { | |||
|
|||
"zones": zonesSchema(), | |||
|
|||
"identity": { |
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.
can we add an acceptance test covering this use-case?
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.
Done
- Removed debug logging statements and some related code - Removed superfluous lines from the example HCL - Copy edit to readme text - Added acceptance test
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.
Great review, Tom. Thanks!
@@ -270,6 +270,41 @@ The following arguments are supported: | |||
* `tier` - (Optional) Specifies the tier of virtual machines in a scale set. Possible values, `standard` or `basic`. | |||
* `capacity` - (Required) Specifies the number of virtual machines in the scale set. | |||
|
|||
`identity` supports the following: | |||
|
|||
* `type` - (Required) Specifies the identity type of the virtual machine. The only allowable value is `SystemAssigned`. To enable Managed Service Identity (MSI) on all machines in the scale set, an extension with the type "ManagedIdentityExtensionForWindows" or "ManagedIdentityExtensionForLinux" must also be added. The scale set's Service Principal ID (SPN) can be retrieved after the scale set has been created. |
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
@@ -639,6 +662,13 @@ func resourceArmVirtualMachineScaleSetCreate(d *schema.ResourceData, meta interf | |||
Zones: zones, | |||
} | |||
|
|||
if _, ok := d.GetOk("identity"); ok { | |||
log.Printf("[DEBUG] attempting to enable MSI") |
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.
done
log.Printf("[DEBUG] attempting to enable MSI") | ||
scaleSetParams.Identity = expandAzureRmVirtualMachineScaleSetIdentity(d) | ||
} else { | ||
log.Printf("[DEBUG] MSI failed") |
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.
done
type_handler_version = "1.0" | ||
auto_upgrade_minor_version = true | ||
settings = "{\"port\": 50342}" | ||
protected_settings = "{}" |
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.
Tested and removed both auto_upgrade_minor_version & protected_settings.
All review comments addressed. Ready for round 2. :) |
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.
hey @dawg89
Thanks for pushing those updates (and apologies for the delayed re-review here!). I've noted two minor comments but this otherwise LGTM 👍. If we can get those sorted then this should be good to merge :)
Thanks!
@@ -701,6 +728,8 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac | |||
return fmt.Errorf("[DEBUG] Error setting Virtual Machine Scale Set Sku error: %#v", err) | |||
} | |||
|
|||
d.Set("identity", flattenAzureRmVirtualMachineScaleSetIdentity(resp.Identity)) |
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.
can we change this to:
if err := d.Set("identity", flattenAzureRmVirtualMachineScaleSetIdentity(resp.Identity)); err != nil {
return fmt.Error("Error flattening `identity`: %+v", err)
}
this allows any bugs (such as the schema not matching) to be caught
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.
Done
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testCheckAzureRMVirtualMachineScaleSetExists(resourceName), | ||
testCheckAzureRMVirtualMachineScaleSetMSI(resourceName), |
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.
can we remove this function (which checks the API) in favour of checking the value stored in the state (which users will consume)? we can do this via:
resources.TestCheckResourceAttrSet(resourceName, "identity.0.principal_id"),
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.
Done
More good changes, Tom. Thx for the reviews. --Jeff |
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.
hey @dawg89
Thanks for pushing the latest changes - this now LGTM 👍 I'll kick off the test suite now :)
Thanks!
@dawg89 just to let you know that the tests picked up a bug in the tests, so I've pushed a commit to fix this: 03a9c31 - I hope you don't mind :) |
According to https://docs.microsoft.com/en-us/azure/active-directory/managed-service-identity/overview, "MSI VM extension endpoint: http://localhost:50342/oauth2/token (to be deprecated)." Since the extension endpoint is being deprecated, will this provider be updated to support enabling MSI without the extension (see also https://docs.microsoft.com/en-us/azure/active-directory/managed-service-identity/tutorial-linux-vm-access-arm)? |
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 👉 [email protected]. Thanks! |
This builds on earlier work enabling MSI for VMs. Adds the identity attribute and principal_id property to the VM scale set resource.