Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1 from cabify/add_module_to_add_gci_and_private_dns
Browse files Browse the repository at this point in the history
Create module to add gci resources with private dns
  • Loading branch information
jvrplmlmn authored Oct 19, 2017
2 parents 76f15c8 + e11a099 commit 5ff93b9
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
21 changes: 21 additions & 0 deletions google_vm_with_r53_private_dns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Terraform Google VM with r53 private dns

Create a Google Compute Instance with a private DNS record in route53

### Example usage

In the following example we're creating 3 nomad agent instances.

```
module "nomad_agent" {
source = "[email protected]:cabify/terraform-modules.git//google_vm_with_r53_private_dns?ref=1aac443ede51bc46a0a4b1d3493287e1537ade57"
gce_zone = "${data.terraform_remote_state.testing.gce-zone}"
component = "nomad"
host_group = "nomad"
instance_count = "3"
aws_route53_zone_id = "${data.terraform_remote_state.testing.aws_route53_zone_id}"
aws_route53_zone_name = "${data.terraform_remote_state.testing.aws_route53_zone_name}"
machine_type = "n1-standard-1"
google_deployer_ssh_public_key = "${data.terraform_remote_state.testing.google_deployer_ssh_public_key}"
}
```
45 changes: 45 additions & 0 deletions google_vm_with_r53_private_dns/inputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
variable "gce_zone" {
type = "string"
default = ""
}

variable "aws_route53_zone_id" {
type = "string"
default = ""
}

variable "aws_route53_zone_name" {
type = "string"
default = ""
}

variable "component" {
type = "string"
default = "default_component"
}

variable "host_group" {
type = "string"
default = "default_host_group"
}

variable "instance_count" {
type = "string"
default = 0
}

variable "machine_type" {
type = "string"
default = "n1-standard-1"
}

variable "os_image" {
description = "OS GCE identifier"
type = "string"
default = "ubuntu-1404-lts"
}

variable "google_deployer_ssh_public_key" {
type = "string"
default = ""
}
36 changes: 36 additions & 0 deletions google_vm_with_r53_private_dns/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
resource "google_compute_instance" "vm" {
name = "${var.component}${count.index + 1}"
machine_type = "${var.machine_type}"
zone = "${var.gce_zone}"
count = "${var.instance_count}"

boot_disk {
initialize_params {
image = "${var.os_image}"
}
}

scratch_disk {}

network_interface {
network = "default"

access_config {}
}

metadata {
host_group = "${var.host_group}"
ssh-keys = "${var.google_deployer_ssh_public_key}"
}
}

resource "aws_route53_record" "dns-int" {
zone_id = "${var.aws_route53_zone_id}"
name = "${var.component}${count.index + 1}.int.${var.aws_route53_zone_name}"
type = "A"
ttl = "60"
count = "${var.instance_count}"

// matches up record N to instance N
records = ["${element(google_compute_instance.vm.*.network_interface.0.address,count.index)}"]
}

0 comments on commit 5ff93b9

Please sign in to comment.