From b49764f559d0843705e039ebeca650a09331e802 Mon Sep 17 00:00:00 2001 From: Archit Chopra Date: Wed, 12 Jul 2023 16:35:06 +0530 Subject: [PATCH] fix: Added comments and updates example folder hierarchy --- .github/dependabot.yml | 43 +++++++++++++++- .github/workflows/static-checks.yml | 3 +- _example/basic/example.tf | 38 ++++++++++++++ _example/{ => basic}/outputs.tf | 0 _example/{ => complete}/example.tf | 33 ++++++++---- _example/complete/outputs.tf | 79 +++++++++++++++++++++++++++++ main.tf | 26 +++++++++- variables.tf | 9 +--- 8 files changed, 211 insertions(+), 20 deletions(-) create mode 100644 _example/basic/example.tf rename _example/{ => basic}/outputs.tf (100%) rename _example/{ => complete}/example.tf (58%) create mode 100644 _example/complete/outputs.tf diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 6a9e48b..6410ec6 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,11 +5,52 @@ version: 2 updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + open-pull-requests-limit: 3 + assignees: + - "clouddrove-ci" + reviewers: + - "approvers" + - package-ecosystem: "terraform" # See documentation for possible values directory: "/" # Location of package manifests schedule: interval: "weekly" + # Add assignees + assignees: + - "clouddrove-ci" + # Add reviewer + reviewers: + - "approvers" + # Allow up to 3 open pull requests for pip dependencies + open-pull-requests-limit: 3 + + - package-ecosystem: "terraform" # See documentation for possible values + directory: "/_example/basic" # Location of package manifests + schedule: + interval: "weekly" + # Add assignees + assignees: + - "clouddrove-ci" + # Add reviewer + reviewers: + - "approvers" + # Allow up to 3 open pull requests for pip dependencies + open-pull-requests-limit: 3 + - package-ecosystem: "terraform" # See documentation for possible values - directory: "_example/" # Location of package manifests + directory: "/_example/complete" # Location of package manifests schedule: interval: "weekly" + # Add assignees + assignees: + - "clouddrove-ci" + # Add reviewer + reviewers: + - "approvers" + # Allow up to 3 open pull requests for pip dependencies + open-pull-requests-limit: 3 diff --git a/.github/workflows/static-checks.yml b/.github/workflows/static-checks.yml index 8e8ef4a..58c1e2e 100644 --- a/.github/workflows/static-checks.yml +++ b/.github/workflows/static-checks.yml @@ -30,7 +30,8 @@ jobs: - ${{ needs.versionExtract.outputs.minVersion }} - ${{ needs.versionExtract.outputs.maxVersion }} directory: - - _example/ + - _example/basic + - _example/complete steps: - name: Checkout diff --git a/_example/basic/example.tf b/_example/basic/example.tf new file mode 100644 index 0000000..5e54602 --- /dev/null +++ b/_example/basic/example.tf @@ -0,0 +1,38 @@ +##----------------------------------------------------------------------------- +## DNS zone module call +## Below module will deploy public dns in azure. +##----------------------------------------------------------------------------- +module "dns_zone" { + depends_on = [module.resource_group, module.vnet] + source = "../.." + name = "app" + environment = "test" + resource_group_name = "test-rg" + dns_zone_names = "example.com" + private_registration_enabled = false + private_dns = false + private_dns_zone_name = "" + virtual_network_id = "/subscriptions/---------------------------" + a_records = [{ + name = "test" + ttl = 3600 + records = ["10.0.180.17", "10.0.180.18"] + }, + { + name = "test2" + ttl = 3600 + records = ["10.0.180.17", "10.0.180.18"] + }] + + cname_records = [{ + name = "test1" + ttl = 3600 + record = "example.com" + }] + + ns_records = [{ + name = "test2" + ttl = 3600 + records = ["ns1.example.com.", "ns2.example.com."] + }] +} \ No newline at end of file diff --git a/_example/outputs.tf b/_example/basic/outputs.tf similarity index 100% rename from _example/outputs.tf rename to _example/basic/outputs.tf diff --git a/_example/example.tf b/_example/complete/example.tf similarity index 58% rename from _example/example.tf rename to _example/complete/example.tf index f4a4003..3ce3d09 100644 --- a/_example/example.tf +++ b/_example/complete/example.tf @@ -2,32 +2,48 @@ provider "azurerm" { features {} } +locals { + name = "app" + environment = "test" + label_order = ["name", "environment", ] +} +##----------------------------------------------------------------------------- +## Resource Group module call +## Resource group in which all resources will be deployed. +##----------------------------------------------------------------------------- module "resource_group" { source = "clouddrove/resource-group/azure" version = "1.0.2" - name = "app" - environment = "test" - label_order = ["name", "environment", ] + name = local.name + environment = local.environment + label_order = local.label_order location = "East US" } +##----------------------------------------------------------------------------- +## Vnet module call +##----------------------------------------------------------------------------- module "vnet" { depends_on = [module.resource_group] source = "clouddrove/vnet/azure" version = "1.0.3" - name = "app" - environment = "test" + name = local.name + environment = local.environment resource_group_name = module.resource_group.resource_group_name location = module.resource_group.resource_group_location address_space = "10.0.0.0/16" } +##----------------------------------------------------------------------------- +## DNS zone module call +## Below module will deploy public dns in azure. +##----------------------------------------------------------------------------- module "dns_zone" { depends_on = [module.resource_group, module.vnet] - source = "../" - name = "app" - environment = "test" + source = "../.." + name = local.name + environment = local.environment resource_group_name = module.resource_group.resource_group_name dns_zone_names = "example.com" private_registration_enabled = false @@ -56,5 +72,4 @@ module "dns_zone" { ttl = 3600 records = ["ns1.example.com.", "ns2.example.com."] }] - } diff --git a/_example/complete/outputs.tf b/_example/complete/outputs.tf new file mode 100644 index 0000000..5c60485 --- /dev/null +++ b/_example/complete/outputs.tf @@ -0,0 +1,79 @@ +output "dns_zone_id" { + description = "The DNS Zone ID." + value = module.dns_zone.dns_zone_id +} + +output "dns_zone_number_of_record_sets" { + description = "The number of records already in the zone." + value = module.dns_zone.dns_zone_number_of_record_sets +} + +output "dns_zone_name_servers" { + description = " A list of values that make up the NS record for the zone." + value = module.dns_zone.dns_zone_name_servers +} + +output "dns_zone_max_number_of_record_sets" { + description = " Maximum number of Records in the zone. Defaults to 1000." + value = module.dns_zone.dns_zone_max_number_of_record_sets +} + +output "private_dns_zone_id" { + description = "The Private DNS Zone ID." + value = module.dns_zone.private_dns_zone_id +} + +output "private_dns_zone_number_of_record_sets" { + description = "The current number of record sets in this Private DNS zone." + value = module.dns_zone.private_dns_zone_number_of_record_sets +} + +output "private_dns_zone_max_number_of_record_sets" { + description = "The maximum number of record sets that can be created in this Private DNS zone." + value = module.dns_zone.private_dns_zone_max_number_of_record_sets +} + +output "private_dns_zone_max_number_of_virtual_network_links" { + description = "The maximum number of virtual networks that can be linked to this Private DNS zone." + value = module.dns_zone.private_dns_zone_max_number_of_virtual_network_links +} + +output "private_dns_zone_max_number_of_virtual_network_links_with_registration" { + description = "The maximum number of virtual networks that can be linked to this Private DNS zone with registration enabled." + value = module.dns_zone.private_dns_zone_max_number_of_virtual_network_links_with_registration +} + +output "private_dns_zone_virtual_network_link_id" { + description = "The ID of the Private DNS Zone Virtual Network Link." + value = module.dns_zone.private_dns_zone_virtual_network_link_id +} + +output "dns_a_record_id" { + description = " The DNS A Record ID." + value = module.dns_zone.dns_a_record_id +} + +output "dns_a_record_fqdn" { + description = "The FQDN of the DNS A Record." + value = module.dns_zone.dns_a_record_fqdn +} + +output "dns_cname_record_id" { + description = " The DNS CNAME Record ID." + value = module.dns_zone.dns_cname_record_id +} + +output "dns_cname_record_fqdn" { + description = "The FQDN of the DNS CNAME Record." + value = module.dns_zone.dns_cname_record_fqdn +} + +output "dns_ns_record_id" { + description = " The DNS NS Record ID." + value = module.dns_zone.dns_ns_record_id +} + +output "dns_ns_record_fqdn" { + description = "The FQDN of the DNS NS Record." + value = module.dns_zone.dns_ns_record_fqdn +} diff --git a/main.tf b/main.tf index dfc655e..ab686a3 100644 --- a/main.tf +++ b/main.tf @@ -1,3 +1,6 @@ +##----------------------------------------------------------------------------- +## Labels module callled that will be used for naming and tags. +##----------------------------------------------------------------------------- module "labels" { source = "clouddrove/labels/azure" name = var.name @@ -7,11 +10,16 @@ module "labels" { repository = var.repository } - +##----------------------------------------------------------------------------- +## Below resource will deploy random id that will be used for naming in vnet link resource for private dns. +##----------------------------------------------------------------------------- resource "random_id" "this" { byte_length = "8" } +##----------------------------------------------------------------------------- +## Below resource will deploy public DNS zone in azure. +##----------------------------------------------------------------------------- resource "azurerm_dns_zone" "dns_zone" { count = var.enabled && var.enabled_dns ? 1 : 0 name = var.dns_zone_names @@ -20,6 +28,9 @@ resource "azurerm_dns_zone" "dns_zone" { } +##----------------------------------------------------------------------------- +## Below resource will deploy private DNS zone in azure. +##----------------------------------------------------------------------------- resource "azurerm_private_dns_zone" "private_dns_zone" { count = var.enabled && var.private_dns ? 1 : 0 name = var.private_dns_zone_name @@ -38,6 +49,9 @@ resource "azurerm_private_dns_zone" "private_dns_zone" { tags = module.labels.tags } +##----------------------------------------------------------------------------- +## Below resource will deploy vnet link in private dns zone. +##----------------------------------------------------------------------------- resource "azurerm_private_dns_zone_virtual_network_link" "private_dns_vnet_link" { count = var.enabled && var.private_dns ? 1 : 0 name = "vnet-link-${random_id.this.hex}" @@ -48,7 +62,9 @@ resource "azurerm_private_dns_zone_virtual_network_link" "private_dns_vnet_link" tags = module.labels.tags } - +##----------------------------------------------------------------------------- +## Below resource will add a_record in DNS zone. +##----------------------------------------------------------------------------- resource "azurerm_dns_a_record" "records_a" { for_each = { for record in var.a_records : record.name => record } name = lookup(each.value, "name", null) # Required @@ -60,6 +76,9 @@ resource "azurerm_dns_a_record" "records_a" { tags = module.labels.tags } +##----------------------------------------------------------------------------- +## Below resource will add cname_record in DNS zone. +##----------------------------------------------------------------------------- resource "azurerm_dns_cname_record" "records_cname" { for_each = { for record in var.cname_records : record.name => record } #toset(var.cname_records) name = lookup(each.value, "name", null) # Required @@ -72,6 +91,9 @@ resource "azurerm_dns_cname_record" "records_cname" { } +##----------------------------------------------------------------------------- +## Below resource will add ns_record in DNS zone. +##----------------------------------------------------------------------------- resource "azurerm_dns_ns_record" "records_ns" { for_each = { for record in var.ns_records : record.name => record } #toset(var.ns_records) diff --git a/variables.tf b/variables.tf index 619397b..b612c04 100644 --- a/variables.tf +++ b/variables.tf @@ -95,18 +95,13 @@ variable "soa_record" { variable "a_records" { type = any + default = [] description = "List of a records to be added in azure dns zone." } variable "cname_records" { type = any - # type = list(object({ - # name = string, #(Required)The name of the DNS CNAME Record. Changing this forces a new resource to be created. - # ttl = number, #(Required)The Time To Live (TTL) of the DNS record in seconds. - # record = string, #(Optional)The target of the CNAME. - # target_resource_id = string #(Optional)The Azure resource id of the target object. Conflicts with record. - # })) - # default = [] + default = [] description = "List of cname records" }