Hi, by using google provider I am creating 3 instances by using a managed instance group and that MIG uses an instance template to create these instances. I need to get those randomly created instance names and register them to DNS. Is there a way of doing this ?
resource “google_compute_instance_template” “etcd_template” {
name = “server-template”
description = “This template is used to create server instances.”
labels = {
environment = “dev”
}
instance_description = “description assigned to instances”
machine_type = “n1-standard-1”
can_ip_forward = false
scheduling {
automatic_restart = true
on_host_maintenance = “MIGRATE”
}
// Create a new boot disk from an image
// Use an existing disk resource
disk {
// Instance Templates reference disks by name, not self link
#source = google_compute_disk.foobar.name
source_image = “projects/my-sandbox/global/images/u16demo-1580244612”
auto_delete = false
boot = true
}
network_interface {
network = “default”
}
metadata = {
startup-script = file("./packer/init.sh")
}
service_account {
scopes = [“userinfo-email”, “compute-ro”, “storage-ro”]
}
}
resource “google_compute_region_instance_group_manager” “instance_group_manager” {
name = “instance-group-manager”
base_instance_name = “etcd”
region = “us-west1”
target_size = “3”
version {
name = “a_name”
instance_template = “${google_compute_instance_template.etcd_template.self_link}”
}
}
resource “google_compute_health_check” “etcd-tcp-health-check” {
name = “etcd-tcp-health-check”
check_interval_sec = 45
timeout_sec = 30
healthy_threshold = 2
unhealthy_threshold = 10
tcp_health_check {
port = “2379”
}
}
resource “google_compute_region_backend_service” “my-int-lb” {
name = “my-int-lb”
health_checks = [google_compute_health_check.etcd-tcp-health-check.self_link]
region = “${var.region}”
backend {
group = google_compute_region_instance_group_manager.instance_group_manager.instance_group
}
}
resource “google_compute_forwarding_rule” “my-int-lb-forwarding-rule” {
name = “my-int-lb-forwarding-rule”
load_balancing_scheme = “INTERNAL”
ports = [“2379”]
network = “{var.network_name}"
subnetwork = "{var.subnetwork_name}”
backend_service = “${google_compute_region_backend_service.my-int-lb.self_link}”
}
resource “google_compute_firewall” “allow-internal-lb” {
name = “allow-internal-lb”
network = “${var.network_name}”
allow {
protocol = “tcp”
ports = [“2379”]
}
source_ranges = [“10.138.0.0/20”]
target_tags = [“int-lb”]
}