### Example Resource Name Output Source: https://github.com/azure/terraform-azurerm-naming/blob/master/README.md This Go-like map structure represents the typical output format for a resource name generated by the module, including unique identifiers and metadata. ```go postgresql_server = { name = "pre-fix-psql-su-fix" name_unique = "pre-fix-psql-su-fix-asdfg" dashes = true slug = "psql" min_length = 3 max_length = 63 scope = "global" regex = "^[a-z0-9][a-zA-Z0-9-]+[a-z0-9]$" } ``` -------------------------------- ### Correct CDKTF Output Reference with Fn_Lookup Source: https://github.com/azure/terraform-azurerm-naming/blob/master/docs/cdktf_usage.md This example demonstrates the correct workaround using `cdktf.Fn_Lookup` to access a specific key ('name') from a map output. This ensures the generated Terraform configuration is valid. ```go // See comment at https://github.com/hashicorp/terraform-cdk/issues/3477#issuecomment-1926338050 // Fn_Lookup states: retrieves the value of a single element from a map, given its key. If the given key does not exist, // the given default value is returned instead. // Using the following will generate the correct cdk.tf.json output. For example... Notice the name field is now referenced correctly. // "resource_group_workaround": { // "//": { // "metadata": { // "path": "naming-output-failure-example/resource_group_workaround", // "uniqueId": "resource_group_workaround" // } // }, // "location": "Canada Central", // "name": "${module.resourceNaming.resource_group.name}" // } resourcegroup.NewResourceGroup(stack, jsii.String("resource_group_workaround"), &resourcegroup.ResourceGroupConfig{ Name: cdktf.Token_AsString(cdktf.Fn_Lookup(n.ResourceGroupOutput(), jsii.String("name"), nil), nil), Location: jsii.String("Canada Central"), }) ``` -------------------------------- ### Unique Resource Group Naming Source: https://github.com/azure/terraform-azurerm-naming/blob/master/README.md This example demonstrates how to generate a unique name for an Azure resource group by appending random characters. It utilizes the `name_unique` output from the naming module. ```terraform module "naming" { source = "Azure/naming/azurerm" suffix = [ "test" ] } resource "azurerm_resource_group" "example" { name = module.naming.resource_group.name_unique location = "West Europe" } ``` -------------------------------- ### Incorrect CDKTF Output Reference Source: https://github.com/azure/terraform-azurerm-naming/blob/master/docs/cdktf_usage.md This example shows an incorrect way to reference a module output in CDKTF, leading to invalid Terraform configuration. The `ResourceGroupOutput()` is directly used as a string, but it's a map. ```go // the following yields invalid cdk.tf.json output. cdk.tf.json contains the following ... // "location": "Canada Central", // "name": "${module.resourceNaming.resource_group}" // ... which is invalid because the name is not a string literal, we need to access the map key as such // "name": "${module.resourceNaming.resource_group.name}" resourcegroup.NewResourceGroup(stack, jsii.String("resource_group"), &resourcegroup.ResourceGroupConfig{ Name: n.ResourceGroupOutput(), // ResourceGroupOutput returns a string instead of a Map object. Location: jsii.String("Canada Central"), }) ``` -------------------------------- ### CDKTF Synthesized JSON (Incorrect) Source: https://github.com/azure/terraform-azurerm-naming/blob/master/docs/cdktf_usage.md This JSON snippet illustrates an incorrect `cdktf.json` output where a module output is referenced directly, leading to an error because it's treated as a string instead of a map. ```json "name": "${module.resourceNaming.resource_group}" ``` -------------------------------- ### Basic Resource Group Naming Source: https://github.com/azure/terraform-azurerm-naming/blob/master/README.md Use this snippet to generate a name for an Azure resource group using the naming module with a specified suffix. Ensure the module is correctly sourced. ```terraform module "naming" { source = "Azure/naming/azurerm" suffix = [ "test" ] } resource "azurerm_resource_group" "example" { name = module.naming.resource_group.name location = "West Europe" } ``` -------------------------------- ### CDKTF Synthesized JSON (Corrected) Source: https://github.com/azure/terraform-azurerm-naming/blob/master/docs/cdktf_usage.md This JSON snippet shows the corrected `cdktf.json` output after applying the workaround. It correctly references the 'name' property within the module output map. ```json "name": "${module.resourceNaming.resource_group.name}" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.