-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding Azure Storage module (#638)
* storage module * update custom error * move unit test update prefix * rm azure ref * refactor test * chg docs * chg comment * formatting * add comment * cleanup nits * chg 4 consistency * mv comments * refactor pattern * terraform * fix dns method * fix pin comments. * Fix pin issues. * spelling. * Add doc ref. * address PR comments Co-authored-by: wmattlong <[email protected]> Co-authored-by: richard guthrie <[email protected]> Co-authored-by: richard guthrie <[email protected]> Co-authored-by: Richard Guthrie <[email protected]> Co-authored-by: Hadwa Abdelhalem <[email protected]>
- Loading branch information
1 parent
fd8775e
commit 1a5b3ae
Showing
7 changed files
with
528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Terraform Azure Storage Example | ||
|
||
This folder contains a simple Terraform module that deploys resources in [Azure](https://azure.microsoft.com/) to demonstrate | ||
how you can use TerraTest to write automated tests for your Azure Terraform code. This module deploys a | ||
Storage Account. | ||
|
||
- An [Azure Storage Account](https://azure.microsoft.com/services/storage/) that gives the module the following: | ||
- [Stock Account Name](https://azure.microsoft.com/services/storage/) with the value specified in the `storage_account_name` output variable. | ||
- [Storage Account Tier](https://azure.microsoft.com/services/storage/) with the value specified in the `"storage_account_account_tier` output variable. | ||
- [Storage Account Kind](https://azure.microsoft.com/services/storage/) with the value specified in the `"storage_account_account_kind` output variable. | ||
- [Storage Container](https://azure.microsoft.com/services/storage/) with the value specified in the `"storage_container_name` output variable. | ||
|
||
Check out [test/azure/terraform_azure_storage_example_test.go](/test/azure/terraform_azure_storage_example_test.go) to see how you can write | ||
automated tests for this module. | ||
|
||
Note that the Storage Account in this module don't actually do anything; it just runs the resources for | ||
demonstration purposes. | ||
|
||
**WARNING**: This module and the automated tests for it deploy real resources into your Azure account which can cost you | ||
money. The resources are all part of the [Azure Free Account](https://azure.microsoft.com/free/), so if you haven't used that up, | ||
it should be free, but you are completely responsible for all Azure charges. | ||
|
||
## Running this module manually | ||
|
||
1. Sign up for [Azure](https://azure.microsoft.com/) | ||
1. Configure your Azure credentials using one of the [supported methods for Azure CLI | ||
tools](https://docs.microsoft.com/cli/azure/azure-cli-configuration?view=azure-cli-latest) | ||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH` | ||
1. Ensure [environment variables](../README.md#review-environment-variables) are available | ||
1. Run `terraform init` | ||
1. Run `terraform apply` | ||
1. When you're done, run `terraform destroy` | ||
|
||
## Running automated tests against this module | ||
|
||
1. Sign up for [Azure](https://azure.microsoft.com/) | ||
1. Configure your Azure credentials using one of the [supported methods for Azure CLI | ||
tools](https://docs.microsoft.com/cli/azure/azure-cli-configuration?view=azure-cli-latest) | ||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH` | ||
1. Configure your TerraTest [Go test environment](../README.md) | ||
1. `cd test/azure` | ||
1. `go build terraform_azure_storage_example_test.go` | ||
1. `go test -v -run TestTerraformAzureStorageExample` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# DEPLOY A STORAGE ACCOUNT SET | ||
# This is an example of how to deploy a Storage Account. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# See test/azure/terraform_azure_storage_example_test.go for how to write automated tests for this code. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
provider "azurerm" { | ||
version = "~> 2.20" | ||
features {} | ||
} | ||
|
||
# PIN TERRAFORM VERSION | ||
|
||
terraform { | ||
# This module is now only being tested with Terraform 0.13.x. However, to make upgrading easier, we are setting | ||
# 0.12.26 as the minimum version, as that version added support for required_providers with source URLs, making it | ||
# forwards compatible with 0.13.x code. | ||
required_version = ">= 0.12.26" | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# DEPLOY A RESOURCE GROUP | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
resource "azurerm_resource_group" "resource_group" { | ||
name = "terratest-storage-rg-${var.postfix}" | ||
location = var.location | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# DEPLOY A STORAGE ACCOUNT | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
resource "azurerm_storage_account" "storage_account" { | ||
name = "storage${var.postfix}" | ||
resource_group_name = azurerm_resource_group.resource_group.name | ||
location = azurerm_resource_group.resource_group.location | ||
account_kind = var.storage_account_kind | ||
account_tier = var.storage_account_tier | ||
account_replication_type = var.storage_replication_type | ||
} | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# ADD A CONTAINER TO THE STORAGE ACCOUNT | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
resource "azurerm_storage_container" "container" { | ||
name = "container1" | ||
storage_account_name = azurerm_storage_account.storage_account.name | ||
container_access_type = var.container_access_type | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "resource_group_name" { | ||
value = azurerm_resource_group.resource_group.name | ||
} | ||
|
||
output "storage_account_name" { | ||
value = azurerm_storage_account.storage_account.name | ||
} | ||
|
||
output "storage_account_account_tier" { | ||
value = azurerm_storage_account.storage_account.account_tier | ||
} | ||
|
||
output "storage_account_account_kind" { | ||
value = azurerm_storage_account.storage_account.account_kind | ||
} | ||
|
||
output "storage_container_name" { | ||
value = azurerm_storage_container.container.name | ||
} |
56 changes: 56 additions & 0 deletions
56
examples/azure/terraform-azure-storage-example/variables.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
# ENVIRONMENT VARIABLES | ||
# Define these secrets as environment variables | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# ARM_CLIENT_ID | ||
# ARM_CLIENT_SECRET | ||
# ARM_SUBSCRIPTION_ID | ||
# ARM_TENANT_ID | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# REQUIRED PARAMETERS | ||
# You must provide a value for each of these parameters. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
# --------------------------------------------------------------------------------------------------------------------- | ||
# OPTIONAL PARAMETERS | ||
# These parameters have reasonable defaults. | ||
# --------------------------------------------------------------------------------------------------------------------- | ||
|
||
variable "location" { | ||
description = "The location to set for the storage account." | ||
type = string | ||
default = "East US" | ||
} | ||
|
||
variable "storage_account_kind" { | ||
description = "The kind of storage account to set" | ||
type = string | ||
default = "StorageV2" | ||
} | ||
|
||
variable "storage_account_tier" { | ||
description = "The tier of storage account to set" | ||
type = string | ||
default = "Standard" | ||
} | ||
|
||
variable "storage_replication_type" { | ||
description = "The replication type of storage account to set" | ||
type = string | ||
default = "GRS" | ||
} | ||
|
||
variable "container_access_type" { | ||
description = "The replication type of storage account to set" | ||
type = string | ||
default = "private" | ||
} | ||
|
||
variable "postfix" { | ||
description = "A postfix string to centrally mitigate resource name collisions" | ||
type = string | ||
default = "resource" | ||
} | ||
|
Oops, something went wrong.