Skip to content

Commit fc5d45e

Browse files
authored
Use Zone ID for DNS Aliases (#2)
* Pass parent zone id * Drop alias module * Add atlantis URL * Update desc
1 parent 04cd4bb commit fc5d45e

File tree

5 files changed

+30
-17
lines changed

5 files changed

+30
-17
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ Available targets:
190190
| default_backend_image | ECS default (bootstrap) image | string | `cloudposse/default-backend:0.1.2` | no |
191191
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
192192
| desired_count | Atlantis desired number of tasks | string | `1` | no |
193-
| domain_name | A domain name for which the certificate should be issued | string | - | yes |
194193
| ecs_cluster_arn | ARN of the ECS cluster to deploy Atlantis | string | - | yes |
195194
| ecs_cluster_name | Name of the ECS cluster to deploy Atlantis | string | - | yes |
196195
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `false` | no |
@@ -202,6 +201,7 @@ Available targets:
202201
| name | Application or solution name (e.g. `app`) | string | `ecs` | no |
203202
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
204203
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | string | `true` | no |
204+
| parent_zone_id | The zone ID where the DNS record for the `short_name` will be written | string | `` | no |
205205
| policy_arn | Permission to grant to atlantis server | string | `arn:aws:iam::aws:policy/AdministratorAccess` | no |
206206
| private_subnet_ids | The private subnet IDs | list | `<list>` | no |
207207
| region | AWS Region for Atlantis deployment | string | `us-west-2` | no |
@@ -222,7 +222,8 @@ Available targets:
222222
| Name | Description |
223223
|------|-------------|
224224
| atlantis_ssh_public_key | Atlantis SSH Public Key |
225-
| badge_url | the url of the build badge when badge_enabled is enabled |
225+
| atlantis_url | The URL endpoint for the atlantis server |
226+
| badge_url | The URL of the build badge when `badge_enabled` is enabled |
226227

227228

228229

docs/terraform.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
| default_backend_image | ECS default (bootstrap) image | string | `cloudposse/default-backend:0.1.2` | no |
3434
| delimiter | Delimiter to be used between `namespace`, `stage`, `name` and `attributes` | string | `-` | no |
3535
| desired_count | Atlantis desired number of tasks | string | `1` | no |
36-
| domain_name | A domain name for which the certificate should be issued | string | - | yes |
3736
| ecs_cluster_arn | ARN of the ECS cluster to deploy Atlantis | string | - | yes |
3837
| ecs_cluster_name | Name of the ECS cluster to deploy Atlantis | string | - | yes |
3938
| enabled | Whether to create the resources. Set to `false` to prevent the module from creating any resources | string | `false` | no |
@@ -45,6 +44,7 @@
4544
| name | Application or solution name (e.g. `app`) | string | `ecs` | no |
4645
| namespace | Namespace (e.g. `eg` or `cp`) | string | - | yes |
4746
| overwrite_ssm_parameter | Whether to overwrite an existing SSM parameter | string | `true` | no |
47+
| parent_zone_id | The zone ID where the DNS record for the `short_name` will be written | string | `` | no |
4848
| policy_arn | Permission to grant to atlantis server | string | `arn:aws:iam::aws:policy/AdministratorAccess` | no |
4949
| private_subnet_ids | The private subnet IDs | list | `<list>` | no |
5050
| region | AWS Region for Atlantis deployment | string | `us-west-2` | no |
@@ -65,5 +65,6 @@
6565
| Name | Description |
6666
|------|-------------|
6767
| atlantis_ssh_public_key | Atlantis SSH Public Key |
68-
| badge_url | the url of the build badge when badge_enabled is enabled |
68+
| atlantis_url | The URL endpoint for the atlantis server |
69+
| badge_url | The URL of the build badge when `badge_enabled` is enabled |
6970

main.tf

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ locals {
2323
atlantis_gh_webhook_secret = "${length(var.atlantis_gh_webhook_secret) > 0 ? var.atlantis_gh_webhook_secret : join("", random_string.atlantis_gh_webhook_secret.*.result)}"
2424
atlantis_url = "${format(var.atlantis_webhook_format, local.hostname)}"
2525
attributes = "${concat(list(var.short_name), var.attributes)}"
26-
default_hostname = "${var.short_name}.${var.domain_name}"
26+
default_hostname = "${join("", aws_route53_record.default.*.fqdn)}"
2727
github_oauth_token = "${length(join("", data.aws_ssm_parameter.atlantis_gh_token.*.value)) > 0 ? join("", data.aws_ssm_parameter.atlantis_gh_token.*.value) : var.github_oauth_token}"
2828
github_oauth_token_ssm_name = "${length(var.github_oauth_token_ssm_name) > 0 ? var.github_oauth_token_ssm_name : format(var.chamber_format, var.chamber_service, "atlantis_gh_token")}"
2929
hostname = "${length(var.hostname) > 0 ? var.hostname : local.default_hostname}"
@@ -44,15 +44,6 @@ module "ssh_key_pair" {
4444
ssm_path_prefix = "${var.chamber_service}"
4545
}
4646

47-
module "hostname" {
48-
source = "git::https://github.com/cloudposse/terraform-aws-route53-alias.git?ref=tags/0.2.7"
49-
enabled = "${local.enabled}"
50-
aliases = ["${local.hostname}"]
51-
parent_zone_name = "${var.domain_name}"
52-
target_dns_name = "${var.alb_dns_name}"
53-
target_zone_id = "${var.alb_zone_id}"
54-
}
55-
5647
module "webhooks" {
5748
source = "git::https://github.com/cloudposse/terraform-github-repository-webhooks.git?ref=tags/0.1.1"
5849
github_token = "${local.github_oauth_token}"
@@ -146,6 +137,20 @@ module "web_app" {
146137

147138
# Resources
148139
#--------------------------------------------------------------
140+
141+
resource "aws_route53_record" "default" {
142+
count = "${local.enabled ? 1 : 0}"
143+
zone_id = "${var.parent_zone_id}"
144+
name = "${var.short_name}"
145+
type = "A"
146+
147+
alias {
148+
name = "${var.alb_dns_name}"
149+
zone_id = "${var.alb_zone_id}"
150+
evaluate_target_health = "false"
151+
}
152+
}
153+
149154
resource "random_string" "atlantis_gh_webhook_secret" {
150155
count = "${local.enabled ? 1 : 0}"
151156
length = "${var.webhook_secret_length}"

outputs.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ output "atlantis_ssh_public_key" {
44
}
55

66
output "badge_url" {
7-
description = "the url of the build badge when badge_enabled is enabled"
7+
description = "The URL of the build badge when `badge_enabled` is enabled"
88
value = "${module.web_app.badge_url}"
99
}
10+
11+
output "atlantis_url" {
12+
description = "The URL endpoint for the atlantis server"
13+
value = "${local.atlantis_url}"
14+
}

variables.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,10 @@ variable "region" {
317317
default = "us-west-2"
318318
}
319319

320-
variable "domain_name" {
320+
variable "parent_zone_id" {
321321
type = "string"
322-
description = "A domain name for which the certificate should be issued"
322+
description = "The zone ID where the DNS record for the `short_name` will be written"
323+
default = ""
323324
}
324325

325326
variable "overwrite_ssm_parameter" {

0 commit comments

Comments
 (0)