In order to automate the creation of the resource group, I want to use a generic Terraform script
As an example, the below script creates the resource group in Azure based on the input values provided in the *.tfvars.json file
main.tf
# Configure the Microsoft Azure provider
provider "azurerm" {
features {}
}
# Create a Resource Group if it doesn’t exist
resource "azurerm_resource_group" "example" {
name = var.resource_group_name
location = "West US"
}
vars.tf
# Input variable: image sku
variable "resource_group_name" {
description = "Name of the resource group"
default = "example-resources"
}
testing.tfvars.json
{
"resource_group_name":"example-resources-testing"
}
and executed like
terraform apply --auto-approve -var-file="testing.tfvars.json"
Before creating the new resource group, it destroys the existing one. I don't want to destroy the existing resource group, just create a new one.
I don't want to clone the script. What should I do to use the generic Terraform script repeatedly without destroying the existing one? Is it just a matter of disabling or removing the state before execution?