dev
provider.tf
# Provider Configuration
# provider "azurerm" {
# features {}
# }
# Module for Azure API Management
module "apim" {
source = "../modules/apim"
# Pass any required variables to the APIM module
# apim_service_name = var.apim_service_name
# resource_group_name = var.resource_group_name
# Add any other required variables here
}
# Define a data source for the existing resource group
data "azurerm_resource_group" "dev_neogenomics_rg" {
name = "rg-esp-dev"
}
# Define a data source for the existing virtual network
data "azurerm_virtual_network" "dev_neogenomics_rg_vnet" {
name = "VNET-Dev-10.117.128.0-17"
resource_group_name = data.azurerm_resource_group.dev_neogenomics_rg.name
}
# Define a data source for the existing subnet within the virtual network
data "azurerm_subnet" "dev_neogenomics_subnet" {
name = "PrivateEndpointDev-Subnet"
virtual_network_name = data.azurerm_virtual_network.dev_neogenomics_rg_vnet.name
resource_group_name = data.azurerm_resource_group.dev_neogenomics_rg.name
}
# Example resource within the existing subnet
resource "azurerm_network_interface" "dev-network-nic" {
name = "dev-neogenomics-nic"
location = data.azurerm_resource_group.dev_neogenomics_rg.location
resource_group_name = data.azurerm_resource_group.dev_neogenomics_rg.name
ip_configuration {
name = "internal"
subnet_id = data.azurerm_subnet.dev_neogenomics_subnet.id
private_ip_address_allocation = "Dynamic"
}
}
# Run the script to set the credentials from environment variables
resource "null_resource" "set_credentials" {
provisioner "local-exec" {
command = "${path.module}/set_credentials.ps1"
}
}
# Configure the Azure provider
provider "azurerm" {
features {}
# Pass subscription ID, client ID, client secret, and tenant ID as variables
subscription_id = var.subscription_id
client_id = data.azurerm_key_vault_secret.client_id.value
client_secret = data.azurerm_key_vault_secret.client_secret.value
tenant_id = var.tenant_id
}
# Retrieve client ID and client secret from Azure Key Vault
data "azurerm_key_vault_secret" "client_id" {
name = var.key_vault_client_id_secret_name
key_vault_id = var.key_vault_id
}
data "azurerm_key_vault_secret" "client_secret" {
name = var.key_vault_client_secret_secret_name
key_vault_id = var.key_vault_id
}
provider "azurerm" {
subscription_id = var.subscription_id_dev
client_id = var.client_id_dev
client_secret = var.client_secret_dev
tenant_id = var.tenant_id_dev
features {} # Optional: You can specify additional features here if needed
}
data "azurerm_resource_group" "existing_rg" {
name = "existing-resource-group-name" # Replace with the actual name of the existing resource group
}
data "azurerm_virtual_network" "existing_vnet" {
name = "existing-vnet-name" # Replace with the actual name of the existing VNet
resource_group_name = data.azurerm_resource_group.existing_rg.name
}
data "azurerm_subnet" "existing_subnet" {
name = "existing-subnet-name" # Replace with the actual name of the existing subnet
virtual_network_name = data.azurerm_virtual_network.existing_vnet.name
resource_group_name = data.azurerm_resource_group.existing_rg.name
}
# Now you can define your resources to use the existing VNet and subnet
# Example resource within the existing subnet
resource "azurerm_network_interface" "example" {
name = "example-nic"
location = data.azurerm_resource_group.existing_rg.location
resource_group_name = data.azurerm_resource_group.existing_rg.name
ip_configuration {
name = "internal"
subnet_id = data.azurerm_subnet.existing_subnet.id
private_ip_address_allocation = "Dynamic"
}
}
# Add more resources as needed, ensuring they're configured to use the existing VNet and subnet
provider.tf
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.0"
}
}
}
provider "azurerm" {
features {}
}
# Define a data source for the existing resource group
data "azurerm_resource_group" "existing_rg" {
name = "existing-resource-group-name"
}
# Define a data source for the existing virtual network
data "azurerm_virtual_network" "existing_vnet" {
name = "existing-vnet-name"
resource_group_name = data.azurerm_resource_group.existing_rg.name
}
# Define a data source for the existing subnet within the virtual network
data "azurerm_subnet" "existing_subnet" {
name = "existing-subnet-name"
virtual_network_name = data.azurerm_virtual_network.existing_vnet.name
resource_group_name = data.azurerm_resource_group.existing_rg.name
}
# Example resource within the existing subnet
resource "azurerm_network_interface" "example" {
name = "example-nic"
location = data.azurerm_resource_group.existing_rg.location
resource_group_name = data.azurerm_resource_group.existing_rg.name
ip_configuration {
name = "internal"
subnet_id = data.azurerm_subnet.existing_subnet.id
private_ip_address_allocation = "Dynamic"
}
}
====
Variables.tf
variable "vnet_name" {
description = "Name of the virtual network"
}
variable "resource_group_name" {
description = "Name of the resource group"
}
variable "subnet_name" {
description = "Name of the subnet"
}
variable "location" {
description = "Location for Azure resources"
}
variable "address_space" {
description = "Address space for the virtual network"
type = list(string)
}
variable "subnet_address_prefixes" {
description = "Address prefixes for the subnet"
type = list(string)
}
# Add more variables as needed for other configuration parameters
====terraform.tfvars
# Azure Credentials (replace with your actual values)
arm_client_id = "your_client_id"
arm_client_secret = "your_client_secret"
arm_subscription_id = "your_subscription_id"
arm_tenant_id = "your_tenant_id"
# Other environment-specific variables (optional)
location = "your_desired_location" # Azure region where resources will be deployed
# Example: Variable for resource naming (optional)
name_prefix = "dev-" # Prefixes resource names for Dev environment
main.tf
# Provider Configuration
provider "azurerm" {
features {}
}
# Module for Azure API Management
module "apim" {
source = "../modules/apim"
# Pass any required variables to the APIM module
subscription_id = var.subscription_id
tenant_id = var.tenant_id
resource_group_name = var.resource_group_name
key_vault_name = var.key_vault_name
key_vault_secret_name = var.key_vault_secret_name
# Add any other required variables here
}
output.tf
output "apim_endpoint" {
description = "The endpoint URL of the Azure API Management service"
value = module.apim.endpoint
}
output "apim_sku_name" {
description = "The SKU name of the Azure API Management service"
value = module.apim.sku_name
}
output "apim_sku_capacity" {
description = "The SKU capacity of the Azure API Management service"
value = module.apim.sku_capacity
}
# Add more outputs as needed
statefile
# Azure Storage Account
resource "azurerm_storage_account" "tf_state" {
name = "tfstate${var.environment}"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "LRS"
tags = {
environment = var.environment
}
}
# Blob Container
resource "azurerm_storage_container" "tf_state" {
name = "terraform-state"
storage_account_name = azurerm_storage_account.tf_state.name
container_access_type = "private"
}
# Backend Configuration
terraform {
backend "azurerm" {
resource_group_name = azurerm_resource_group.example.name
storage_account_name = azurerm_storage_account.tf_state.name
container_name = azurerm_storage_container.tf_state.name
key = "terraform.tfstate"
}
}
===
# main.tf
# Run the script to set the credentials from environment variables
resource "null_resource" "set_credentials" {
provisioner "local-exec" {
command = "${path.module}/set_credentials.ps1"
}
}
# Configure the Azure provider
provider "azurerm" {
features {}
subscription_id = var.subscription_id
client_id = data.azurerm_key_vault_secret.client_id.value
client_secret = data.azurerm_key_vault_secret.client_secret.value
tenant_id = var.tenant_id
}
# Retrieve client ID and client secret from Azure Key Vault
data "azurerm_key_vault_secret" "client_id" {
name = var.key_vault_client_id_secret_name
key_vault_id = var.key_vault_id
}
data "azurerm_key_vault_secret" "client_secret" {
name = var.key_vault_client_secret_secret_name
key_vault_id = var.key_vault_id
}
Comments
Post a Comment