If I was to use this example to create an Azure Container Environment and Apps via Terraform, I would find some additional resources created in a new resource group with a random name:
My question is, can we use Terraform to create those so that I can apply naming conventions, tags etc.
2
Answers
When you deploy resources in Azure using Terraform, Azure sometimes creates additional, ancillary resources to support the primary resource. These automatically generated resources usually come with auto-generated names.
Some Azure resources inherently depend on other resources. For example, when you create a Virtual Machine, Azure might create additional resources like a Network Interface Card (NIC) if you don’t specify an existing one.
To avoid surprises, I always, Before applying any changes, run terraform plan. This will show you all the resources Terraform intends to create, modify, or destroy. This is a good chance to catch unexpected resources.
If there are resources you find being created automatically and you want to define and control them via Terraform, you can:
To create resources with your
own naming conventions
, below is theTerraform code
${var.resource_prefix}"
is a constant value used for all resources."${var.blob_private_endpoint}"
allows you to define a custom resource name at the time of input.For example, if "resource_prefix" is set to "Prod" and "blob_private_endpoint" is set to "demoendpoint," the resource name is created as follows: [resource_prefix]-demoendpoint
Kindly follow the same format in all resources.
Terraform Plan:
Here is terraform code to create Azure Container Environment and Apps with network resources using own naming convention.
Varaible.tf
Resources
are created in portal with my own naming convention, as below.