Skip to content

Commit

Permalink
fix: update code and add tf latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
mamrajyadav committed Dec 11, 2023
1 parent c09c2f8 commit 0a5c65c
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 103 deletions.
13 changes: 8 additions & 5 deletions _example/basic/example.tf
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
provider "azurerm" {
features {}
}

locals {
name = "app"
environment = "test"
label_order = ["name", "environment"]
}

##-----------------------------------------------------------------------------
##-----------------------------------------------------------------------------
## Virtual Network module call.
##-----------------------------------------------------------------------------
module "vnet" {
source = "../../"
name = local.name
environment = local.environment
resource_group_name = "app-test"
resource_group_name = "testsg"
location = "NorthEurope"
address_space = "10.0.0.0/16"
enable_network_watcher = false # To be set true when network security group flow logs are to be tracked and network watcher with specific name is to be deployed.
}
enable_network_watcher = false # To be set true when network security group flow logs are to be tracked and network watcher with specific name is to be deployed.
}
13 changes: 13 additions & 0 deletions _example/basic/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Terraform version
terraform {
required_version = ">= 1.6.5"
}

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.83.0"
}
}
}
8 changes: 3 additions & 5 deletions _example/complete/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ provider "azurerm" {
locals {
name = "app"
environment = "test"
label_order = ["name", "environment"]
}

##-----------------------------------------------------------------------------
##-----------------------------------------------------------------------------
## Resource Group module call
## Resource group in which all resources will be deployed.
##-----------------------------------------------------------------------------
Expand All @@ -17,11 +16,10 @@ module "resource_group" {
version = "1.0.2"
name = local.name
environment = local.environment
label_order = local.label_order
location = "North Europe"
}

##-----------------------------------------------------------------------------
##-----------------------------------------------------------------------------
## Virtual Network module call.
##-----------------------------------------------------------------------------
module "vnet" {
Expand All @@ -31,5 +29,5 @@ module "vnet" {
resource_group_name = module.resource_group.resource_group_name
location = module.resource_group.resource_group_location
address_space = "10.0.0.0/16"
enable_network_watcher = false # To be set true when network security group flow logs are to be tracked and network watcher with specific name is to be deployed.
enable_network_watcher = false # To be set true when network security group flow logs are to be tracked and network watcher with specific name is to be deployed.
}
13 changes: 13 additions & 0 deletions _example/complete/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Terraform version
terraform {
required_version = ">= 1.6.5"
}

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=3.83.0"
}
}
}
28 changes: 13 additions & 15 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
##-----------------------------------------------------------------------------
## Locals declaration for determining the id of ddos protection plan.
##-----------------------------------------------------------------------------
## Locals declaration for determining the id of ddos protection plan.
##-----------------------------------------------------------------------------
locals {
ddos_pp_id = var.enable_ddos_pp && var.existing_ddos_pp != null ? var.existing_ddos_pp : var.enable_ddos_pp && var.existing_ddos_pp == null ? azurerm_network_ddos_protection_plan.example[0].id : null
}

##-----------------------------------------------------------------------------
## Labels module callled that will be used for naming and tags.
##-----------------------------------------------------------------------------
## Labels module callled that will be used for naming and tags.
##-----------------------------------------------------------------------------
module "labels" {

source = "clouddrove/labels/azure"
version = "1.0.0"

source = "clouddrove/labels/azure"
version = "1.0.0"
name = var.name
environment = var.environment
managedby = var.managedby
label_order = var.label_order
repository = var.repository
}

##-----------------------------------------------------------------------------
## Below resource will deploy virtual network in your azure environment.
##-----------------------------------------------------------------------------
## Below resource will deploy virtual network in your azure environment.
##-----------------------------------------------------------------------------
resource "azurerm_virtual_network" "vnet" {
count = var.enable == true ? 1 : 0
Expand All @@ -43,8 +41,8 @@ resource "azurerm_virtual_network" "vnet" {
tags = module.labels.tags
}

##-----------------------------------------------------------------------------
## Below resource will deploy ddos protection plan for virtual network.
##-----------------------------------------------------------------------------
## Below resource will deploy ddos protection plan for virtual network.
##-----------------------------------------------------------------------------
resource "azurerm_network_ddos_protection_plan" "example" {
count = var.enable_ddos_pp && var.enable == true ? 1 : 0
Expand All @@ -56,12 +54,12 @@ resource "azurerm_network_ddos_protection_plan" "example" {

##-----------------------------------------------------------------------------
## Below resource will deploy network watcher resource group in azure.
## To be deployed when flow logs for network security group is to be tracked.
## By default azure deploys network wather on its own, but if in azure infrastructure deployment you need network watcher with specific name than set 'enable_network_watcher' variable to true.
## To be deployed when flow logs for network security group is to be tracked.
## By default azure deploys network wather on its own, but if in azure infrastructure deployment you need network watcher with specific name than set 'enable_network_watcher' variable to true.
##-----------------------------------------------------------------------------
resource "azurerm_network_watcher" "flow_log_nw" {
count = var.enable && var.enable_network_watcher ? 1 : 0
name = format("%s-network_watcher", module.labels.id)
location = var.location
resource_group_name = var.resource_group_name
}
}
20 changes: 10 additions & 10 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
output "vnet_id" {
description = "The id of the newly created vNet"
value = azurerm_virtual_network.vnet.*.id
value = azurerm_virtual_network.vnet[*].id
}

output "vnet_name" {
description = "The name of the newly created vNet"
value = azurerm_virtual_network.vnet.*.name
value = azurerm_virtual_network.vnet[*].name
}

output "vnet_location" {
description = "The location of the newly created vNet"
value = azurerm_virtual_network.vnet.*.location
value = azurerm_virtual_network.vnet[*].location
}

output "vnet_address_space" {
description = "The address space of the newly created vNet"
value = azurerm_virtual_network.vnet.*.address_space
value = azurerm_virtual_network.vnet[*].address_space
}

output "vnet_guid" {
description = "The GUID of the virtual network."
value = azurerm_virtual_network.vnet.*.guid
value = azurerm_virtual_network.vnet[*].guid
}

output "vnet_rg_name" {
description = "The name of the resource group in which to create the virtual network. Changing this forces a new resource to be created"
value = azurerm_virtual_network.vnet.*.resource_group_name
value = azurerm_virtual_network.vnet[*].resource_group_name
}

output "ddos_protection_plan_id" {
value = join("", azurerm_network_ddos_protection_plan.example.*.id)
value = join("", azurerm_network_ddos_protection_plan.example[*].id)
description = "The ID of the DDoS Protection Plan"
}
output "network_watcher_id" {
value = join("", azurerm_network_watcher.flow_log_nw.*.id)
value = join("", azurerm_network_watcher.flow_log_nw[*].id)
description = "The ID of the Network Watcher."
}

output "network_watcher_name" {
value = join("", azurerm_network_watcher.flow_log_nw.*.name)
value = join("", azurerm_network_watcher.flow_log_nw[*].name)
description = "The name of Network Watcher deployed."
}
}
67 changes: 1 addition & 66 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ variable "name" {

variable "repository" {
type = string
default = "https://github.com/clouddrove/terraform-azure-virtual-network"
default = "https://github.com/clouddrove/terraform-azure-vnet"
description = "Terraform current module repo"

validation {
Expand All @@ -30,24 +30,6 @@ variable "label_order" {
description = "Label order, e.g. `name`,`application`."
}

variable "attributes" {
type = list(any)
default = []
description = "Additional attributes (e.g. `1`)."
}

variable "delimiter" {
type = string
default = "-"
description = "Delimiter to be used between `organization`, `environment`, `name` and `attributes`."
}

variable "tags" {
type = map(any)
default = {}
description = "Additional tags (e.g. map(`BusinessUnit`,`XYZ`)."
}

variable "managedby" {
type = string
default = "hello@clouddrove.com"
Expand Down Expand Up @@ -123,50 +105,3 @@ variable "enable_network_watcher" {
default = false
description = "Flag to control creation of network watcher."
}

variable "network_security_group_id" {
type = string
default = null
description = "Id of network security group for which flow are to be calculated"
}

variable "storage_account_id" {
type = string
default = null
description = "Id of storage account."
}

variable "workspace_id" {
type = string
default = null
description = "Log analytics workspace id"
}

variable "workspace_resource_id" {
type = string
default = null
description = "Resource id of workspace"
}

variable "enable_flow_logs" {
type = bool
default = false
description = "Flag to control creation of flow logs for nsg."
}

variable "enable_traffic_analytics" {
type = bool
default = true
description = "Flag to control creation of traffic analytics."
}

variable "retention_policy_enabled" {
type = bool
default = true
description = "Boolean flag to enable/disable retention."
}
variable "retention_policy_days" {
type = number
default = 30
description = "The number of days to retain flow log records."
}
5 changes: 3 additions & 2 deletions versions.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Terraform version
terraform {
required_version = ">= 1.0.0"
required_version = ">= 1.6.5"
}

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = ">=2.90.0"
version = ">=3.83.0"
}
}
}

0 comments on commit 0a5c65c

Please sign in to comment.