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

Sets Azure Storage authentication method from Access Key to Entra User Account #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
This is a terraform module for initializing a terraform state backend in Azure.

By default, it creates a resource group named `terraform-state`, a storage account with a unique name, and a container named "terraform-state",

Azure will not auto-assign sufficient access privilege to your az cli user running terraform automatically. Follow this environment backend module's apply with authenticated:
```
az role assignment create --assignee PRINCIPAL_ID --role "Storage Blob Data Contributor" --scope $(terraform output -raw storage_role_access_scope -state=PATH_TO_TFSTATE)
```
While the az role assignment is very quick, it may take up to ten minutes for your principal to gain role access to this resource (see [learn.microsoft.com/en-us/azure/storage/blobs/assign-azure-role-data-access](https://learn.microsoft.com/en-us/azure/storage/blobs/assign-azure-role-data-access?tabs=azure-cli#:~:text=When%20you%20assign%20roles%20or%20remove%20role%20assignments%2C%20it%20can%20take%20up%20to%2010%20minutes%20for%20changes%20to%20take%20effect.)).

<!-- BEGIN_TF_DOCS -->
## Requirements

Expand Down
6 changes: 5 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ provider "azurerm" {
storage_use_azuread = true
}


resource "random_string" "storage_account_name" {
length = 14
special = false
Expand All @@ -26,6 +25,7 @@ resource "random_string" "storage_account_name" {

locals {
storage_account_name = var.storage_account_name == null ? "tfstate00${random_string.storage_account_name.result}" : var.storage_account_name
tfstate_role_access_scope = "${azurerm_storage_account.tfstate.id}/blobServices/default/containers/tfstate"
}

resource "azurerm_resource_group" "tfstate" {
Expand Down Expand Up @@ -109,3 +109,7 @@ output "storage_account_name" {
output "container_name" {
value = azurerm_storage_container.tfstate.name
}

output "tfstate_role_access_scope" {
value = local.tfstate_role_access_scope
}