Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
Adjust default AMI removing Ent license requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpeteuil committed Oct 30, 2020
2 parents 22ffbd1 + faed9f4 commit 73020a0
Show file tree
Hide file tree
Showing 18 changed files with 433 additions and 62 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,20 @@ This repo can be used to show Consul service discovery, Consul Connect using bui
- AWS account & credentials
- AWS Route53 Subzone (that you have write permissions to)
- Terraform will create FQDNs for instances & load balancers in this subzone
- Consul Enterprise License (Highly Recommended)
- If not specified - Consul Enterprise demo-binary will shutdown in 30m
- After no-license shutdown
- demo will no longer work and `terraform destroy` will fail
- fix by rebooting each host (or restart consul service on each host)
- this re-starts Consul as Open Source Consul
- Consul Enterprise License is no longer required

### AWS AMIs

- AWS AMIs are available in HC account in `us-east-1` and `us-west-2`
- To customize AMIs view the [Packer README](./packer/README.md)
- AWS AMIs are available in HC account in `us-east-1`, `us-west-2`, `ap-southeast-1` and `ap-southeast-2`
- AMI default prefix `consul-into`
- changed when OSS AMIs were added to avoid mis-matches
- To customize AMIs view [Packer README](./packer/README.md)
- Consul Enterprise AMIs available in us-west-2 and east-1
- use these AMIs by setting Terraform vars
- `ami_prefix = "consul-demo-ent"`
- `consul_lic = "CONSUL-ENT-LICENSE-v2-TEXT"`
- published
- See [Packer README](./packer/README.md) to publish to other regions

## First Time Setup

Expand All @@ -68,8 +71,8 @@ This repo can be used to show Consul service discovery, Consul Connect using bui
- Set Terraform variables (in `terraform.auto.tfvars` or `setup-tfe.sh`)
- `ssh_key_name` - must exist in both AWS regions (default: us-west-2 & us-east-1)
- Specify either `ssh_pri_key_data` or `ssh_pri_key_file` that refers to private SSH key referenced by `ssh_key_name`
- `ssh_pri_key_file` - file path to the private key (does not work with TFC/TFE)
- `ssh_pri_key_data` - contents of private key as data with newlines replaced with `\n` (required for TFC/TFE)
- `ssh_pri_key_file` - file path to the private key
- `ssh_pri_key_data` - contents of private key as data with newlines replaced with `\n`
- remove newlines with command: `awk '{printf "%s\\n", $0}' ~/.ssh/id_rsa`

## Demo Script
Expand All @@ -78,11 +81,14 @@ This repo can be used to show Consul service discovery, Consul Connect using bui

- Deploy with Terraform (takes 3-4 minutes)
- (OPTIONAL) add aliases from Terraform output `working_aliases` to .bash_profile
- eliminates need to remove keys from known_hosts before each demo
- This eliminates need to remove known_hosts entries after each demo
- (OPTIONAL) bookmark web URLs specified in Terraform output `working connections`
- Edit `~/.ssh/known_hosts` and remove entries from previous demos (unless using ssh aliases)

### Setup Browser

- Follow instruction in Terraform output `working connections`
- Open two URL's in Browser
- Open two specified URL's in Browser
- web-page rendered by `web_client` service
- Consul UI
- Verify the all services are running in Consul UI
Expand Down
20 changes: 11 additions & 9 deletions packer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ ENCRYPT_CONFIG := files/encrypt.hcl

# if AMI_PREFIX is changed, new value must be specified in Terraform code
# using ami_prefix parameter for consul-demo-cluster module
AMI_PREFIX="consul-demo"
AMI_PREFIX="consul-intro"
AMI_OWNER=self
CONSUL_VER="1.7.3"
CONSUL_VER="1.8.5"
PROJ_SUFFIX="Q4-2020"
OWNER_TAG="rpeteuil@hashicorp.com"
BUILD_DATE := $(shell date +%Y%m%d-%H%M)

DEFAULT:
Expand Down Expand Up @@ -35,31 +37,31 @@ aws_client_product: aws_consul_client .built.aws_client_product
aws_client_webclient: aws_consul_client .built.aws_client_webclient

.built.aws_consul_base: consul_base.json files/install_base.sh files/install_consul.sh
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) packer build -only amazon-ebs consul_base.json
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX) OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs consul_base_oss.json
touch .built.aws_consul_base

.built.aws_consul_client: consul_client.json files/auto-join-aws.hcl.tmpl files/update-consul-join-config files/client.hcl
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) packer build -only amazon-ebs consul_client.json
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs consul_client.json
touch .built.aws_consul_client

.built.aws_consul_server: consul_server.json files/server.hcl
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) packer build -only amazon-ebs consul_server.json
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs consul_server_oss.json
touch .built.aws_consul_server

.built.aws_client_listing: client_listing.json files/install_node.sh services/listing.hcl files/listing.service
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) packer build -only amazon-ebs client_listing.json
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_listing.json
touch .built.aws_client_listing

.built.aws_client_mongodb: client_mongodb.json services/mongodb.hcl files/mongod.conf
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) packer build -only amazon-ebs client_mongodb.json
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_mongodb.json
touch .built.aws_client_mongodb

.built.aws_client_product: client_product.json services/product.hcl files/product.service
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) packer build -only amazon-ebs client_product.json
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_product.json
touch .built.aws_client_product

.built.aws_client_webclient: client_webclient.json services/web_client.hcl files/web_client.service
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) packer build -only amazon-ebs client_webclient.json
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_webclient.json
touch .built.aws_client_webclient

$(ENCRYPT_CONFIG):
Expand Down
70 changes: 70 additions & 0 deletions packer/Makefile-ent
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
ENCRYPT_CONFIG := files/encrypt.hcl

# if AMI_PREFIX is changed, new value must be specified in Terraform code
# using ami_prefix parameter for consul-demo-cluster module
AMI_PREFIX="consul-demo-ent"
AMI_OWNER=self
CONSUL_VER="1.8.5"
PROJ_SUFFIX="Q4-2020"
OWNER_TAG="rpeteuil@hashicorp.com"
BUILD_DATE := $(shell date +%Y%m%d-%H%M)

DEFAULT:
@echo Run 'make aws' to build appropriate images

.PHONY: aws
aws: aws_consul_server aws_client_mongodb aws_client_product aws_client_webclient aws_client_listing

.PHONY: aws_consul_base
aws_consul_base: .built.aws_consul_base

.PHONY: aws_consul_client
aws_consul_client: aws_consul_base .built.aws_consul_client

.PHONY: aws_consul_server
aws_consul_server: aws_consul_client .built.aws_consul_server

.PHONY: aws_client_listing
aws_client_listing: aws_consul_client .built.aws_client_listing

.PHONY: aws_client_mongodb
aws_client_mongodb: aws_consul_client .built.aws_client_mongodb

.PHONY: aws_client_product
aws_client_product: aws_consul_client .built.aws_client_product

.PHONY: aws_client_webclient
aws_client_webclient: aws_consul_client .built.aws_client_webclient

.built.aws_consul_base: consul_base.json files/install_base.sh files/install_consul.sh
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX) OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs consul_base.json
touch .built.aws_consul_base

.built.aws_consul_client: consul_client.json files/auto-join-aws.hcl.tmpl files/update-consul-join-config files/client.hcl
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs consul_client.json
touch .built.aws_consul_client

.built.aws_consul_server: consul_server.json files/server.hcl
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs consul_server.json
touch .built.aws_consul_server

.built.aws_client_listing: client_listing.json files/install_node.sh services/listing.hcl files/listing.service
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_listing.json
touch .built.aws_client_listing

.built.aws_client_mongodb: client_mongodb.json services/mongodb.hcl files/mongod.conf
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_mongodb.json
touch .built.aws_client_mongodb

.built.aws_client_product: client_product.json services/product.hcl files/product.service
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_product.json
touch .built.aws_client_product

.built.aws_client_webclient: client_webclient.json services/web_client.hcl files/web_client.service
BUILD_DATE=$(BUILD_DATE) AMI_OWNER=$(AMI_OWNER) CONSUL_VER=$(CONSUL_VER) AMI_PREFIX=$(AMI_PREFIX) PROJ_SUFFIX=$(PROJ_SUFFIX)OWNER_TAG=$(OWNER_TAG) packer build -only amazon-ebs client_webclient.json
touch .built.aws_client_webclient

$(ENCRYPT_CONFIG):
$(if $(shell PATH=$(PATH) which consul),,$(error "No consul in PATH"))
@echo Making encryption key
echo "encrypt = $$(consul keygen)" > $(ENCRYPT_CONFIG)
30 changes: 23 additions & 7 deletions packer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,36 @@

The code which built all of the images is in the `packer` directory. The Packer code is there to enable customization of the demo, and view application configuration changes as you investigate Consul.

The images can be built by following these steps:
## Packer File Layout

The AMI's can be adjusted using the following info:

- `cd packer`
- `Makefile` - builds AMIs using Consul OSS
- `Makefile-ent` - builds AMIs using Consul Enterprise
- requires setting Terraform var `consul_lic`
- edit `Makefile` and adjust variables
- `CONSUL_VER` - version of Consul to build into AMIs
- `AMI_PREFIX` - default "consul-demo"
- `AMI_PREFIX` - default "consul-intro"
- previously was "consul-demo" and used Enterprise bins
- `AMI_OWNER` - specifies AWS AMI owner ID
- view & edit the packer templates (`.json` files)
- adjust variables defined at the beginning of each template

## Adjust Terraform

- change Terraform code if needed
- if custom prefix used bu changing the `ami_prefix` variable
- set the `ami_owner` variable
- if custom prefix used, change `ami_prefix` variable
- set `ami_owner` variable
- if using Enterprise AMIs, set `consul_lic` to v2 license

## Build

The images can be built by following these steps:

- export the AWS_REGION to build AMIs
- `export AWS_REGION="us-west-2"`
- view & edit the packer templates (`.json` files in packer directory)
- adjust variables defined at the beginning of each template
- use make to build all the aws images with command
- `make aws`
- `make aws` - build default Makefile
- `make -f Makefile-ent aws` - build Enterprise makefile
- All images will be built and pushed to your AWS environment
4 changes: 2 additions & 2 deletions packer/client_listing.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"role": "consul-client-listing",
"ami_owner": "{{ env `AMI_OWNER` }}",
"ami_prefix": "{{ env `AMI_PREFIX` }}",
"owner_tag": "rpeteuil@hashicorp.com",
"proj_suffix_tag": "Q2-2020",
"owner_tag": "{{ env `OWNER_TAG` }}",
"proj_suffix_tag": "{{ env `PROJ_SUFFIX` }}",
"type": "{{ env `NODE_TYPE` }}",
"consul_version": "{{ env `CONSUL_VER` }}",
"build_date": "{{ env `BUILD_DATE` }}"
Expand Down
4 changes: 2 additions & 2 deletions packer/client_mongodb.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"role": "consul-client-listing",
"ami_owner": "{{ env `AMI_OWNER` }}",
"ami_prefix": "{{ env `AMI_PREFIX` }}",
"owner_tag": "rpeteuil@hashicorp.com",
"proj_suffix_tag": "Q2-2020",
"owner_tag": "{{ env `OWNER_TAG` }}",
"proj_suffix_tag": "{{ env `PROJ_SUFFIX` }}",
"type": "{{ env `NODE_TYPE` }}",
"consul_version": "{{ env `CONSUL_VER` }}",
"build_date": "{{ env `BUILD_DATE` }}"
Expand Down
4 changes: 2 additions & 2 deletions packer/client_product.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"role": "consul-client-product",
"ami_owner": "{{ env `AMI_OWNER` }}",
"ami_prefix": "{{ env `AMI_PREFIX` }}",
"owner_tag": "rpeteuil@hashicorp.com",
"proj_suffix_tag": "Q2-2020",
"owner_tag": "{{ env `OWNER_TAG` }}",
"proj_suffix_tag": "{{ env `PROJ_SUFFIX` }}",
"type": "{{ env `NODE_TYPE` }}",
"consul_version": "{{ env `CONSUL_VER` }}",
"build_date": "{{ env `BUILD_DATE` }}"
Expand Down
4 changes: 2 additions & 2 deletions packer/client_webclient.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"role": "consul-client-webclient",
"ami_owner": "{{ env `AMI_OWNER` }}",
"ami_prefix": "{{ env `AMI_PREFIX` }}",
"owner_tag": "rpeteuil@hashicorp.com",
"proj_suffix_tag": "Q2-2020",
"owner_tag": "{{ env `OWNER_TAG` }}",
"proj_suffix_tag": "{{ env `PROJ_SUFFIX` }}",
"type": "{{ env `NODE_TYPE` }}",
"consul_version": "{{ env `CONSUL_VER` }}",
"build_date": "{{ env `BUILD_DATE` }}"
Expand Down
6 changes: 3 additions & 3 deletions packer/consul_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"aws_region": "{{ env `AWS_REGION` }}",
"role": "consul-base",
"type": "{{ env `NODE_TYPE` }}",
"owner_tag": "rpeteuil@hashicorp.com",
"ami_prefix": "{{ env `AMI_PREFIX` }}",
"proj_suffix_tag": "Q2-2020",
"owner_tag": "{{ env `OWNER_TAG` }}",
"proj_suffix_tag": "{{ env `PROJ_SUFFIX` }}",
"consul_version": "{{ env `CONSUL_VER` }}",
"build_date": "{{ env `BUILD_DATE` }}"
},
Expand Down Expand Up @@ -105,7 +105,7 @@
{
"type": "shell",
"inline": [
"curl -o /tmp/consul.zip https://s3-us-west-2.amazonaws.com/hc-enterprise-binaries/consul/ent/{{ user `consul_version` }}/consul-enterprise_{{ user `consul_version` }}%2Bent_linux_amd64.zip"
"curl -o /tmp/consul.zip https://releases.hashicorp.com/consul/{{ user `consul_version` }}%2Bent/consul_{{ user `consul_version` }}%2Bent_linux_amd64.zip"
]
},
{
Expand Down
Loading

0 comments on commit 73020a0

Please sign in to comment.