Skip to content

Commit

Permalink
feat: Add optional resource group module (#4)
Browse files Browse the repository at this point in the history
* feat: Add optional resource group module

* fix: Use resource group module output for resrouce group name

* docs: Fix contributors block
  • Loading branch information
jakubigla authored Aug 9, 2022
1 parent 3ba5881 commit f79d171
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 25 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Terraform Module to create an Azure storage account with a set of containers (an
```terraform
module "resource_group" {
source = "getindata/resource-group/azurerm"
version = "1.1.0"
version = "1.2.0"
context = module.this.context
name = "example-rg"
Expand Down Expand Up @@ -69,6 +69,7 @@ module "storage_account" {
| <a name="input_container_soft_delete_retention_days"></a> [container\_soft\_delete\_retention\_days](#input\_container\_soft\_delete\_retention\_days) | Specifies the number of days that the blob should be retained, between `1` and `365` days. Defaults to `7` | `number` | `7` | no |
| <a name="input_containers_list"></a> [containers\_list](#input\_containers\_list) | List of containers to create and their access levels. | `list(object({ name = string, access_type = string }))` | `[]` | no |
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
| <a name="input_create_resource_group"></a> [create\_resource\_group](#input\_create\_resource\_group) | Whether to create resource group and use it for storage resources | `bool` | `false` | no |
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
| <a name="input_diagnostics_log_analytics_workspace_id"></a> [diagnostics\_log\_analytics\_workspace\_id](#input\_diagnostics\_log\_analytics\_workspace\_id) | Resource ID of the log analytics workspace. Used for diagnostics logs and metrics. If not provided, diagnostics will not be enabled | `string` | `null` | no |
Expand All @@ -84,7 +85,7 @@ module "storage_account" {
| <a name="input_labels_as_tags"></a> [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.<br>Default is to include all labels.<br>Tags with empty values will not be included in the `tags` output.<br>Set to `[]` to suppress all generated tags.<br>**Notes:**<br> The value of the `name` tag, if included, will be the `id`, not the `name`.<br> Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be<br> changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | <pre>[<br> "default"<br>]</pre> | no |
| <a name="input_last_access_time_enabled"></a> [last\_access\_time\_enabled](#input\_last\_access\_time\_enabled) | Is the last access time based tracking enabled? Default to `false` | `bool` | `false` | no |
| <a name="input_lifecycles"></a> [lifecycles](#input\_lifecycles) | Configure Azure Storage lifecycles | `list(object({ prefix_match = set(string), tier_to_cool_after_days = number, tier_to_archive_after_days = number, delete_after_days = number, snapshot_delete_after_days = number }))` | `[]` | no |
| <a name="input_location"></a> [location](#input\_location) | Azure datacenter location, where resources will be deployed | `string` | n/a | yes |
| <a name="input_location"></a> [location](#input\_location) | Azure datacenter location, where resources will be deployed | `string` | `null` | no |
| <a name="input_managed_identity_ids"></a> [managed\_identity\_ids](#input\_managed\_identity\_ids) | A list of User Managed Identity ID's which should be assigned to the Linux Virtual Machine. | `list(string)` | `null` | no |
| <a name="input_managed_identity_type"></a> [managed\_identity\_type](#input\_managed\_identity\_type) | The type of Managed Identity which should be assigned to the Linux Virtual Machine. Possible values are `SystemAssigned`, `UserAssigned` and `SystemAssigned, UserAssigned` | `string` | `null` | no |
| <a name="input_min_tls_version"></a> [min\_tls\_version](#input\_min\_tls\_version) | The minimum supported TLS version for the storage account | `string` | `"TLS1_2"` | no |
Expand All @@ -111,6 +112,7 @@ module "storage_account" {
| Name | Source | Version |
|------|--------|---------|
| <a name="module_diagnostic_settings"></a> [diagnostic\_settings](#module\_diagnostic\_settings) | claranet/diagnostic-settings/azurerm | 5.0.0 |
| <a name="module_resource_group"></a> [resource\_group](#module\_resource\_group) | getindata/resource-group/azurerm | 1.1.0 |
| <a name="module_storage"></a> [storage](#module\_storage) | kumarvna/storage/azurerm | 2.5.0 |
| <a name="module_this"></a> [this](#module\_this) | cloudposse/label/null | 0.25.0 |
| <a name="module_this_private_endpoint_label"></a> [this\_private\_endpoint\_label](#module\_this\_private\_endpoint\_label) | cloudposse/label/null | 0.25.0 |
Expand Down Expand Up @@ -157,8 +159,7 @@ Apache 2 Licensed. See [LICENSE](LICENSE) for full details.

## AUTHORS

<!--- Replace repository name -->
<a href="https://github.com/getindata/REPO_NAME/graphs/contributors">
<a href="https://github.com/getindata/terraform-azurerm-storage-account/graphs/contributors">
<img src="https://contrib.rocks/image?repo=getindata/terraform-module-template" />
</a>

Expand Down
16 changes: 3 additions & 13 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
module "resource_group" {
source = "getindata/resource-group/azurerm"
version = "1.1.0"
context = module.this.context

name = "example-rg"
location = "West Europe"
}

module "storage_account" {
source = "../.."
context = module.this.context

name = "example"

location = module.resource_group.location
resource_group_name = module.resource_group.name
create_resource_group = true
resource_group_name = "sample-rg"
location = "West Europe"

# Container lists with access_type to create
containers_list = [
Expand All @@ -23,6 +15,4 @@ module "storage_account" {
access_type = "private"
}
]

depends_on = [module.resource_group]
}
9 changes: 6 additions & 3 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ locals {
ip_rules = []
} : var.network_rules)

resource_group_name = one(module.storage[*].resource_group_name)
storage_account_id = one(module.storage[*].storage_account_id)
storage_account_name = one(module.storage[*].storage_account_name)
resource_group_name = var.create_resource_group ? one(module.resource_group[*].name) : var.resource_group_name
resource_group_location = var.create_resource_group ? one(module.resource_group[*].location) : one(module.storage[*].resource_group_location)

storage_account_id = one(module.storage[*].storage_account_id)
storage_account_name = one(module.storage[*].storage_account_name)
storage_account_location = one(module.storage[*].resource_group_location)
}
21 changes: 17 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
module "resource_group" {
source = "getindata/resource-group/azurerm"
version = "1.1.0"

context = module.this.context

name = var.resource_group_name
location = var.location

count = module.this.enabled && var.create_resource_group ? 1 : 0
}

module "storage" {
source = "kumarvna/storage/azurerm"
version = "2.5.0"

count = module.this.enabled ? 1 : 0

create_resource_group = false
resource_group_name = var.resource_group_name
location = var.location
resource_group_name = local.resource_group_name
storage_account_name = local.name_from_descriptor
account_kind = var.account_kind
skuname = var.skuname
Expand All @@ -28,6 +39,8 @@ module "storage" {
managed_identity_ids = var.managed_identity_ids

tags = module.this.tags

depends_on = [module.resource_group]
}

resource "azurerm_role_assignment" "this" {
Expand Down Expand Up @@ -71,9 +84,9 @@ module "this_private_endpoint_label" {
resource "azurerm_private_endpoint" "this" {
count = module.this.enabled && var.private_endpoint_enabled ? 1 : 0

location = var.location
location = local.resource_group_location
name = local.private_endpoint_name_from_descriptor
resource_group_name = var.resource_group_name
resource_group_name = local.resource_group_name
subnet_id = var.private_endpoint_subnet_id

private_service_connection {
Expand Down
9 changes: 8 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ variable "resource_group_name" {
}

variable "location" {
type = string
description = "Azure datacenter location, where resources will be deployed"
default = null
type = string
}

variable "create_resource_group" {
description = "Whether to create resource group and use it for storage resources"
default = false
type = bool
}

variable "account_kind" {
Expand Down

0 comments on commit f79d171

Please sign in to comment.