TeeTee
TeeTee

Reputation: 147

Attach Domain Name to private internal IP with GCP terraform

Hi I am to create a DNS record for my DNS zone so I can set up ssh to via hostname instead of an IP address. I can't quite get terraform to create the domain name for my use case. How can I get it to work? I can't find the right value for rrdatas. The IP for the internal address is arbitrary as long as it's on the subnet specified for the VM.

resource "google_compute_instance" "tyler_test_vm_instance" {
   count = var.node_count
   name = "jenkins-worker-test-${count.index}"
   machine_type = "n2-standard-2"
   min_cpu_platform = "Intel Ice Lake"
   attached_disk {
     source = google_compute_disk.jenkins_data_disk.*.id[count.index]
     device_name = "jenkins-data-test"
   }
   attached_disk {
       source = google_compute_disk.docker_data_disk.*.id[count.index]
       device_name = "docker-data-test"

   }

   lifecycle {
       create_before_destroy = true
       ignore_changes = [
         attached_disk
       ]
   }

   service_account { 
       email = "[email protected]"
       scopes = ["cloud-platform"]

   }
   
   boot_disk {
       initialize_params {
           image = "ubuntu-1804-bionic-v20220805"
       }
   }

   network_interface {
       network = var.gcp_project_network_name
       subnetwork = var.subnet_name
   }
   metadata_startup_script = "${file(var.startup_script)}"
}


resource "google_dns_record_set" "rs" {
   count = var.node_count
   name = "jenkins-worker-test-${count.index}.com"
   type = "A"
   ttl = 300
   managed_zone = "corp-org-com"
#no idea what goes in rrdatas. None of these work.
   #rrdatas = ["jenkins-worker-test-${count.index}.com"]
   rrdatas = [google_compute_instance.tyler_test_vm_instance.*.id[count.index].network_interface.network.network_ip]
   #rrdatas = [google_compute_instance.tyler_test_vm_instance.*.id[count.index].network_interface[0]]
}

Upvotes: -1

Views: 739

Answers (1)

TeeTee
TeeTee

Reputation: 147

I had the wrong rrdatas and was using the wrong record for the name.

I should of been using "jenkins-worker-test-${count.index}.corp.domain.com." This needed a . at the end. and rrdatas should have looked like this. rrdatas = [google_compute_instance.tyler_test_vm_instance.*[count.index].network_interface.0.network_ip]

Once I changed these values I was able to get everything to work.

Upvotes: 2

Related Questions