Resolve the default security group UUID dynamically instead of hardcoding it
The "default" security group VK Cloud auto-creates in every project has a UUID unique to that project, but main.tf hardcoded one project's UUID across all 4 instance resources (router, priv_srv_01/02/03) - not portable to another project. Replaced with data.vkcs_networking_secgroup (matched by name = "default", verified against the real provider schema via terraform providers schema -json on the local provider mirror) behind local.default_security_group_id. The new default_security_group_id variable is a last-resort manual override via coalesce() for projects where the lookup doesn't fit (non-standard name/SDN) - not the normal path. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011hXR2ftXZZhJ4Y3XuSoR8r
This commit is contained in:
1 parent
1ef4b12143
commit
b5d6367fd8
7 files changed
+174
-6
No files matched your search
+20
-4
@@ -12,6 +12,22 @@ data "vkcs_networking_network" "extnet" {
|
||||
sdn = "sprut"
|
||||
}
|
||||
|
||||
# Every VK Cloud project auto-creates a "default" security group with a
|
||||
# UUID unique to that project - resolve it dynamically instead of
|
||||
# hardcoding one project's UUID. var.default_security_group_id is a
|
||||
# last-resort manual override (e.g. non-standard name/SDN in a project).
|
||||
data "vkcs_networking_secgroup" "default" {
|
||||
name = "default"
|
||||
sdn = "sprut"
|
||||
}
|
||||
|
||||
locals {
|
||||
default_security_group_id = coalesce(
|
||||
var.default_security_group_id,
|
||||
data.vkcs_networking_secgroup.default.id
|
||||
)
|
||||
}
|
||||
|
||||
# LAN Network
|
||||
resource "vkcs_networking_network" "lan_net" {
|
||||
name = "router-lan-net"
|
||||
@@ -164,7 +180,7 @@ resource "vkcs_compute_instance" "router" {
|
||||
|
||||
security_group_ids = [
|
||||
vkcs_networking_secgroup.router_sg.id,
|
||||
"d479b4d7-55b3-4ff1-bf8d-24d826a38f11"
|
||||
local.default_security_group_id
|
||||
]
|
||||
|
||||
config_drive = true
|
||||
@@ -213,7 +229,7 @@ resource "vkcs_compute_instance" "priv_srv_01" {
|
||||
|
||||
security_group_ids = [
|
||||
vkcs_networking_secgroup.private_sg.id,
|
||||
"d479b4d7-55b3-4ff1-bf8d-24d826a38f11"
|
||||
local.default_security_group_id
|
||||
]
|
||||
|
||||
network {
|
||||
@@ -241,7 +257,7 @@ resource "vkcs_compute_instance" "priv_srv_02" {
|
||||
|
||||
security_group_ids = [
|
||||
vkcs_networking_secgroup.private_sg.id,
|
||||
"d479b4d7-55b3-4ff1-bf8d-24d826a38f11"
|
||||
local.default_security_group_id
|
||||
]
|
||||
|
||||
network {
|
||||
@@ -268,7 +284,7 @@ resource "vkcs_compute_instance" "priv_srv_03" {
|
||||
|
||||
security_group_ids = [
|
||||
vkcs_networking_secgroup.private_sg.id,
|
||||
"d479b4d7-55b3-4ff1-bf8d-24d826a38f11"
|
||||
local.default_security_group_id
|
||||
]
|
||||
|
||||
network {
|
||||
|
||||
Reference in new issue
Block a user