Skip to content
This repository was archived by the owner on Feb 27, 2025. It is now read-only.

Commit fd74e4b

Browse files
author
Anshul Sharma
committed
Ubuntu 18.04 Support
1 parent 5a5ef5a commit fd74e4b

File tree

15 files changed

+350
-16
lines changed

15 files changed

+350
-16
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ To deploy Consul clients for production using this repo:
4444
1. Use the [install-consul module](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-consul) to install Consul alongside your application code.
4545
1. Before booting your app, execute the [run-consul script](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/run-consul) with `--client` flag.
4646
1. Your app can now use the local Consul agent for service discovery and key/value storage.
47-
1. Optionally, you can use the [install-dnsmasq module](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-dnsmasq) to configure Consul as the DNS for a
47+
1. Optionally, you can use the [install-dnsmasq module](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-dnsmasq) for Ubuntu 16.04 and Amazon Linux 2 or [setup-systemd-resolved](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/setup-systemd-resolved) for Ubuntu 18.04 to configure Consul as the DNS for a
4848
specific domain (e.g. `.consul`) so that URLs such as `foo.service.consul` resolve automatically to the IP
4949
address(es) for a service `foo` registered in Consul (all other domain names will be continue to resolve using the
5050
default resolver on the OS).
@@ -94,7 +94,11 @@ Gruntwork can help with:
9494
to create the cluster.
9595

9696
* [install-dnsmasq module](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-dnsmasq): Install [Dnsmasq](http://www.thekelleys.org.uk/dnsmasq/doc.html)
97-
and configure it to forward requests for a specific domain to Consul. This allows you to use Consul as a DNS server
97+
for Ubuntu 16.04 and Amazon Linux 2 and configure it to forward requests for a specific domain to Consul. This allows you to use Consul as a DNS server
98+
for URLs such as `foo.service.consul`.
99+
100+
* [setup-systemd-resolved module](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/setup-systemd-resolved): Setup [systemd-resolved](https://www.freedesktop.org/software/systemd/man/resolved.conf.html)
101+
for ubuntu 18.04 and configure it to forward requests for a specific domain to Consul. This allows you to use Consul as a DNS server
98102
for URLs such as `foo.service.consul`.
99103

100104
* [consul-iam-policies](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/consul-iam-policies): Defines the IAM policies necessary for a Consul cluster.

examples/consul-ami/README.md

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Consul AMI
22

33
This folder shows an example of how to use the [install-consul](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-consul) and
4-
[install-dnsmasq](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-dnsmasq) modules with [Packer](https://www.packer.io/) to create [Amazon Machine
4+
either [install-dnsmasq](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-dnsmasq) for Ubuntu 16.04 and Amazon Linux 2 or [setup-systemd-resolved](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/setup-systemd-resolved) for Ubuntu 18.04 modules with [Packer](https://www.packer.io/) to create [Amazon Machine
55
Images (AMIs)](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) that have Consul and Dnsmasq installed on
66
top of:
77

88
1. Ubuntu 16.04
9+
1. Ubuntu 18.04
910
1. Amazon Linux 2
1011

1112
These AMIs will have [Consul](https://www.consul.io/) installed and configured to automatically join a cluster during
@@ -15,7 +16,7 @@ services](https://www.consul.io/intro/getting-started/services.html) for instruc
1516
in Consul). To see how to deploy this AMI, check out the [consul-cluster example](https://github.com/hashicorp/terraform-aws-consul/tree/master/examples/root-example).
1617

1718
For more info on Consul installation and configuration, check out the
18-
[install-consul](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-consul) and [install-dnsmasq](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-dnsmasq) documentation.
19+
[install-consul](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-consul) and [install-dnsmasq](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/install-dnsmasq) for Ubuntu 16.04 and Amazon Linux 2 or [setup-systemd-resolved](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/setup-systemd-resolved) for Ubuntu 18.04 documentation.
1920

2021
## Dependencies
2122
1. AWSCLI must be installed on the base AMI in order for run-consul to run
@@ -57,10 +58,23 @@ provisioner. Instead of:
5758
},{
5859
"type": "shell",
5960
"inline": [
60-
"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}}",
61+
"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}}"
62+
],
63+
"pause_before": "30s"
64+
},{
65+
"type": "shell",
66+
"only": ["ubuntu16-ami", "amazon-linux-2-ami"],
67+
"inline": [
6168
"/tmp/terraform-aws-consul/modules/install-dnsmasq/install-dnsmasq"
6269
],
6370
"pause_before": "30s"
71+
},{
72+
"type": "shell",
73+
"only": ["ubuntu18-ami"],
74+
"inline": [
75+
"/tmp/terraform-aws-consul/modules/setup-systemd-resolved/setup-systemd-resolved"
76+
],
77+
"pause_before": "30s"
6478
}]
6579
}
6680
```
@@ -73,10 +87,23 @@ Your code should look more like this:
7387
"type": "shell",
7488
"inline": [
7589
"git clone --branch <MODULE_VERSION> https://github.com/hashicorp/terraform-aws-consul.git /tmp/terraform-aws-consul",
76-
"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}}",
90+
"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}}"
91+
],
92+
"pause_before": "30s"
93+
},{
94+
"type": "shell",
95+
"only": ["ubuntu16-ami", "amazon-linux-2-ami"],
96+
"inline": [
7797
"/tmp/terraform-aws-consul/modules/install-dnsmasq/install-dnsmasq"
7898
],
7999
"pause_before": "30s"
100+
},{
101+
"type": "shell",
102+
"only": ["ubuntu18-ami"],
103+
"inline": [
104+
"/tmp/terraform-aws-consul/modules/setup-systemd-resolved/setup-systemd-resolved"
105+
],
106+
"pause_before": "30s"
80107
}]
81108
}
82109
```

examples/consul-ami/consul.json

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"min_packer_version": "0.12.0",
33
"variables": {
44
"aws_region": "us-east-1",
5-
"consul_version": "1.2.2",
5+
"consul_version": "1.5.1",
66
"download_url": "{{env `CONSUL_DOWNLOAD_URL`}}"
77
},
88
"builders": [{
@@ -24,6 +24,26 @@
2424
"most_recent": true
2525
},
2626
"ssh_username": "ubuntu"
27+
},{
28+
"name": "ubuntu18-ami",
29+
"ami_name": "consul-ubuntu-{{isotime | clean_ami_name}}-{{uuid}}",
30+
"ami_description": "An Ubuntu 18.04 AMI that has Consul installed.",
31+
"instance_type": "t2.micro",
32+
"region": "{{user `aws_region`}}",
33+
"associate_public_ip_address": true,
34+
"type": "amazon-ebs",
35+
"source_ami_filter": {
36+
"filters": {
37+
"virtualization-type": "hvm",
38+
"architecture": "x86_64",
39+
"name": "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
40+
"block-device-mapping.volume-type": "gp2",
41+
"root-device-type": "ebs"
42+
},
43+
"owners": ["099720109477"],
44+
"most_recent": true
45+
},
46+
"ssh_username": "ubuntu"
2747
},{
2848
"name": "amazon-linux-2-ami",
2949
"ami_name": "consul-amazon-linux-2-{{isotime | clean_ami_name}}-{{uuid}}",
@@ -63,5 +83,19 @@
6383
"/tmp/terraform-aws-consul/modules/install-dnsmasq/install-dnsmasq"
6484
],
6585
"pause_before": "30s"
86+
},{
87+
"type": "shell",
88+
"only": ["ubuntu16-ami", "amazon-linux-2-ami"],
89+
"inline": [
90+
"/tmp/terraform-aws-consul/modules/install-dnsmasq/install-dnsmasq"
91+
],
92+
"pause_before": "30s"
93+
},{
94+
"type": "shell",
95+
"only": ["ubuntu18-ami"],
96+
"inline": [
97+
"/tmp/terraform-aws-consul/modules/setup-systemd-resolved/setup-systemd-resolved"
98+
],
99+
"pause_before": "30s"
66100
}]
67101
}

examples/example-with-encryption/packer/consul-with-certs.json

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,25 @@
2626
"most_recent": true
2727
},
2828
"ssh_username": "ubuntu"
29+
},{
30+
"name": "ubuntu18-ami",
31+
"ami_name": "consul-with-encryption-ubuntu-18.04-{{isotime | clean_ami_name}}-{{uuid}}",
32+
"ami_description": "An Ubuntu 16.04 AMI that has Consul installed and TLS certificates.",
33+
"instance_type": "t2.micro",
34+
"region": "{{user `aws_region`}}",
35+
"type": "amazon-ebs",
36+
"source_ami_filter": {
37+
"filters": {
38+
"virtualization-type": "hvm",
39+
"architecture": "x86_64",
40+
"name": "ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*",
41+
"block-device-mapping.volume-type": "gp2",
42+
"root-device-type": "ebs"
43+
},
44+
"owners": ["099720109477"],
45+
"most_recent": true
46+
},
47+
"ssh_username": "ubuntu"
2948
},{
3049
"ami_name": "consul-with-encryption-amazon-linux-2-{{isotime | clean_ami_name}}-{{uuid}}",
3150
"ami_description": "An Amazon Linux 2 AMI that has Consul installed and TLS certificates.",
@@ -65,9 +84,22 @@
6584
},{
6685
"type": "shell",
6786
"inline": [
68-
"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}} --ca-file-path /tmp/ca.crt.pem --cert-file-path /tmp/consul.crt.pem --key-file-path /tmp/consul.key.pem",
87+
"/tmp/terraform-aws-consul/modules/install-consul/install-consul --version {{user `consul_version`}} --ca-file-path /tmp/ca.crt.pem --cert-file-path /tmp/consul.crt.pem --key-file-path /tmp/consul.key.pem"
88+
],
89+
"pause_before": "30s"
90+
},{
91+
"type": "shell",
92+
"only": ["ubuntu16-ami", "amazon-linux-2-ami"],
93+
"inline": [
6994
"/tmp/terraform-aws-consul/modules/install-dnsmasq/install-dnsmasq"
7095
],
7196
"pause_before": "30s"
97+
},{
98+
"type": "shell",
99+
"only": ["ubuntu18-ami"],
100+
"inline": [
101+
"/tmp/terraform-aws-consul/modules/setup-systemd-resolved/setup-systemd-resolved"
102+
],
103+
"pause_before": "30s"
72104
}]
73105
}

modules/install-consul/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ This folder contains a script for installing Consul and its dependencies. Use th
88
This script has been tested on the following operating systems:
99

1010
* Ubuntu 16.04
11+
* Ubuntu 18.04
1112
* Amazon Linux 2
1213

1314
There is a good chance it will work on other flavors of Debian, CentOS, and RHEL as well.

modules/install-consul/install-consul

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# operating systems:
44
#
55
# 1. Ubuntu 16.04
6+
# 1. Ubuntu 18.04
67
# 1. Amazon Linux 2
78

89
set -e

modules/install-dnsmasq/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ it to forward requests for a specific domain to Consul. This way, you can easily
55
domain names such as `foo.service.consul`, where `foo` is a service registered with Consul (see the [Registering
66
Services docs](https://www.consul.io/intro/getting-started/services.html) for instructions on registering your services
77
with Consul). All other domain names will continue to be resolved via the default resolver on your OS. See the [Consul
8-
DNS Forwarding Guide](https://www.consul.io/docs/guides/forwarding.html) for more info.
8+
DNS Forwarding Guide](https://www.consul.io/docs/guides/forwarding.html) for more info, including trade-offs between using this module and [systemd-resolved](https://github.com/hashicorp/terraform-aws-consul/tree/master/modules/setup-systemd-resolved) for DNS forwarding.
9+
910

1011
This script has been tested on the following operating systems:
1112

modules/run-consul/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This folder contains a script for configuring and running Consul on an [AWS](htt
44
script has been tested on the following operating systems:
55

66
* Ubuntu 16.04
7+
* Ubuntu 18.04
78
* Amazon Linux 2
89

910
There is a good chance it will work on other flavors of Debian, CentOS, and RHEL as well.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# systemd-resolved Setup Script
2+
3+
This folder contains a script for configuring [systemd-resolved](http://man7.org/linux/man-pages/man8/systemd-resolved.service.8.html)
4+
to forward requests for a specific domain to Consul. This way, you can easily use Consul as your DNS server for
5+
domain names such as `foo.service.consul`, where `foo` is a service registered with Consul (see the [Registering
6+
Services docs](https://www.consul.io/intro/getting-started/services.html) for instructions on registering your services
7+
with Consul). All other domain names will continue to be resolved via the default resolver on your OS. See the [Consul
8+
DNS Forwarding Guide](https://www.consul.io/docs/guides/forwarding.html) and [Github Issue](https://github.com/hashicorp/consul/issues/4155) for more info.
9+
10+
11+
This script has been tested on the following operating systems:
12+
13+
* Ubuntu 18.04
14+
15+
## Quick start
16+
17+
To setup systemd-resolved, use `git` to clone this repository at a specific tag (see the [releases page](../../../../releases)
18+
for all available tags) and run the `setup-systemd-resolved` script:
19+
20+
```
21+
git clone --branch <VERSION> https://github.com/hashicorp/terraform-aws-consul.git
22+
terraform-aws-consul/modules/setup-systemd-resolved/setup-systemd-resolved
23+
```
24+
25+
Note: by default, the `setup-systemd-resolved` script assumes that a Consul agent is already running locally and connected to
26+
a Consul cluster. After the install completes, restart `systemd-resolved` (e.g. `sudo systemctl restart systemd-resolved.service`) and queries
27+
to the `.consul` domain will be resolved via Consul:
28+
29+
```
30+
dig foo.service.consul
31+
```
32+
33+
We recommend running the `setup-systemd-resolved` script as part of a [Packer](https://www.packer.io/) template to create an
34+
[Amazon Machine Image (AMI)](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AMIs.html) (see the
35+
[consul-ami example](https://github.com/hashicorp/terraform-aws-consul/tree/master/examples/consul-ami) for sample code).
36+
37+
38+
39+
40+
## Command line Arguments
41+
42+
The `setup-systemd-resolved` script accepts the following arguments:
43+
44+
* `consul-domain DOMAIN`: The domain name to point to Consul. Optional. Default: `consul`.
45+
* `consul-ip IP`: The IP address to use for Consul. Optional. Default: `127.0.0.1`. This assumes a Consul agent is
46+
running locally and connected to a Consul cluster.
47+
* `consul-dns-port PORT`: The port Consul uses for DNS requests. Optional. Default: `8600`.
48+
49+
Example:
50+
51+
```
52+
setup-systemd-resolved
53+
```
54+
55+
56+
57+
58+
## Troubleshooting
59+
60+
Add the `+trace` argument to `dig` commands to more clearly see what's going on:
61+
62+
```
63+
dig vault.service.consul +trace
64+
```

0 commit comments

Comments
 (0)