You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+52-3Lines changed: 52 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,51 @@ This is a terraform module for initializing a terraform state backend in Azure.
3
3
4
4
By default, it creates a resource group named `terraform-state`, a storage account with a unique name, and a container named "terraform-state",
5
5
<!-- BEGIN_TF_DOCS -->
6
+
7
+
## Example usage
8
+
9
+
A common pattern for using this is to create a folder within your terraform IaC project for setting up your environment, such as `/environments/{env_name}/setup`, containing a `main.tf` like:
To execute, first `az login` with an appropriately permissioned Azure account using the Azure CLI. Once logged in, run command `terraform init` within the new `terraform-state` folder. Then, run `terraform plan` to see what will be created. If satisfied with the results, run command `terraform apply`. This will create the appropriate Azure Blob Storage for holding state files for the main project. Azure Blobs are semaphore-locked from concurrent writes automatically. The state file for this remote state terraform script will be stored on the file system. Be sure to capture the results of the output (run `terraform output` to see it again) and copy it into your main Terraform stack variables. It is recommended to alter the name of the key to fit the granularity of separation of concerns that you require.
37
+
38
+
> [!CAUTION]
39
+
> The terraform statefile with an Azure storage account resource will contain the initial storage account access keys. It is best practice to _disable_ access key access in favor of Entra ID authentication for your storage accounts. Do not commit the statefile until either the access keys are removed, rotated, or access keys disabled.
40
+
41
+
Consider adding the following to your parent terraform IaC project `.gitignore` file:
42
+
```
43
+
# .tfstate files
44
+
*.tfstate
45
+
*.tfstate.*
46
+
!environments/*/setup/*.tfstate
47
+
!environments/*/setup/*.tfstate.*
48
+
```
49
+
This will ignore the `.tfstate` file in your project, which will use remote storage, but retain the `.tfstate` for the remote tfstate infrastructure.
50
+
6
51
## Requirements
7
52
8
53
| Name | Version |
@@ -34,11 +79,12 @@ No modules.
34
79
35
80
| Name | Description | Type | Default | Required |
| <aname="input_client_id"></a> [client\_id](#input\_client\_id)| The client ID to use for authenticating to Azure |`string`|`null`| no |
82
+
| <aname="input_client_id"></a> [client\_id](#input\_client\_id)| The client ID to use for authenticating to Azure. Terraform authentication will overwrite this.|`string`|`null`| no |
38
83
| <aname="input_container_name"></a> [container\_name](#input\_container\_name)| The name of the storage container to use for the Terraform state |`string`|`"terraform-state"`| no |
39
84
| <aname="input_location"></a> [location](#input\_location)| The location to use for the Terraform state |`string`|`"centralus"`| no |
40
85
| <aname="input_resource_group_name"></a> [resource\_group\_name](#input\_resource\_group\_name)| The name of the resource group to use for the Terraform state |`string`|`"terraform-state"`| no |
41
-
| <aname="input_storage_account_name"></a> [storage\_account\_name](#input\_storage\_account\_name)| The name of the storage account to use for the Terraform state |`string`|`null`| no |
86
+
| <aname="input_remove_secrets_from_state"></a> [remove\_secrets\_from\_state](#input\_remove\_secrets\_from\_state)| Whether to sanitize tfstate of access keys automatically created on created resources. Actual, assigned keys remain untouched on created assets. |`bool`|`true`| no |
87
+
| <aname="input_storage_account_name"></a> [storage\_account\_name](#input\_storage\_account\_name)| The name of the storage account to use for the Terraform state. Leave blank to let Terraform manage a globally unique name to fit Azure constraints. |`string`|`null`| no |
42
88
| <aname="input_subscription_id"></a> [subscription\_id](#input\_subscription\_id)| The subscription ID to use for the Terraform state |`string`|`null`| no |
43
89
| <aname="input_tenant_id"></a> [tenant\_id](#input\_tenant\_id)| The tenant ID to use for the Terraform state |`string`|`null`| no |
0 commit comments