Skip to content

Commit

Permalink
Removed the use of deprecated null data source. Module no longer gene…
Browse files Browse the repository at this point in the history
…rates multiple results since the count variable is now supported in modules (0.13+).
  • Loading branch information
Yohan Belval committed Mar 15, 2021
1 parent 56abb4e commit 1086d4b
Show file tree
Hide file tree
Showing 143 changed files with 131 additions and 703 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
node_modules/
*.tfstate
*.tfstate.backup
.terraform/
.terraform/
.idea/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ _Note: Since this module is comprised of multiple sub-modules, you need to [refe
## Example Usage
```hcl
provider "azurerm" {
version = "=2.1.0"
features {}
}
variable "location" {
Expand Down Expand Up @@ -60,4 +60,4 @@ terraform get -update

## License

Copyright © 2020, GSoft inc. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/gsoft-license/blob/master/LICENSE.
Copyright © 2021, GSoft inc. This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/gsoft-license/blob/master/LICENSE.
9 changes: 1 addition & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ resource "random_string" "suffix" {
}
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? substr("${local.prefix}${local.separated_name}${count.index}${var.separator}${local.suffix}", 0, var.max_length) : substr("${local.prefix}${var.separator}${var.name}${var.separator}${local.suffix}", 0, var.max_length)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = substr("${local.prefix}${local.separated_name}${local.suffix}", 0, var.max_length)
}
10 changes: 1 addition & 9 deletions modules/compute/vm_linux/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "vm_linux" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "-"
max_length = 64
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.vm_linux.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.vm_linux.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.vm_linux.result)
}
7 changes: 1 addition & 6 deletions modules/compute/vm_linux/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated linux virtual machine name."
value = local.results[0]
}

output "results" {
description = "The generated linux virtual machine names."
value = local.results
value = local.result
}
4 changes: 0 additions & 4 deletions modules/compute/vm_linux/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ variable "suffixes" {
description = "List of suffixes to append at the end of the resource name."
type = list(string)
default = null
}

variable "nb_instances" {
default = 1
}
2 changes: 1 addition & 1 deletion modules/compute/vm_linux/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}
10 changes: 1 addition & 9 deletions modules/compute/vm_windows/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "vm_windows" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "-"
max_length = 15
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.vm_windows.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.vm_windows.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.vm_windows.result)
}
7 changes: 1 addition & 6 deletions modules/compute/vm_windows/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated windows virtual machine name."
value = local.results[0]
}

output "results" {
description = "The generated windows virtual machine names."
value = local.results
value = local.result
}
4 changes: 0 additions & 4 deletions modules/compute/vm_windows/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ variable "suffixes" {
description = "List of suffixes to append at the end of the resource name."
type = list(string)
default = null
}

variable "nb_instances" {
default = 1
}
2 changes: 1 addition & 1 deletion modules/compute/vm_windows/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}
10 changes: 1 addition & 9 deletions modules/containers/container_registry/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "container_registry" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "0"
max_length = 50
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9]*$", module.container_registry.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9]*$", module.container_registry.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9]*$", module.container_registry.result)
}
7 changes: 1 addition & 6 deletions modules/containers/container_registry/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated traffic manager profile name."
value = local.results[0]
}

output "results" {
description = "The generated traffic manager profile names."
value = local.results
value = local.result
}
4 changes: 0 additions & 4 deletions modules/containers/container_registry/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ variable "suffixes" {
description = "List of suffixes to append at the end of the resource name."
type = list(string)
default = null
}

variable "nb_instances" {
default = 1
}
2 changes: 1 addition & 1 deletion modules/containers/container_registry/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}
10 changes: 1 addition & 9 deletions modules/general/api_management/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "api_management" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "-"
max_length = 50
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.api_management.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.api_management.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.api_management.result)
}
7 changes: 1 addition & 6 deletions modules/general/api_management/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated api management name."
value = local.results[0]
}

output "results" {
description = "The generated api management names."
value = local.results
value = local.result
}
4 changes: 0 additions & 4 deletions modules/general/api_management/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ variable "suffixes" {
description = "List of suffixes to append at the end of the resource name."
type = list(string)
default = null
}

variable "nb_instances" {
default = 1
}
2 changes: 1 addition & 1 deletion modules/general/api_management/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}
10 changes: 1 addition & 9 deletions modules/general/availability_set/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "availability_set" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "-"
max_length = 80
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.availability_set.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.availability_set.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.availability_set.result)
}
7 changes: 1 addition & 6 deletions modules/general/availability_set/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated availability set name."
value = local.results[0]
}

output "results" {
description = "The generated availability set names."
value = local.results
value = local.result
}
4 changes: 0 additions & 4 deletions modules/general/availability_set/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ variable "suffixes" {
description = "List of suffixes to append at the end of the resource name."
type = list(string)
default = null
}

variable "nb_instances" {
default = 1
}
2 changes: 1 addition & 1 deletion modules/general/availability_set/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}
10 changes: 1 addition & 9 deletions modules/general/key_vault/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "key_vault" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "-"
max_length = 24
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.key_vault.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.key_vault.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-]*$", module.key_vault.result)
}
7 changes: 1 addition & 6 deletions modules/general/key_vault/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated key vault name."
value = local.results[0]
}

output "results" {
description = "The generated key vault names."
value = local.results
value = local.result
}
4 changes: 0 additions & 4 deletions modules/general/key_vault/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ variable "suffixes" {
description = "List of suffixes to append at the end of the resource name."
type = list(string)
default = null
}

variable "nb_instances" {
default = 1
}
2 changes: 1 addition & 1 deletion modules/general/key_vault/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}
10 changes: 1 addition & 9 deletions modules/general/resource_group/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "resource_group" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "-"
max_length = 90
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-_]*$", module.resource_group.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-_]*$", module.resource_group.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-_]*$", module.resource_group.result)
}
7 changes: 1 addition & 6 deletions modules/general/resource_group/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated resource group name."
value = local.results[0]
}

output "results" {
description = "The generated resource group names."
value = local.results
value = local.result
}
4 changes: 0 additions & 4 deletions modules/general/resource_group/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,4 @@ variable "suffixes" {
description = "List of suffixes to append at the end of the resource name."
type = list(string)
default = null
}

variable "nb_instances" {
default = 1
}
2 changes: 1 addition & 1 deletion modules/general/resource_group/versions.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
terraform {
required_version = ">= 0.12"
required_version = ">= 0.13"
}
10 changes: 1 addition & 9 deletions modules/messaging/event_hub/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@ module "event_hub" {
suffixes = var.suffixes
separator = var.separator != null ? var.separator : "-"
max_length = 50
nb_instances = var.nb_instances
}

data "null_data_source" "names" {
count = var.nb_instances
inputs = {
result = var.nb_instances > 1 ? regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-_.]*$", module.event_hub.results[count.index]) : regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-_.]*$", module.event_hub.result)
}
}

locals {
results = data.null_data_source.names.*.outputs.result
result = regex("^[a-zA-Z0-9]{1}[a-zA-Z0-9-_.]*$", module.event_hub.result)
}
7 changes: 1 addition & 6 deletions modules/messaging/event_hub/outputs.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
output "result" {
description = "The generated event hub name."
value = local.results[0]
}

output "results" {
description = "The generated event hub names."
value = local.results
value = local.result
}
Loading

0 comments on commit 1086d4b

Please sign in to comment.