Skip to content

Commit

Permalink
Add owner permissions on current subscription (#3)
Browse files Browse the repository at this point in the history
* Add owner permissions on current subscription

Signed-off-by: Roman Schwarz <[email protected]>

* Disable Blob public access on Storage Account

Signed-off-by: Roman Schwarz <[email protected]>

* Disable overprovisioning on virtual machine scale set

Signed-off-by: Roman Schwarz <[email protected]>

* Add mocked value for subscriptions

Signed-off-by: Roman Schwarz <[email protected]>

---------

Signed-off-by: Roman Schwarz <[email protected]>
  • Loading branch information
rswrz authored Nov 13, 2024
1 parent 7ea14ec commit b8054af
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
data "azurerm_client_config" "current" {}

data "azurerm_subscription" "managed_by_launchpad" {
for_each = toset(var.subscription_ids)
for_each = toset(concat(var.subscription_ids, [data.azurerm_client_config.current.subscription_id]))
subscription_id = each.key
}

Expand Down
4 changes: 2 additions & 2 deletions r-identity.tf
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ resource "azurerm_role_assignment" "management_group_owner" {
}

resource "azurerm_role_assignment" "subscription_owner" {
for_each = toset(var.subscription_ids)
for_each = data.azurerm_subscription.managed_by_launchpad

principal_id = azurerm_user_assigned_identity.this.principal_id
role_definition_name = "Owner"
scope = data.azurerm_subscription.managed_by_launchpad[each.key].id
scope = each.value.id
}

resource "azurerm_role_assignment" "resource_specific" {
Expand Down
1 change: 1 addition & 0 deletions r-storage-account.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ resource "azurerm_storage_account" "this" {
account_tier = "Standard"
account_replication_type = "RAGRS"

allow_nested_items_to_be_public = false
cross_tenant_replication_enabled = false
default_to_oauth_authentication = true
https_traffic_only_enabled = true
Expand Down
2 changes: 1 addition & 1 deletion r-virtual-machine-scale-set.tf
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "this" {
upgrade_mode = "Automatic"
secure_boot_enabled = false
vtpm_enabled = false
overprovision = true
overprovision = false

# trigger instance update
custom_data = base64encode("#cloud-config\n#${sha256(local.github_runner_script)}")
Expand Down
11 changes: 9 additions & 2 deletions tests/examples/mocks/main.tfmock.hcl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
mock_data "azurerm_client_config" {
defaults = {
tenant_id = "00000000-0000-0000-0000-000000000000"
object_id = "00000000-0000-0000-0000-000000000000"
object_id = "00000000-0000-0000-0000-000000000000"
subscription_id = "00000000-0000-0000-0000-000000000000"
tenant_id = "00000000-0000-0000-0000-000000000000"
}
}

Expand All @@ -12,6 +13,12 @@ mock_data "azurerm_management_group" {
}
}

mock_data "azurerm_subscription" {
defaults = {
id = "/subscriptions/00000000-0000-0000-0000-000000000000"
}
}

mock_resource "azurerm_user_assigned_identity" {
defaults = {
id = "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/RG-MOCK/providers/Microsoft.ManagedIdentity/userAssignedIdentities/ID-MOCK"
Expand Down

0 comments on commit b8054af

Please sign in to comment.