diff --git a/.terraform-docs.yml b/.terraform-docs.yml new file mode 100644 index 0000000..bf47c65 --- /dev/null +++ b/.terraform-docs.yml @@ -0,0 +1,5 @@ +formatter: markdown document +output: + file: "README.md" +settings: + anchor: false diff --git a/README.md b/README.md new file mode 100644 index 0000000..e7f4a98 --- /dev/null +++ b/README.md @@ -0,0 +1,90 @@ +# Terraform state management (for Azure) + +## Introduction + +This module manages storage for Terraform states and is usually used in the Terraform "state" module as a base +for other modules' backend configuration. + +## Usage + +Instantiate the module by calling it from Terraform like this: + +```hcl +module "state" { + source = "dodevops/state/azure" + version = "" +} +``` + + +## Requirements + +No requirements. + +## Providers + +The following providers are used by this module: + +- azurerm + +## Modules + +No modules. + +## Resources + +The following resources are used by this module: + +- [azurerm_storage_account.storage-account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) (resource) +- [azurerm_storage_blob.storage-blob](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_blob) (resource) +- [azurerm_storage_container.storage-container](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_container) (resource) + +## Required Inputs + +The following input variables are required: + +### location + +Description: The azure location used for azure + +Type: `string` + +### project + +Description: Three letter project key + +Type: `string` + +### resource\_group + +Description: Name of the resource group to use + +Type: `string` + +### size + +Description: Size of state blob in bytes + +Type: `string` + +### stage + +Description: Name of the stage for this state + +Type: `string` + +## Optional Inputs + +No optional inputs. + +## Outputs + +No outputs. + + +## Development + +Use [terraform-docs](https://terraform-docs.io/) to generate the API documentation by running + + terraform fmt . + terraform-docs . diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..123c296 --- /dev/null +++ b/main.tf @@ -0,0 +1,26 @@ +# Azure Storage blob for state storage + +resource "azurerm_storage_account" "storage-account" { + name = "${lower(var.project)}${lower(var.stage)}stateacc" + resource_group_name = var.resource_group + location = var.location + account_tier = "Standard" + account_replication_type = "ZRS" + enable_https_traffic_only = false +} + +resource "azurerm_storage_container" "storage-container" { + name = "${lower(var.project)}${lower(var.stage)}statecont" + storage_account_name = azurerm_storage_account.storage-account.name + container_access_type = "private" +} + +resource "azurerm_storage_blob" "storage-blob" { + name = "${lower(var.project)}${lower(var.stage)}stateblob" + + storage_account_name = azurerm_storage_account.storage-account.name + storage_container_name = azurerm_storage_container.storage-container.name + + type = "Block" + size = var.size +} diff --git a/vars.tf b/vars.tf new file mode 100644 index 0000000..09d3c27 --- /dev/null +++ b/vars.tf @@ -0,0 +1,24 @@ +variable "project" { + type = string + description = "Three letter project key" +} + +variable "stage" { + type = string + description = "Name of the stage for this state" +} + +variable "location" { + type = string + description = "The azure location used for azure" +} + +variable "resource_group" { + type = string + description = "Name of the resource group to use" +} + +variable "size" { + type = string + description = "Size of state blob in bytes" +}