-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstorage_account.tf
39 lines (31 loc) · 1.31 KB
/
storage_account.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
locals {
terraform_state_aad_group = toset(length(var.terraform_state_aad_group) > 0 ? [var.terraform_state_aad_group] : [])
}
data "azuread_group" "terraform_state_aad_group" {
for_each = local.terraform_state_aad_group
name = each.value
}
data "azurerm_storage_account" "state" {
name = var.storage_account_name
resource_group_name = data.azurerm_resource_group.state.name
}
data "azurerm_storage_container" "tfstate" {
name = var.container_name
storage_account_name = data.azurerm_storage_account.state.name
}
//=============================================================
resource "azurerm_storage_container" "bootstrap" {
name = "bootstrap"
storage_account_name = data.azurerm_storage_account.state.name
}
resource "azurerm_role_assignment" "terraform_state_owner" {
scope = data.azurerm_storage_account.state.id
role_definition_name = "Owner"
principal_id = data.azurerm_client_config.current.object_id
}
resource "azurerm_role_assignment" "terraform_state_aad_group" {
for_each = local.terraform_state_aad_group
scope = data.azurerm_storage_account.state.id
role_definition_name = "Storage Blob Data Contributor"
principal_id = data.azuread_group.terraform_state_aad_group[each.value].object_id
}