Skip to content

Commit de27bb0

Browse files
Add backend resources and update VMSS resource group
Introduces backend.tf to provision a dedicated resource group and storage for Terraform state. Updates vmss.tf to create and reference the resource group directly, ensuring consistency with the backend state resources.
1 parent 5e5cbb2 commit de27bb0

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

gh-runners/backend.tf

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Resource group for Terraform state storage
2+
resource "azurerm_resource_group" "tfstate" {
3+
name = "dbatools-ci-runners"
4+
location = var.location
5+
6+
tags = {
7+
Environment = "CI"
8+
ManagedBy = "Terraform"
9+
Purpose = "Terraform-State"
10+
}
11+
}
12+
13+
# Storage account for Terraform state
14+
resource "azurerm_storage_account" "tfstate" {
15+
name = "dbatoolstfstate"
16+
resource_group_name = azurerm_resource_group.tfstate.name
17+
location = azurerm_resource_group.tfstate.location
18+
account_tier = "Standard"
19+
account_replication_type = "LRS"
20+
min_tls_version = "TLS1_2"
21+
22+
tags = {
23+
Environment = "CI"
24+
ManagedBy = "Terraform"
25+
Purpose = "Terraform-State"
26+
}
27+
}
28+
29+
# Storage container for Terraform state files
30+
resource "azurerm_storage_container" "tfstate" {
31+
name = "tfstate"
32+
storage_account_name = azurerm_storage_account.tfstate.name
33+
container_access_type = "private"
34+
}

gh-runners/vmss.tf

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
# Get current Azure context
22
data "azurerm_client_config" "current" {}
33

4-
# Reference existing resource group
5-
data "azurerm_resource_group" "rg" {
6-
name = var.resource_group_name
4+
# Use the resource group created in backend.tf
5+
# This references the same resource group used for Terraform state
6+
resource "azurerm_resource_group" "rg" {
7+
name = var.resource_group_name
8+
location = var.location
9+
10+
tags = {
11+
Environment = "CI"
12+
ManagedBy = "Terraform"
13+
}
714
}
815

916
# Reference existing Key Vault
@@ -21,8 +28,8 @@ data "azurerm_image" "golden" {
2128
# Create virtual network for VMSS
2229
resource "azurerm_virtual_network" "vnet" {
2330
name = "${var.vmss_name}-vnet"
24-
resource_group_name = data.azurerm_resource_group.rg.name
25-
location = data.azurerm_resource_group.rg.location
31+
resource_group_name = azurerm_resource_group.rg.name
32+
location = azurerm_resource_group.rg.location
2633
address_space = ["10.0.0.0/16"]
2734

2835
tags = {
@@ -34,16 +41,16 @@ resource "azurerm_virtual_network" "vnet" {
3441
# Create subnet for VMSS
3542
resource "azurerm_subnet" "subnet" {
3643
name = "${var.vmss_name}-subnet"
37-
resource_group_name = data.azurerm_resource_group.rg.name
44+
resource_group_name = azurerm_resource_group.rg.name
3845
virtual_network_name = azurerm_virtual_network.vnet.name
3946
address_prefixes = ["10.0.1.0/24"]
4047
}
4148

4249
# Windows Virtual Machine Scale Set with custom image
4350
resource "azurerm_windows_virtual_machine_scale_set" "vmss" {
4451
name = var.vmss_name
45-
resource_group_name = data.azurerm_resource_group.rg.name
46-
location = data.azurerm_resource_group.rg.location
52+
resource_group_name = azurerm_resource_group.rg.name
53+
location = azurerm_resource_group.rg.location
4754
sku = var.vm_sku
4855
instances = var.min_instances
4956
admin_username = var.admin_username

0 commit comments

Comments
 (0)