-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial module release
- Loading branch information
Showing
7 changed files
with
149 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -1,2 +1,46 @@ | ||
# terraform-azurerm-terrakube-cloud-storage | ||
|
||
Terrakube module to create cloud storage to save the terraform output, state and modules. | ||
|
||
## Parameters | ||
The module will require the following parameters: | ||
- storage_name (default: terrakube) | ||
- storage_location | ||
- storage_tier (Standard or Premium) | ||
- storage_replication_type (LRS, GRS, RAGRS, ZRS, GZRS and RAGZRS) | ||
|
||
## Output Values | ||
|
||
The module will output the following values: | ||
|
||
- Storage account name | ||
- Storage account resource group | ||
- Storage account access key | ||
|
||
Example: | ||
|
||
```bash | ||
terraform apply --var "storage_name=terrakube" \ | ||
--var "storage_location=eastus2" \ | ||
--var "storage_tier=Standard" \ | ||
--var "storage_replication_type=LRS" \ | ||
--var "cors_domain=ui.terrakube.docker.internal"; | ||
|
||
Apply complete! Resources: 0 added, 0 changed, 0 destroyed. | ||
|
||
Outputs: | ||
|
||
storage_account_key = <sensitive> | ||
storage_account_name = "XXXX" | ||
storage_rg = "XXXXXX" | ||
``` | ||
|
||
To see the value for the storage account access key you can use the following command: | ||
|
||
```bash | ||
terraform console | ||
nonsensitive(azurerm_storage_account.storage.primary_access_key) | ||
"XXXXXXXXXXXXXXXXXXXX" | ||
``` | ||
|
||
> These values will be used to setup the Terrakube Executor storage settings. |
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,5 @@ | ||
locals { | ||
storage_name = lower(format("%s%s", var.storage_name, random_string.name_suffix.result)) | ||
storage_name_rg = lower(format("%s-%s-rg", var.storage_name, random_string.name_suffix.result)) | ||
allowed_origins = tolist([var.cors_domain]) | ||
} |
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,47 @@ | ||
resource "random_string" "name_suffix" { | ||
length = 5 | ||
special = false | ||
lower = true | ||
} | ||
|
||
resource "azurerm_resource_group" "rg" { | ||
name = local.storage_name_rg | ||
location = var.storage_location | ||
} | ||
|
||
resource "azurerm_storage_account" "storage" { | ||
name = local.storage_name | ||
resource_group_name = azurerm_resource_group.rg.name | ||
location = azurerm_resource_group.rg.location | ||
account_tier = "Standard" | ||
account_replication_type = "LRS" | ||
allow_blob_public_access = true | ||
|
||
blob_properties { | ||
cors_rule{ | ||
allowed_headers = ["*"] | ||
allowed_methods = ["GET","OPTIONS"] | ||
allowed_origins = local.allowed_origins | ||
exposed_headers = ["*"] | ||
max_age_in_seconds = 3600 | ||
} | ||
} | ||
} | ||
|
||
resource "azurerm_storage_container" "registry" { | ||
name = "registry" | ||
storage_account_name = azurerm_storage_account.storage.name | ||
container_access_type = "blob" | ||
} | ||
|
||
resource "azurerm_storage_container" "tfoutput" { | ||
name = "tfoutput" | ||
storage_account_name = azurerm_storage_account.storage.name | ||
container_access_type = "private" | ||
} | ||
|
||
resource "azurerm_storage_container" "tfstate" { | ||
name = "tfstate" | ||
storage_account_name = azurerm_storage_account.storage.name | ||
container_access_type = "private" | ||
} |
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,15 @@ | ||
output "storage_rg" { | ||
value = azurerm_resource_group.rg.name | ||
description = "Azure storage account resource group" | ||
} | ||
|
||
output "storage_account_name" { | ||
value = azurerm_storage_account.storage.name | ||
description = "Azure storage account name" | ||
} | ||
|
||
output "storage_account_key" { | ||
value = azurerm_storage_account.storage.primary_access_key | ||
description = "Azure storage account access key" | ||
sensitive = true | ||
} |
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,14 @@ | ||
terraform { | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "=2.83.0" | ||
} | ||
} | ||
} | ||
|
||
# Configure the Microsoft Azure Provider | ||
provider "azurerm" { | ||
features {} | ||
} | ||
|
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,23 @@ | ||
|
||
variable "storage_name" { | ||
type = string | ||
default = "terrakube" | ||
} | ||
|
||
variable "storage_location" { | ||
type = string | ||
default = "eastus2" | ||
} | ||
|
||
variable "storage_tier" { | ||
type = string | ||
} | ||
|
||
variable "storage_replication_type" { | ||
type = string | ||
} | ||
|
||
variable "cors_domain" { | ||
type = string | ||
description = "CORS for storage account Example: ui.terrakube.docker.internal" | ||
} |