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

Feature/default #4

Open
wants to merge 10 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
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "terraform"
directory: "/"
schedule:
interval: "daily"
24 changes: 24 additions & 0 deletions .github/workflows/superlinter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: "Code Quality: Super-Linter"
on:
pull_request:
jobs:
superlinter:
name: Super-Linter
runs-on: ubuntu-latest
steps:

- name: Checkout Repository
uses: actions/checkout@v3

- name: Lint Code
uses: docker://github/super-linter:v4
env:
VALIDATE_ALL_CODEBASE: true
DEFAULT_BRANCH: "main"
DISABLE_ERRORS: false
VALIDATE_BASH: true
VALIDATE_JSON: true
VALIDATE_MD: true
VALIDATE_TERRAFORM: true
VALIDATE_YAML: true
35 changes: 35 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
name: "Code Quality: Terraform"
on:
push:
branches:
- main
pull_request:
jobs:
terraform:
name: Terraform
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v1

# - name: Terraform Format
# id: fmt
# run: terraform fmt -check -recursive

- name: Terraform Init
id: init
run: terraform init

- name: Terraform Validate
id: validate
run: terraform validate -no-color

# - name: Terraform Plan
# id: plan
# run: terraform plan -no-color -input=false
# continue-on-error: true
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ override.tf.json

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*
*tfplan*

*.terraform.lock.hcl

# Mac Files
.DS_Store

# IntelliJ IDEA files
*.idea/
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ terraform {
}
}
# Terraform State Storage to Azure Storage Container
backend "azurerm" {
/* backend "azurerm" {
resource_group_name = "terraform-storage-rg"
storage_account_name = "terraformstate201"
container_name = "tfstatefiles"
key = "terraform.tfstate"
}
}*/
}

#####################################################################
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Terraform Block
terraform {
required_version = ">= 1.0.0"
required_version = "~> 1.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ terraform {
required_version = ">= 1.0.0"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">= 2.0"
source = "hashicorp/azurerm"
version = ">= 2.0"
}
random = {
source = "hashicorp/random"
source = "hashicorp/random"
version = ">= 3.0"
}
}
}

# Provider Block
provider "azurerm" {
features {}
features {}
}


Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
# Business Division
variable "business_divsion" {
description = "Business Division in the large organization this Infrastructure belongs"
type = string
default = "sap"
type = string
default = "sap"
}
# Environment Variable
variable "environment" {
description = "Environment Variable used as a prefix"
type = string
default = "dev"
type = string
default = "dev"
}

# Azure Resource Group Name
variable "resource_group_name" {
description = "Resource Group Name"
type = string
default = "rg-default"
type = string
default = "rg-default"
}

# Azure Resources Location
variable "resource_group_location" {
description = "Region in which Azure Resources to be created"
type = string
default = "eastus2"
type = string
default = "eastus2"
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Define Local Values in Terraform
locals {
owners = var.business_divsion
environment = var.environment
owners = var.business_divsion
environment = var.environment
resource_name_prefix = "${var.business_divsion}-${var.environment}"
#name = "${local.owners}-${local.environment}"
common_tags = {
owners = local.owners
owners = local.owners
environment = local.environment
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Random String Resource
resource "random_string" "myrandom" {
length = 6
upper = false
length = 6
upper = false
special = false
number = false
number = false
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Resource-1: Azure Resource Group
resource "azurerm_resource_group" "rg" {
# name = "${local.resource_name_prefix}-${var.resource_group_name}"
name = "${local.resource_name_prefix}-${var.resource_group_name}-${random_string.myrandom.id}"
name = "${local.resource_name_prefix}-${var.resource_group_name}-${random_string.myrandom.id}"
location = var.resource_group_location
tags = local.common_tags
tags = local.common_tags
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +3,69 @@
## Virtual Network
variable "vnet_name" {
description = "Virtual Network name"
type = string
default = "vnet-default"
type = string
default = "vnet-default"
}
variable "vnet_address_space" {
description = "Virtual Network address_space"
type = list(string)
default = ["10.0.0.0/16"]
type = list(string)
default = ["10.0.0.0/16"]
}


# Web Subnet Name
variable "web_subnet_name" {
description = "Virtual Network Web Subnet Name"
type = string
default = "websubnet"
type = string
default = "websubnet"
}
# Web Subnet Address Space
variable "web_subnet_address" {
description = "Virtual Network Web Subnet Address Spaces"
type = list(string)
default = ["10.0.1.0/24"]
type = list(string)
default = ["10.0.1.0/24"]
}


# App Subnet Name
variable "app_subnet_name" {
description = "Virtual Network App Subnet Name"
type = string
default = "appsubnet"
type = string
default = "appsubnet"
}
# App Subnet Address Space
variable "app_subnet_address" {
description = "Virtual Network App Subnet Address Spaces"
type = list(string)
default = ["10.0.11.0/24"]
type = list(string)
default = ["10.0.11.0/24"]
}


# Database Subnet Name
variable "db_subnet_name" {
description = "Virtual Network Database Subnet Name"
type = string
default = "dbsubnet"
type = string
default = "dbsubnet"
}
# Database Subnet Address Space
variable "db_subnet_address" {
description = "Virtual Network Database Subnet Address Spaces"
type = list(string)
default = ["10.0.21.0/24"]
type = list(string)
default = ["10.0.21.0/24"]
}


# Bastion / Management Subnet Name
variable "bastion_subnet_name" {
description = "Virtual Network Bastion Subnet Name"
type = string
default = "bastionsubnet"
type = string
default = "bastionsubnet"
}
# Bastion / Management Subnet Address Space
variable "bastion_subnet_address" {
description = "Virtual Network Bastion Subnet Address Spaces"
type = list(string)
default = ["10.0.100.0/24"]
type = list(string)
default = ["10.0.100.0/24"]
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ resource "azurerm_virtual_network" "vnet" {
address_space = var.vnet_address_space
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
tags = local.common_tags
tags = local.common_tags
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "azurerm_subnet" "websubnet" {
name = "${azurerm_virtual_network.vnet.name}-${var.web_subnet_name}"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = var.web_subnet_address
address_prefixes = var.web_subnet_address
}

# Resource-2: Create Network Security Group (NSG)
Expand All @@ -15,7 +15,7 @@ resource "azurerm_network_security_group" "web_subnet_nsg" {

# Resource-3: Associate NSG and Subnet
resource "azurerm_subnet_network_security_group_association" "web_subnet_nsg_associate" {
depends_on = [ azurerm_network_security_rule.web_nsg_rule_inbound] # Every NSG Rule Association will disassociate NSG from Subnet and Associate it, so we associate it only after NSG is completely created - Azure Provider Bug https://github.com/terraform-providers/terraform-provider-azurerm/issues/354
depends_on = [azurerm_network_security_rule.web_nsg_rule_inbound] # Every NSG Rule Association will disassociate NSG from Subnet and Associate it, so we associate it only after NSG is completely created - Azure Provider Bug https://github.com/terraform-providers/terraform-provider-azurerm/issues/354
subnet_id = azurerm_subnet.websubnet.id
network_security_group_id = azurerm_network_security_group.web_subnet_nsg.id
}
Expand All @@ -27,18 +27,18 @@ locals {
"100" : "80", # If the key starts with a number, you must use the colon syntax ":" instead of "="
"110" : "443",
"120" : "22"
}
}
}
## NSG Inbound Rule for WebTier Subnets
resource "azurerm_network_security_rule" "web_nsg_rule_inbound" {
for_each = local.web_inbound_ports_map
for_each = local.web_inbound_ports_map
name = "Rule-Port-${each.value}"
priority = each.key
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = each.value
destination_port_range = each.value
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = azurerm_resource_group.rg.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ resource "azurerm_subnet" "appsubnet" {
name = "${azurerm_virtual_network.vnet.name}-${var.app_subnet_name}"
resource_group_name = azurerm_resource_group.rg.name
virtual_network_name = azurerm_virtual_network.vnet.name
address_prefixes = var.app_subnet_address
address_prefixes = var.app_subnet_address
}

# Resource-2: Create Network Security Group (NSG)
Expand All @@ -15,7 +15,7 @@ resource "azurerm_network_security_group" "app_subnet_nsg" {

# Resource-3: Associate NSG and Subnet
resource "azurerm_subnet_network_security_group_association" "app_subnet_nsg_associate" {
depends_on = [ azurerm_network_security_rule.app_nsg_rule_inbound]
depends_on = [azurerm_network_security_rule.app_nsg_rule_inbound]
subnet_id = azurerm_subnet.appsubnet.id
network_security_group_id = azurerm_network_security_group.app_subnet_nsg.id
}
Expand All @@ -28,18 +28,18 @@ locals {
"110" : "443",
"120" : "8080",
"130" : "22"
}
}
}
## NSG Inbound Rule for AppTier Subnets
resource "azurerm_network_security_rule" "app_nsg_rule_inbound" {
for_each = local.app_inbound_ports_map
for_each = local.app_inbound_ports_map
name = "Rule-Port-${each.value}"
priority = each.key
direction = "Inbound"
access = "Allow"
protocol = "Tcp"
source_port_range = "*"
destination_port_range = each.value
destination_port_range = each.value
source_address_prefix = "*"
destination_address_prefix = "*"
resource_group_name = azurerm_resource_group.rg.name
Expand Down
Loading