-
Prequisites:
- Ensure you have credentials for an admin-like AWS user in the terminal shell where you will be running Terraform apply.
- Run
aws sts get-caller-identityto verify your AWS identity.
-
Step 1
- From the project's root directory run
terraform init. - Run
terraform apply - Type
yesand hit enter. - Retrieve the Public DNS name for the created EC2 instance:
- Via web ui: Navigate to EC2 page, select instance, copy the value for
Public IPv4 DNS - Via aws cli: run the following command and copy the value for
DNS NAME:aws ec2 describe-instances \ --filter Name=instance-state-name,Values=running \ --output table \ --query 'sort_by(Reservations[].Instances[].{NAME: Tags[?Key==`Name`].Value | [0], "DNS NAME": PublicDnsName, "INSTANCE ID": InstanceId}, &NAME)'
- Via web ui: Navigate to EC2 page, select instance, copy the value for
- From the project's root directory run
-
Step 2
- Prepend
http://to the public DNS name and append:8200. - Set this new value to shell env variable
VAULT_ADDRexport VAULT_ADDR=http://<Public DNS Name>:8200
- Prepend
-
Step 3
- Run
vault status
- Run
-
Step 1
- Retrieve the name of the EC2 key pair you use for SSH-ing into EC2 instances.
-
Step 2
- In the project's root directory, create a file called
terraform.tfvars. - Add your EC2 key pair name value as a variable called
ec2_key_pair_name:- terraform.tfvars
ec2_key_pair_name = "<Your EC2 key pair name>"
- terraform.tfvars
- Run
terraform apply - Type
yesand hit enter.
- In the project's root directory, create a file called
-
Step 3
- Once that completes, you should now be able to SSH in to the instance as either the
vaultuser orec2-userusing the instance's public DNS and your EC2 key pair.ssh -i /Users/maxwinslow/.ssh/ec2/us-west-2.pem -A vault@<Public DNS Name>ssh -i /Users/maxwinslow/.ssh/ec2/us-west-2.pem -A ec2-user@<Public DNS Name>- Note: The vault user is only created when the Terraform variable
bootstrap_vaultis set totrue. By default this variable is set totrue. However, if set to false, thevaultuser is not created and therefore you cannot ssh into the instance as that user.
- Note: The vault user is only created when the Terraform variable
- Once that completes, you should now be able to SSH in to the instance as either the
-
Step 4
- Run
terraform apply - Type
yesand hit enter.
- Run
- Step 1
- Add your desired number of servers as a variable called
desired_capacityin yourterraform.tfvarsfile.- terraform.tfvars
desired_capacity = <YOUR DESIRED # of servers>
- terraform.tfvars
- Add your desired number of servers as a variable called
- Step 2
- Run
terraform apply - Type
yesand hit enter.
- Run
- Step 1
- Add your desired vault version as a variable called
vault_versionin yourterraform.tfvarsfile.- Syntax used is (as an example):
1.17.0,1.17.0+ent - terraform.tfvars
vault_version = "<YOUR DESIRED vault version>"
- Syntax used is (as an example):
- Add your desired vault version as a variable called
- Step 2
- Run
terraform apply - Type
yesand hit enter.- Note: Instances with the updated Vault version will only be created on new instances. It will not upgrade existing instances.
- Run
- Step 1
- Add a variable called
create_load_balancerin yourterraform.tfvarsfile and set it totrue.- terraform.tfvars
create_load_balancer = true
- terraform.tfvars
- Add a variable called
- Step 2
- Run
terraform apply - Type
yesand hit enter. - Note: You can change this to a network load balancer by setting the variable
load_balancer_typetonetwork(it isapplicationby default).
- Run
- Step 1
- Add a variable called
create_secondary_clusterin yourterraform.tfvarsfile and set it totrue.- terraform.tfvars
create_secondary_cluster = true
- terraform.tfvars
- Add a variable called
- Step 2
- Run
terraform apply - Type
yesand hit enter.
- Run
- Step 1
- Add a variable called
consul_modein yourterraform.tfvarsfile and set it totrue.- terraform.tfvars
consul_mode = true
- terraform.tfvars
- Add a variable called
- Step 2
- Run
terraform apply - Type
yesand hit enter. - Note: Set
desired_capacityto zero and run aterraform applybefore changing this variable.
Otherwise you're going to have a bad time.
- Run
Full Terraform Documentation (generated via terraform-docs)
| Name | Source | Version |
|---|---|---|
| consul | ./consul | n/a |
| iam | ./iam | n/a |
| kms | ./kms | n/a |
| load_balancer | ./load_balancer | n/a |
| network | ./network | n/a |
| security | ./security | n/a |
| servers | ./servers | n/a |
No resources.
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| ami_name_filters | n/a | list(string) |
[ |
no |
| ami_owners | n/a | list(string) |
[ |
no |
| bootstrap_vault | n/a | bool |
true |
no |
| consul_mode | n/a | bool |
false |
no |
| consul_version | n/a | string |
"1.19.0" |
no |
| create_load_balancer | n/a | bool |
false |
no |
| create_secondary_cluster | n/a | bool |
false |
no |
| deletion_window_in_days | n/a | number |
7 |
no |
| desired_capacity | n/a | number |
1 |
no |
| ec2_key_pair_name | n/a | string |
"" |
no |
| enable_dns_hostnames | n/a | bool |
true |
no |
| instance_type | n/a | string |
"t2.micro" |
no |
| kms_key_arn | n/a | string |
"*" |
no |
| listener_port | n/a | string |
"80" |
no |
| listener_protocol | n/a | string |
"" |
no |
| load_balancer_port | n/a | number |
80 |
no |
| load_balancer_type | n/a | string |
"application" |
no |
| map_public_ip_on_launch | n/a | bool |
true |
no |
| max_size | n/a | number |
5 |
no |
| min_size | n/a | number |
0 |
no |
| most_recent_ami | n/a | bool |
true |
no |
| security_groups | n/a | list(string) |
[] |
no |
| server_name | n/a | list(string) |
[ |
no |
| subnet_a_cidr_block | n/a | string |
"10.0.1.0/24" |
no |
| subnet_b_cidr_block | n/a | string |
"10.0.2.0/24" |
no |
| subnets | n/a | list(string) |
[] |
no |
| target_group_arns | n/a | list(string) |
[] |
no |
| target_group_health_check_codes | n/a | string |
"200,473" |
no |
| target_group_health_check_path | n/a | string |
"/v1/sys/health" |
no |
| target_group_port | n/a | string |
"8200" |
no |
| target_group_protocol | n/a | string |
"HTTP" |
no |
| vault_api_port | n/a | number |
8200 |
no |
| vault_cluster_port | n/a | number |
8201 |
no |
| vault_license | n/a | string |
"" |
no |
| vault_version | n/a | string |
"1.16.0" |
no |
| vpc_cidr_block | n/a | string |
"10.0.0.0/16" |
no |
| vpc_id | n/a | string |
"" |
no |
