Skip to content

Commit

Permalink
Initial release (#1)
Browse files Browse the repository at this point in the history
* Initial module release
  • Loading branch information
alfespa17 authored Mar 18, 2022
1 parent 28184d2 commit 97f3236
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]
Copyright 2022 Alfredo España

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
44 changes: 44 additions & 0 deletions README.md
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.
5 changes: 5 additions & 0 deletions local.tf
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])
}
47 changes: 47 additions & 0 deletions main.tf
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"
}
15 changes: 15 additions & 0 deletions output.tf
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
}
14 changes: 14 additions & 0 deletions provider.tf
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 {}
}

23 changes: 23 additions & 0 deletions variables.tf
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"
}

0 comments on commit 97f3236

Please sign in to comment.