Skip to content

Commit

Permalink
feat: adding virtual machine admin on rg
Browse files Browse the repository at this point in the history
Signed-off-by: Fredrik Klingenberg <[email protected]>
  • Loading branch information
fredrkl committed Nov 16, 2023
1 parent 698b473 commit d6b73f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
31 changes: 16 additions & 15 deletions terraform/modules/bastion/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,17 @@ locals {
azuread_group_object_id = "43f5e30f-0e58-47a1-93e0-7e8342f890b0"
}

# Virtual Machine Administrator login on the entire resource group
data "azurerm_role_definition" "vm_admin" {
name = "Virtual Machine Administrator Login"
}
resource "azurerm_role_assignment" "entire_resource_group" {
scope = var.resource_group.id
role_definition_id = data.azurerm_role_definition.vm_admin.id
principal_id = local.azuread_group_object_id
}

# Bastion
resource "azurerm_public_ip" "bastion" {
name = "example-bastion-pip"
location = var.resource_group.location
Expand All @@ -26,6 +36,7 @@ resource "azurerm_bastion_host" "example" {
copy_paste_enabled = true
}

# Linux VM
resource "azurerm_network_interface" "example" {
name = "example-nic"
location = var.resource_group.location
Expand Down Expand Up @@ -83,15 +94,11 @@ resource "azurerm_virtual_machine_extension" "AADSSHLoginForLinux" {
auto_upgrade_minor_version = true
}

resource "azurerm_role_assignment" "example" {
scope = azurerm_linux_virtual_machine.example.id
role_definition_id = data.azurerm_role_definition.vm_admin.id
principal_id = local.azuread_group_object_id
}

data "azurerm_role_definition" "vm_admin" {
name = "Virtual Machine Administrator Login"
}
#resource "azurerm_role_assignment" "example" {
# scope = azurerm_linux_virtual_machine.example.id
# role_definition_id = data.azurerm_role_definition.vm_admin.id
# principal_id = local.azuread_group_object_id
#}

// Windows VM
resource "azurerm_network_interface" "vm" {
Expand Down Expand Up @@ -143,9 +150,3 @@ resource "azurerm_virtual_machine_extension" "AADLoginForWindows" {
type_handler_version = "1.0"
auto_upgrade_minor_version = true
}

resource "azurerm_role_assignment" "windows_vm_admin" {
scope = azurerm_windows_virtual_machine.vm.id
role_definition_id = data.azurerm_role_definition.vm_admin.id
principal_id = local.azuread_group_object_id
}
1 change: 1 addition & 0 deletions terraform/modules/bastion/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ variable "resource_group" {
type = object({
name = string
location = string
id = string
})
}

Expand Down

0 comments on commit d6b73f4

Please sign in to comment.