Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #91

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 0 additions & 98 deletions .terraform.lock.hcl

This file was deleted.

21 changes: 21 additions & 0 deletions 00_tfstate_storage/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.45.1"
version = "~> 2.68.0"
}
}
}
Expand All @@ -11,15 +11,6 @@ provider "azurerm" {
features {}
}

# NOTE: Needed when storage account uniqueness wants to be automatically achieved
# resource "random_string" "storage_account_name_suffix" {
# length = 8
# upper = false
# number = true
# lower = true
# special = false
# }

resource "azurerm_resource_group" "tfstate_rg" {
name = "${lower(var.project_name)}-${var.tfstate_resource_group_name_suffix}"
location = var.location
Expand All @@ -32,12 +23,6 @@ resource "azurerm_resource_group" "tfstate_rg" {
}

resource "azurerm_storage_account" "tfstate_sa" {
depends_on = [azurerm_resource_group.tfstate_rg]

# 'name' must be unique across the entire Azure service, not just within the resource group.
# 'name' can only consist of lowercase letters and numbers, and must be between 3 and 24 characters long
# NOTE: Uncomment the next line to generate suffix for storage account.
# name = "${lower(var.project_name)}tfstatesa${random_id.storage_account_name_suffix.result}"
name = "${lower(var.project_name)}${var.tfstate_storage_account_name_suffix}"
resource_group_name = azurerm_resource_group.tfstate_rg.name
location = var.location
Expand All @@ -53,7 +38,6 @@ resource "azurerm_storage_account" "tfstate_sa" {
}

resource "azurerm_storage_container" "tfstate_container" {
depends_on = [azurerm_storage_account.tfstate_sa]
name = var.tfstate_container_name
storage_account_name = azurerm_storage_account.tfstate_sa.name
container_access_type = "private"
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
variable "environment" {
type = string
default = "development"
}

variable "location" {
type = string
default = "West Europe"
}

variable "project_name" {
default = "kuksatrng"
type = string
default = "smaddis"
}

variable "tfstate_resource_group_name_suffix" {
type = string
default = "tfstate-rg"
}

# 'name' must be unique across the entire Azure service,
# 'name' must be unique across the entire Azure service,
# not just within the resource group.
# 'name' can only consist of lowercase letters and numbers,
# 'name' can only consist of lowercase letters and numbers,
# and must be between 3 and 24 characters long.
variable "tfstate_storage_account_name_suffix" {
type = string
default = "tfstatesa"
}

variable "tfstate_container_name" {
type = string
default = "tfstate"
}

39 changes: 39 additions & 0 deletions 01_storage_rg/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 82 additions & 0 deletions 01_storage_rg/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
terraform {

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 2.68.0"
}
}

backend "azurerm" {
# Shared state is stored in Azure
# (https://www.terraform.io/docs/backends/types/azurerm.html)
#
# This creates separate tfstate for a resource group for storage needs.
# This way we can have storage volumes that will not be destroyed every time we run `terraform destroy`
#
# Authentication is expected to be done via Azure CLI
# For other authentication means see documentation provided by Microsoft:
# https://docs.microsoft.com/en-us/azure/developer/terraform/store-state-in-azure-storage
#
# We can use the same resource group as we use in storing other tfstate files
resource_group_name = "smaddis-tfstate-rg"
# We can use the same storage account as we use in storing other tfstate files
storage_account_name = "smaddistfstatesa"
# We can use the same container as we use in storing other tfstate files
container_name = "tfstate"
# Separate state file so we can use it in terraform_remote_state datasource
key = "smaddis-storage.tfstate"
}
}

provider "azurerm" {
features {}
}

resource "random_id" "number" {
byte_length = 2
}

resource "azurerm_resource_group" "storage_rg" {
name = "storage-resource-group-${terraform.workspace}${random_id.number.hex}"
location = var.location
}
resource "azurerm_storage_account" "storage_account" {
name = "storage${terraform.workspace}${random_id.number.hex}"
resource_group_name = azurerm_resource_group.storage_rg.name
location = var.location
account_tier = "Standard"
account_replication_type = "LRS"
}
resource "azurerm_storage_share" "influx_share" {
name = "influx-share${terraform.workspace}"
storage_account_name = azurerm_storage_account.storage_account.name
quota = 10
}

resource "azurerm_storage_share" "mongo_share" {
name = "mongo-share${terraform.workspace}"
storage_account_name = azurerm_storage_account.storage_account.name
quota = 10
}

resource "azurerm_storage_share" "kafka_share" {
name = "kafka-share${terraform.workspace}"
storage_account_name = azurerm_storage_account.storage_account.name
quota = 10
}

resource "azurerm_storage_share" "zookeeper_share" {
name = "zookeeper-share${terraform.workspace}"
storage_account_name = azurerm_storage_account.storage_account.name
quota = 10
}

resource "azurerm_managed_disk" "mongo_disk" {
name = "mongo_disk${terraform.workspace}"
location = azurerm_resource_group.storage_rg.location
resource_group_name = azurerm_resource_group.storage_rg.name
storage_account_type = "Standard_LRS"
create_option = "Empty"
disk_size_gb = "8"
}
25 changes: 25 additions & 0 deletions 01_storage_rg/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
output "rg_id" {
value = azurerm_resource_group.storage_rg.id
}
output "rg_name" {
value = azurerm_resource_group.storage_rg.name
}
output "storage_acc_name" {
value = azurerm_storage_account.storage_account.name
}
output "storage_share_influx" {
value = azurerm_storage_share.influx_share.name
}
output "storage_acc_key" {
value = azurerm_storage_account.storage_account.primary_access_key
sensitive = true
}
output "storage_share_mongo" {
value = azurerm_storage_share.mongo_share.name
}
output "storage_share_kafka" {
value = azurerm_storage_share.kafka_share.name
}
output "storage_share_zookeeper" {
value = azurerm_storage_share.zookeeper_share.name
}
4 changes: 4 additions & 0 deletions 01_storage_rg/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
variable "location" {
default = "West Europe"
type = string
}
Loading