Skip to content

Commit

Permalink
feat: improve example (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-FFFFFF authored Dec 12, 2023
1 parent 2a71a8c commit 2e22fec
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
37 changes: 24 additions & 13 deletions examples/default/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,52 @@ terraform {
source = "hashicorp/azurerm"
version = ">= 3.7.0, < 4.0.0"
}
random = {
source = "hashicorp/random"
version = ">= 3.5.0, < 4.0.0"
}
}
}

provider "azurerm" {
features {}
}

variable "enable_telemetry" {
type = bool
default = true
description = <<DESCRIPTION
This variable controls whether or not telemetry is enabled for the module.
For more information see https://aka.ms/avm/telemetryinfo.
If it is set to false, then no telemetry will be collected.
DESCRIPTION
## Section to provide a random Azure region for the resource group
# This allows us to randomize the region for the resource group.
module "regions" {
source = "Azure/regions/azurerm"
version = ">= 0.3.0"
}

# This allows us to randomize the region for the resource group.
resource "random_integer" "region_index" {
min = 0
max = length(module.regions.regions) - 1
}
## End of section to provide a random Azure region for the resource group

# This ensures we have unique CAF compliant names for our resources.
module "naming" {
source = "Azure/naming/azurerm"
version = "0.4.0"
version = ">= 0.3.0"
}

# This is required for resource modules
resource "azurerm_resource_group" "this" {
name = module.naming.resource_group.name_unique
location = "MYLOCATION"
location = module.regions.regions[random_integer.region_index.result].name
}

# This is the module call
module "MYMODULE" {
# Do not specify location here due to the randomization above.
# Leaving location as `null` will cause the module to use the resource group location
# with a data source.
module "test" {
source = "../../"
# source = "Azure/avm-<res/ptn>-<name>/azurerm"
# ...
enable_telemetry = var.enable_telemetry
name = "" # TODO update with module.naming.<RESOURCE_TYPE>.name_unique
enable_telemetry = var.enable_telemetry # see variables.tf
name = "" # TODO update with module.naming.<RESOURCE_TYPE>.name_unique
resource_group_name = azurerm_resource_group.this.name
}
9 changes: 9 additions & 0 deletions examples/default/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
variable "enable_telemetry" {
type = bool
default = true
description = <<DESCRIPTION
This variable controls whether or not telemetry is enabled for the module.
For more information see <https://aka.ms/avm/telemetryinfo>.
If it is set to false, then no telemetry will be collected.
DESCRIPTION
}

0 comments on commit 2e22fec

Please sign in to comment.