Environment:
Terraform v0.11.11
+ provider.azurerm v1.21.0
+ provider.random v2.0.0
+ provider.template v2.0.0```
Problem:
Attempting to create Managed System Identity for a VM. Here is the code snippet:
###############################################################################
# Create Managed System Identity for VMs
###############################################################################
data "azurerm_subscription" "primary" {}
data "azurerm_builtin_role_definition" "contributor" {
name = "Contributor"
}
resource "azurerm_role_assignment" "contributor" {
name = "[${element(azurerm_virtual_machine.consul.*.id, count.index + 1)}]"
scope = "${var.subscription_id}"
#scope = "${data.azurerm_subscription.primary.id}"
principal_id = "${var.tenant_object_id}"
role_definition_id = "${var.subscription_id}${data.azurerm_builtin_role_definition.contributor.id}"
}
Running terraform apply yields the following error:
Error:
Error: Error applying plan:
1 error(s) occurred:
* azurerm_role_assignment.contributor: 1 error(s) occurred:
* azurerm_role_assignment.contributor: authorization.RoleAssignmentsClient#Create: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="MissingSubscription" Message="The request did not have a subscription or a valid tenant level resource provider."
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
I tried to follow the example described here - https://www.terraform.io/docs/providers/azurerm/r/role_assignment.html, but it looks like if I change my scope back to scope = "${data.azurerm_subscription.primary.id}", it errors out with:
* azurerm_role_assignment.contributor: 1 error(s) occurred:
* azurerm_role_assignment.contributor: authorization.RoleAssignmentsClient#Create: Failure responding to request: StatusCode=405 -- Original Error: autorest/azure: Service returned an error. Status=405 Code="" Message="The requested resource does not support http method 'PUT'."
Changed TF variables to the following:
##############################################################################
# Create Managed System Identity for VMs
###############################################################################
#data "azurerm_subscription" "current" {}
data "azurerm_subscription" "primary" {}
data "azurerm_builtin_role_definition" "contributor" {
name = "Contributor"
}
resource "azurerm_role_assignment" "contributor" {
name = "[${element(azurerm_virtual_machine.consul.*.id, count.index + 1)}]"
scope = "${var.subscription_id}"
principal_id = "${var.tenant_object_id}"
role_definition_id = "${var.subscription_id}${data.azurerm_builtin_role_definition.contributor.id}"
}
...and started getting another set of errors:
* azurerm_role_assignment.contributor: 1 error(s) occurred:
* azurerm_role_assignment.contributor: authorization.RoleAssignmentsClient#Create: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="MissingSubscription" Message="The request did not have a subscription or a valid tenant level resource provider."
Any thoughts?
Thanks!!!!!
Solved with the following setup:
###############################################################################
# Create Managed System Identity for VMs
###############################################################################
data "azurerm_subscription" "primary" {}
resource "azurerm_role_assignment" "Contributor" {
scope = "/subscriptions/${var.subscription_id}"
role_definition_name = "Contributor"
principal_id = "${var.tenant_object_id}"
}
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!
Most helpful comment
Solved with the following setup: