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

Add Managed Service Identity (MSI) support to VM Scale Sets #1018

Merged
merged 10 commits into from Apr 4, 2018

Conversation

day-jeff
Copy link
Contributor

This builds on earlier work enabling MSI for VMs. Adds the identity attribute and principal_id property to the VM scale set resource.

@tombuildsstuff tombuildsstuff added enhancement service/vmss Virtual Machine Scale Sets labels Mar 22, 2018
@@ -803,6 +835,22 @@ func resourceArmVirtualMachineScaleSetDelete(d *schema.ResourceData, meta interf
return nil
}

func flattenAzureRmVirtualMachineScaleSetIdentity(identity *compute.VirtualMachineScaleSetIdentity) []interface{} {
log.Printf("[DEBUG] entered flattenAzureRmVirtualMachineScaleSetIdentity")
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, will do.

Copy link
Member

@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 @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")
Copy link
Member

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?

Copy link
Contributor Author

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")
Copy link
Member

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?

Copy link
Contributor Author

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 = "{}"
Copy link
Member

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?

Copy link
Contributor Author

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.
Copy link
Member

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

Copy link
Contributor Author

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": {
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Contributor Author

@day-jeff day-jeff left a 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.
Copy link
Contributor Author

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")
Copy link
Contributor Author

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")
Copy link
Contributor Author

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 = "{}"
Copy link
Contributor Author

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.

@day-jeff
Copy link
Contributor Author

All review comments addressed. Ready for round 2. :)

Copy link
Member

@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 @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))
Copy link
Member

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

Copy link
Contributor Author

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),
Copy link
Member

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"),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@day-jeff
Copy link
Contributor Author

More good changes, Tom. Thx for the reviews.

--Jeff

Copy link
Member

@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 @dawg89

Thanks for pushing the latest changes - this now LGTM 👍 I'll kick off the test suite now :)

Thanks!

@tombuildsstuff
Copy link
Member

@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 :)

@tombuildsstuff
Copy link
Member

tombuildsstuff commented Apr 4, 2018

All VM tests before the previous commit:

screen shot 2018-04-04 at 13 36 06

The final commit fixes the broken test:

screen shot 2018-04-04 at 13 35 59

This is now good to merge 👍 - thanks for this PR @dawg89 :)

@tombuildsstuff tombuildsstuff merged commit 615d89a into hashicorp:master Apr 4, 2018
tombuildsstuff added a commit that referenced this pull request Apr 4, 2018
@herrkunstler
Copy link

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)?

@ghost
Copy link

ghost commented Mar 31, 2020

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 and limited conversation to collaborators Mar 31, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement service/vmss Virtual Machine Scale Sets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants