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

Dev #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.exe
*.tfstate*
41 changes: 41 additions & 0 deletions .terraform.lock.hcl

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

1 change: 1 addition & 0 deletions .terraform/modules/modules.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Modules":[{"Key":"","Source":"","Dir":"."},{"Key":"resource_group_storage","Source":"registry.terraform.io/YegorVolkov/resource_group_storage/azurerm","Version":"1.11.0","Dir":".terraform/modules/resource_group_storage"}]}
1 change: 1 addition & 0 deletions .terraform/modules/resource_group_storage
Submodule resource_group_storage added at a1ef81

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module "resource_group_storage" {
source = "YegorVolkov/resource_group_storage/azurerm"
version = "1.11.0"
}
7 changes: 7 additions & 0 deletions modules/resource_group_storage/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2024 Yegor Volkov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 changes: 15 additions & 0 deletions modules/resource_group_storage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
This module is prepared as the requiremnt of the Task under the MateAcademy DevOps course.

- The module creates a resource group and a storage account
- The module requires following variables:

1) res_gr_name
2) region
3) strg_ac_name_prefix

- Storage account name uiniqueness is provided with 8 random characters & digits at the end

- The module is provided with additional validation for:

1) region name
2) storage account name prefix
3 changes: 3 additions & 0 deletions modules/resource_group_storage/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
locals {
strg_acc_name = "${var.strg_ac_name_prefix}${random_string.strg_name.result}${random_integer.strg_name.result}"
}
27 changes: 27 additions & 0 deletions modules/resource_group_storage/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.115.0"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "main" {
name = var.res_gr_name
location = var.region
}

resource "azurerm_storage_account" "main" {
name = local.strg_acc_name
location = var.region
resource_group_name = var.res_gr_name
account_tier = "Premium"
access_tier = "Hot"
account_kind = "StorageV2"
account_replication_type = "LRS"
}
4 changes: 4 additions & 0 deletions modules/resource_group_storage/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
output "strg_ac_name" {
description = "Storage Account name"
value = azurerm_storage_account.main.name
}
14 changes: 14 additions & 0 deletions modules/resource_group_storage/random.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
provider "random" {}

resource "random_integer" "strg_name" {
min = 0
max = 9999
}

resource "random_string" "strg_name" {
length = 4
lower = true
upper = false
special = false
numeric = false
}
45 changes: 45 additions & 0 deletions modules/resource_group_storage/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
variable "res_gr_name" {
description = "Resource group name"
default = "group1"
}

variable "region" {
description = "Azure Region"
default = "uksouth"
validation {
condition = contains(
[
"eastus", "eastus2", "southcentralus", "westus2", "westus3", "australiaeast", "southeastasia", "northeurope", "swedencentral", "uksouth", "westeurope",
"centralus", "southafricanorth", "centralindia", "eastasia", "japaneast", "koreacentral", "canadacentral", "francecentral", "germanywestcentral",
"italynorth", "norwayeast", "polandcentral", "spaincentral", "switzerlandnorth", "mexicocentral", "uaenorth", "brazilsouth", "israelcentral", "qatarcentral",
"centralusstage", "eastusstage", "eastus2stage", "northcentralusstage", "southcentralusstage", "westusstage", "westus2stage", "asia", "asiapacific",
"australia", "brazil", "canada", "europe", "france", "germany", "global", "india", "israel", "italy", "japan", "korea", "newzealand", "norway",
"poland", "qatar", "singapore", "southafrica", "sweden", "switzerland", "uae", "uk", "unitedstates", "unitedstateseuap", "eastasiastage",
"southeastasiastage", "brazilus", "eastusstg", "northcentralus", "westus", "japanwest", "jioindiawest", "centraluseuap", "eastus2euap",
"westcentralus", "southafricawest", "australiacentral", "australiacentral2", "australiasoutheast", "jioindiacentral", "koreasouth", "southindia",
"westindia", "canadaeast", "francesouth", "germanynorth", "norwaywest", "switzerlandwest", "ukwest", "uaecentral", "brazilsoutheast"
], var.region
)
error_message = (
<<EOF
The region name must be one of the allowed regions.

Follow the Link to see available region Names
https://github.com/YegorVolkov/az_regions
EOF
)
}
}

variable "strg_ac_name_prefix" {
description = "Storage Account Name Prefix"
type = string
default = "storage"
validation {
condition = (
length(var.strg_ac_name_prefix) <= 16 &&
can(regex("^[a-z]+$", var.strg_ac_name_prefix))
)
error_message = "The storage account prefix must be up to 16 characters in length & contain only lowercase characters."
}
}
Binary file added tfplan
Binary file not shown.
Loading