Skip to content

Commit

Permalink
feat: add parameter containerName (#18)
Browse files Browse the repository at this point in the history
* feat: add parameter `containerName`

Create blob container with the specified name. Set previously hard coded value as default to ensure backwards compatability.

* Build Bicep file

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
hknutsen and github-actions[bot] authored Jan 2, 2025
1 parent a50ca43 commit 137ef2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Azure Resource Manager (ARM) template that creates an Azure Storage account to s

- Creates a storage account with the specified name.
- Configures the storage account according to [security recommendations](https://learn.microsoft.com/en-us/azure/storage/blobs/security-recommendations).
- Creates a storage container `tfstate`.
- Creates a blob container with the specified name.
- Grants access to the storage account for specified user, group and service principals.
- Creates a read-only lock to prevent changes to the storage account.

Expand Down Expand Up @@ -83,6 +83,7 @@ Azure Resource Manager (ARM) template that creates an Azure Storage account to s
| Name | Description | Type | Default |
| - | - | - | - |
| `storageAccountName` | The name of the storage account to create. | `string` | |
| `containerName` | The name of the blob container to create. | `string` | `tfstate` |
| `ipRules` | An array of IP addresses or ranges that should be granted access to the storage account. If empty, all IP addresses and ranges will be granted access to the storage account. | `array` | `[]` |
| `principalIds` | An array of object IDs for user, group or service principals that should be granted access to the storage account. | `array` | `[]` |

Expand All @@ -91,7 +92,7 @@ Azure Resource Manager (ARM) template that creates an Azure Storage account to s
| Name | Description | Type |
| - | - | - |
| `storageAccountName` | The name of the storage account that was created. | `string` |
| `containerName` | The name of the storage container that was created. | `string` |
| `containerName` | The name of the blob container that was created. | `string` |

## References

Expand Down
14 changes: 10 additions & 4 deletions azuredeploy.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"_generator": {
"name": "bicep",
"version": "0.32.4.45862",
"templateHash": "6435624962667709005"
"templateHash": "8688306575345230913"
}
},
"parameters": {
Expand All @@ -15,6 +15,12 @@
"description": "The name of the Storage account to create."
}
},
"containerName": {
"type": "string",
"metadata": {
"description": "The name of the blob container to create."
}
},
"ipRules": {
"type": "array",
"defaultValue": [],
Expand All @@ -34,7 +40,7 @@
{
"type": "Microsoft.Storage/storageAccounts/blobServices/containers",
"apiVersion": "2023-05-01",
"name": "[format('{0}/{1}/{2}', parameters('storageAccountName'), 'default', 'tfstate')]",
"name": "[format('{0}/{1}/{2}', parameters('storageAccountName'), 'default', parameters('containerName'))]",
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts/blobServices', parameters('storageAccountName'), 'default')]"
]
Expand Down Expand Up @@ -172,9 +178,9 @@
"containerName": {
"type": "string",
"metadata": {
"description": "The name of the Storage container that was created."
"description": "The name of the blob container that was created."
},
"value": "tfstate"
"value": "[parameters('containerName')]"
}
}
}
7 changes: 5 additions & 2 deletions main.bicep
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@description('The name of the Storage account to create.')
param storageAccountName string

@description('The name of the blob container to create.')
param containerName string

@description('An array of IP addresses or IP ranges that should be allowed to bypass the firewall of the Terraform backend. If empty, the firewall will be disabled.')
param ipRules array = []

Expand Down Expand Up @@ -52,7 +55,7 @@ resource storageAccount 'Microsoft.Storage/storageAccounts@2023-05-01' = {
}

resource container 'containers' = {
name: 'tfstate'
name: containerName
}
}

Expand Down Expand Up @@ -115,5 +118,5 @@ resource lock 'Microsoft.Authorization/locks@2020-05-01' = {
@description('The name of the Storage account that was created.')
output storageAccountName string = storageAccount.name

@description('The name of the Storage container that was created.')
@description('The name of the blob container that was created.')
output containerName string = storageAccount::blobService::container.name

0 comments on commit 137ef2a

Please sign in to comment.