├── test ├── .terraform-version ├── .gitignore ├── go.mod ├── variables.tf ├── README.md ├── test.tf ├── main.tf ├── deployment_test.go └── utils.go ├── CODE_OF_CONDUCT ├── modules ├── networking │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── iam │ ├── outputs.tf │ ├── README.md │ ├── variables.tf │ └── main.tf ├── user_data │ ├── outputs.tf │ ├── main.tf │ ├── README.md │ ├── variables.tf │ └── templates │ │ └── install_vault.sh.tpl ├── kms │ ├── outputs.tf │ ├── README.md │ ├── main.tf │ └── variables.tf ├── vm │ ├── outputs.tf │ ├── README.md │ ├── variables.tf │ └── main.tf └── load_balancer │ ├── outputs.tf │ ├── README.md │ ├── variables.tf │ └── main.tf ├── versions.tf ├── examples └── prereqs_quickstart │ ├── versions.tf │ ├── secrets │ ├── acm.tf │ ├── main.tf │ ├── outputs.tf │ ├── variables.tf │ └── tls.tf │ ├── aws-vpc │ ├── outputs.tf │ ├── main.tf │ └── variables.tf │ ├── main.tf │ ├── variables.tf │ ├── outputs.tf │ └── README.md ├── .gitignore ├── .github ├── workflows │ ├── lint.yml │ ├── ok-to-test.yml │ └── integration.yml └── actions │ └── integration_tests │ └── action.yml ├── outputs.tf ├── CHANGELOG.md ├── main.tf ├── variables.tf ├── README.md └── LICENSE /test/.terraform-version: -------------------------------------------------------------------------------- 1 | 1.2.1 2 | -------------------------------------------------------------------------------- /test/.gitignore: -------------------------------------------------------------------------------- 1 | .terraform* 2 | *.tfvars 3 | *.tfstate 4 | backend* 5 | terraform* 6 | 7 | !.terraform-version 8 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | HashiCorp Community Guidelines apply to you when interacting with the community here on GitHub and contributing code. 4 | 5 | Please read the full text at https://www.hashicorp.com/community-guidelines 6 | -------------------------------------------------------------------------------- /test/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hashicorp/terraform-aws-vault-starter 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/gruntwork-io/terratest v0.40.5 7 | github.com/hashicorp/hcl v1.0.0 8 | github.com/hashicorp/hcl/v2 v2.12.0 // indirect 9 | github.com/stretchr/testify v1.7.0 10 | ) 11 | -------------------------------------------------------------------------------- /modules/networking/README.md: -------------------------------------------------------------------------------- 1 | # AWS Networking Module 2 | 3 | ## Required variables 4 | 5 | * `vpc_id` - VPC ID where Vault will be deployed 6 | 7 | ## Example usage 8 | 9 | ```hcl 10 | module "networking" { 11 | source = "./modules/networking" 12 | 13 | vpc_id = var.vpc_id 14 | } 15 | ``` 16 | -------------------------------------------------------------------------------- /modules/networking/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | data "aws_vpc" "selected" { 9 | id = var.vpc_id 10 | } 11 | -------------------------------------------------------------------------------- /modules/networking/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "vpc_id" { 9 | value = data.aws_vpc.selected.id 10 | } 11 | -------------------------------------------------------------------------------- /modules/iam/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "aws_iam_instance_profile" { 9 | value = aws_iam_instance_profile.vault.name 10 | } 11 | -------------------------------------------------------------------------------- /modules/user_data/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "vault_userdata_base64_encoded" { 9 | value = base64encode(local.vault_user_data) 10 | } 11 | -------------------------------------------------------------------------------- /modules/networking/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "vpc_id" { 9 | type = string 10 | description = "VPC ID where Vault will be deployed" 11 | } 12 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | terraform { 9 | required_version = ">= 1.2.1" 10 | 11 | required_providers { 12 | aws = ">= 3.0.0, < 4.0.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /modules/kms/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "kms_key_arn" { 9 | value = var.user_supplied_kms_key_arn != null ? var.user_supplied_kms_key_arn : aws_kms_key.vault[0].arn 10 | } 11 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/versions.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | terraform { 9 | required_version = ">= 1.2.1" 10 | 11 | required_providers { 12 | aws = ">= 3.0.0, < 4.0.0" 13 | tls = ">= 3.0.0, < 4.0.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /modules/kms/README.md: -------------------------------------------------------------------------------- 1 | # AWS KMS Module 2 | 3 | ## Required variables 4 | 5 | * `kms_key_deletion_window` - Duration in days after which the key is deleted after destruction of the resource (must be between 7 and 30 days) 6 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 7 | 8 | ## Example usage 9 | 10 | ```hcl 11 | module "kms" { 12 | source = "./modules/kms" 13 | 14 | kms_key_deletion_window = var.kms_key_deletion_window 15 | resource_name_prefix = var.resource_name_prefix 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/acm.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_acm_certificate" "vault" { 9 | private_key = tls_private_key.server.private_key_pem 10 | certificate_body = tls_locally_signed_cert.server.cert_pem 11 | certificate_chain = tls_self_signed_cert.ca.cert_pem 12 | } 13 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/aws-vpc/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "private_subnet_ids" { 9 | description = "Private subnet IDs" 10 | value = module.vpc.private_subnets 11 | } 12 | 13 | output "vpc_id" { 14 | description = "The ID of the VPC" 15 | value = module.vpc.vpc_id 16 | } 17 | 18 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | provider "aws" { 9 | region = var.aws_region 10 | } 11 | 12 | module "vpc" { 13 | source = "./aws-vpc/" 14 | 15 | azs = var.azs 16 | common_tags = var.tags 17 | resource_name_prefix = var.resource_name_prefix 18 | } 19 | 20 | module "secrets" { 21 | source = "./secrets/" 22 | 23 | resource_name_prefix = var.resource_name_prefix 24 | } 25 | 26 | -------------------------------------------------------------------------------- /modules/iam/README.md: -------------------------------------------------------------------------------- 1 | # AWS IAM Module 2 | 3 | ## Required variables 4 | 5 | * `aws_region` - Specific AWS region being used 6 | * `kms_key_arn` - KMS Key ARN used for Vault auto-unseal permissions 7 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 8 | * `secrets_manager_arn` - Secrets manager ARN where TLS cert info is stored 9 | 10 | ## Example usage 11 | 12 | ```hcl 13 | module "iam" { 14 | source = "./modules/iam" 15 | 16 | aws_region = data.aws_region.current.name 17 | kms_key_arn = var.kms_key_arn 18 | resource_name_prefix = var.resource_name_prefix 19 | secrets_manager_arn = var.secrets_manager_arn 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /modules/vm/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "asg_name" { 9 | description = "Name of autoscaling group" 10 | value = aws_autoscaling_group.vault.name 11 | } 12 | 13 | output "launch_template_id" { 14 | description = "ID of launch template for Vault autoscaling group" 15 | value = aws_launch_template.vault.id 16 | } 17 | 18 | output "vault_sg_id" { 19 | description = "Security group ID of Vault cluster" 20 | value = aws_security_group.vault.id 21 | } 22 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/aws-vpc/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | module "vpc" { 9 | source = "terraform-aws-modules/vpc/aws" 10 | version = "3.0.0" 11 | name = "${var.resource_name_prefix}-vault" 12 | cidr = var.vpc_cidr 13 | azs = var.azs 14 | enable_nat_gateway = true 15 | one_nat_gateway_per_az = true 16 | private_subnets = var.private_subnet_cidrs 17 | public_subnets = var.public_subnet_cidrs 18 | 19 | tags = var.common_tags 20 | } 21 | 22 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_secretsmanager_secret" "tls" { 9 | name = "${var.resource_name_prefix}-tls-secret" 10 | description = "contains TLS certs and private keys" 11 | kms_key_id = var.kms_key_id 12 | recovery_window_in_days = var.recovery_window 13 | tags = var.tags 14 | } 15 | 16 | resource "aws_secretsmanager_secret_version" "tls" { 17 | secret_id = aws_secretsmanager_secret.tls.id 18 | secret_string = local.secret 19 | } 20 | 21 | -------------------------------------------------------------------------------- /modules/kms/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_kms_key" "vault" { 9 | count = var.user_supplied_kms_key_arn != null ? 0 : 1 10 | deletion_window_in_days = var.kms_key_deletion_window 11 | description = "AWS KMS Customer-managed key used for Vault auto-unseal and encryption" 12 | enable_key_rotation = false 13 | is_enabled = true 14 | key_usage = "ENCRYPT_DECRYPT" 15 | 16 | tags = merge( 17 | { Name = "${var.resource_name_prefix}-vault-key" }, 18 | var.common_tags, 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "lb_certificate_arn" { 9 | description = "ARN of ACM cert to use with Vault LB listener" 10 | value = aws_acm_certificate.vault.arn 11 | } 12 | 13 | output "leader_tls_servername" { 14 | description = "Shared SAN that will be given to the Vault nodes configuration for use as leader_tls_servername" 15 | value = var.shared_san 16 | } 17 | 18 | output "secrets_manager_arn" { 19 | description = "ARN of secrets_manager secret" 20 | value = aws_secretsmanager_secret.tls.arn 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | 28 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 29 | # example: *tfplan* 30 | -------------------------------------------------------------------------------- /modules/user_data/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | locals { 9 | vault_user_data = templatefile( 10 | var.user_supplied_userdata_path != null ? var.user_supplied_userdata_path : "${path.module}/templates/install_vault.sh.tpl", 11 | { 12 | region = var.aws_region 13 | name = var.resource_name_prefix 14 | vault_version = var.vault_version 15 | kms_key_arn = var.kms_key_arn 16 | secrets_manager_arn = var.secrets_manager_arn 17 | leader_tls_servername = var.leader_tls_servername 18 | } 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /test/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "common_tags" { type = map(string) } 9 | variable "resource_name_prefix" { type = string } 10 | 11 | variable "azs" { 12 | description = "Availability zones to use in AWS region" 13 | type = list(string) 14 | } 15 | 16 | variable "permissions_boundary" { 17 | description = "IAM Managed Policy to serve as permissions boundary for created IAM Roles" 18 | type = string 19 | default = null 20 | } 21 | 22 | variable "region" { 23 | type = string 24 | default = "us-east-1" 25 | description = "Region in which to launch resources" 26 | } 27 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "aws_region" { 9 | description = "AWS region to deploy resources into" 10 | type = string 11 | default = "us-east-1" 12 | } 13 | 14 | variable "azs" { 15 | description = "availability zones to use in AWS region" 16 | type = list(string) 17 | default = [ 18 | "us-east-1a", 19 | "us-east-1b", 20 | "us-east-1c", 21 | ] 22 | } 23 | 24 | variable "tags" { 25 | type = map(string) 26 | description = "Tags for VPC resources" 27 | default = {} 28 | } 29 | 30 | variable "resource_name_prefix" { 31 | description = "Prefix for resource names in VPC infrastructure" 32 | } 33 | 34 | -------------------------------------------------------------------------------- /modules/user_data/README.md: -------------------------------------------------------------------------------- 1 | # AWS User Data Module 2 | 3 | ## Required variables 4 | 5 | * `aws_region` - AWS region where Vault is being deployed 6 | * `kms_key_arn` - KMS Key ARN used for Vault auto-unseal 7 | * `leader_tls_servername` - One of the shared DNS SAN used to create the certs use for mTLS 8 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 9 | * `secrets_manager_arn` - Secrets manager ARN where TLS cert info is stored 10 | * `vault_version` - Vault version 11 | 12 | ## Example usage 13 | 14 | ```hcl 15 | module "user_data" { 16 | source = "./modules/user_data" 17 | 18 | aws_region = data.aws_region.current.name 19 | kms_key_arn = var.kms_key_arn 20 | leader_tls_servername = var.leader_tls_servername 21 | resource_name_prefix = var.resource_name_prefix 22 | secrets_manager_arn = var.secrets_manager_arn 23 | vault_version = var.vault_version 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /modules/load_balancer/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "vault_lb_arn" { 9 | description = "ARN of Vault load balancer" 10 | value = aws_lb.vault_lb.arn 11 | } 12 | 13 | output "vault_lb_dns_name" { 14 | description = "DNS name of Vault load balancer" 15 | value = aws_lb.vault_lb.dns_name 16 | } 17 | 18 | output "vault_lb_sg_id" { 19 | description = "Security group ID of Vault load balancer" 20 | value = var.lb_type == "application" ? aws_security_group.vault_lb[0].id : null 21 | } 22 | 23 | output "vault_lb_zone_id" { 24 | description = "Zone ID of Vault load balancer" 25 | value = aws_lb.vault_lb.zone_id 26 | } 27 | 28 | output "vault_target_group_arn" { 29 | description = "Target group ARN to register Vault nodes with" 30 | value = aws_lb_target_group.vault.arn 31 | } 32 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "lb_certificate_arn" { 9 | description = "ARN of ACM cert to use with Vault LB listener" 10 | value = module.secrets.lb_certificate_arn 11 | } 12 | 13 | output "leader_tls_servername" { 14 | description = "Shared SAN that will be given to the Vault nodes configuration for use as leader_tls_servername" 15 | value = module.secrets.leader_tls_servername 16 | } 17 | 18 | output "private_subnet_ids" { 19 | description = "Private subnet IDs" 20 | value = module.vpc.private_subnet_ids 21 | } 22 | 23 | output "secrets_manager_arn" { 24 | description = "ARN of secrets_manager secret" 25 | value = module.secrets.secrets_manager_arn 26 | } 27 | 28 | output "vpc_id" { 29 | description = "The ID of the VPC" 30 | value = module.vpc.vpc_id 31 | } 32 | 33 | -------------------------------------------------------------------------------- /modules/kms/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "common_tags" { 9 | type = map(string) 10 | description = "(Optional) Map of common tags for all taggable AWS resources." 11 | default = {} 12 | } 13 | 14 | variable "kms_key_deletion_window" { 15 | type = number 16 | description = "Duration in days after which the key is deleted after destruction of the resource (must be between 7 and 30 days)." 17 | } 18 | 19 | variable "resource_name_prefix" { 20 | type = string 21 | description = "Resource name prefix used for tagging and naming AWS resources" 22 | } 23 | 24 | variable "user_supplied_kms_key_arn" { 25 | type = string 26 | description = "(OPTIONAL) User-provided KMS key ARN. Providing this will disable the KMS submodule from generating a KMS key used for Vault auto-unseal" 27 | default = null 28 | } 29 | -------------------------------------------------------------------------------- /modules/load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # AWS Load Balancer Module 2 | 3 | ## Required variables 4 | 5 | * `lb_certificate_arn` - ARN of TLS certificate imported into ACM for use with LB listener 6 | * `lb_health_check_path` - The endpoint to check for Vault's health status 7 | * `lb_subnets` - Subnets where load balancer will be deployed 8 | * `lb_type` - The type of load balancer to provision: network or application 9 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 10 | * `ssl_policy` - SSL policy to use on LB listener 11 | * `vault_sg_id` - Security group ID of Vault cluster 12 | * `vpc_id` - VPC ID where Vault will be deployed 13 | 14 | ## Example usage 15 | 16 | ```hcl 17 | module "loadbalancer" { 18 | source = "./modules/load_balancer" 19 | 20 | lb_certificate_arn = var.lb_certificate_arn 21 | lb_health_check_path = var.lb_health_check_path 22 | lb_subnets = var.vault_subnet_ids 23 | lb_type = var.lb_type 24 | resource_name_prefix = var.resource_name_prefix 25 | ssl_policy = var.ssl_policy 26 | vault_sg_id = var.vault_sg_id 27 | vpc_id = var.vpc_id 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | ## Overview 2 | 3 | This test directory defines basic integration tests for the module. 4 | 5 | ## Prereqs 6 | 7 | * Terraform or tfenv in PATH 8 | * [Terraform Cloud credentials](https://www.terraform.io/cli/commands/login) 9 | 10 | ## Use 11 | 12 | ``` 13 | go test -v -timeout 120m 14 | ``` 15 | 16 | Optional environment variables: 17 | * `DEPLOY_ENV` - set this to change the prefix applied to resource names. 18 | * `AWS_DEFAULT_REGION` - set the AWS region in which resources are deployed 19 | * `AWS_PERMISSIONS_BOUNDARY` - this can be set when deploying with a limited-permission IAM principle (i.e. when running in CI) to create IAM Roles with the specified IAM Managed Policy ARN as their permissions boundary 20 | * `TEST_DONT_DESTROY_UPON_SUCCESS` - set this to skip running terraform destroy upon testing success 21 | 22 | The `go test` will populate terraform `.auto.tfvars` in this test directory and execute `terraform apply`. If the deployment & tests pass, `terraform destroy` will be invoked. 23 | 24 | ### Cleaning Up 25 | 26 | If resources aren't deleted automatically (at the end of successful tests), Terraform can be manually invoked to delete them (`terraform destroy`) 27 | -------------------------------------------------------------------------------- /test/test.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "time_sleep" "wait_30s_after_vault_bootstrap" { 9 | create_duration = "30s" 10 | 11 | depends_on = [ 12 | testingtoolsaws_ssm_runcommand.bootstrap_vault, 13 | ] 14 | } 15 | 16 | resource "testingtoolsaws_ssm_runcommand" "vault_operator_raft_list_peers" { 17 | document_name = "AWS-RunShellScript" 18 | 19 | instance_ids = [ 20 | data.aws_instances.servers.ids[0], 21 | ] 22 | 23 | parameters = { 24 | commands = "VAULT_TOKEN=\"${local.bootstrap_token}\" VAULT_ADDR=\"https://127.0.0.1:8200\" VAULT_CACERT=\"/opt/vault/tls/vault-ca.pem\" VAULT_CLIENT_CERT=\"/opt/vault/tls/vault-cert.pem\" VAULT_CLIENT_KEY=\"/opt/vault/tls/vault-key.pem\" vault operator raft list-peers" 25 | } 26 | 27 | depends_on = [ 28 | time_sleep.wait_30s_after_vault_bootstrap, 29 | ] 30 | } 31 | output "vault_operator_raft_list_peers" { 32 | value = testingtoolsaws_ssm_runcommand.vault_operator_raft_list_peers.outputs[0].StandardOutputContent 33 | } 34 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2014-2022 HashiCorp, Inc. 2 | # 3 | # This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | 6 | name: Lint 7 | 8 | on: 9 | push: 10 | branches: 11 | - main 12 | paths-ignore: 13 | - '**/CHANGELOG.md' 14 | - '**/README.md' 15 | pull_request: 16 | paths-ignore: 17 | - '**/CHANGELOG.md' 18 | - '**/README.md' 19 | 20 | jobs: 21 | test: 22 | name: Lint 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v2 27 | - name: Setup tfenv 28 | run: | 29 | TFENV_DL_TMP=$(mktemp -d) 30 | curl -Lo $TFENV_DL_TMP/tfenv.zip https://github.com/tfutils/tfenv/archive/2989f1a5560e313f70f7711be592ddb68418862b.zip 31 | unzip $TFENV_DL_TMP/tfenv.zip -d $TFENV_DL_TMP 32 | mv $TFENV_DL_TMP/tfenv-2989f1a5560e313f70f7711be592ddb68418862b ~/.tfenv 33 | echo "$HOME/.tfenv/bin" >> $GITHUB_PATH 34 | echo "latest:^1.0" > .terraform-version 35 | - name: Check Terraform formatting 36 | run: tfenv install && terraform fmt -check -recursive 37 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "asg_name" { 9 | value = module.vm.asg_name 10 | } 11 | 12 | output "kms_key_arn" { 13 | value = module.kms.kms_key_arn 14 | } 15 | 16 | output "launch_template_id" { 17 | value = module.vm.launch_template_id 18 | } 19 | 20 | output "vault_lb_dns_name" { 21 | description = "DNS name of Vault load balancer" 22 | value = module.loadbalancer.vault_lb_dns_name 23 | } 24 | 25 | output "vault_lb_zone_id" { 26 | description = "Zone ID of Vault load balancer" 27 | value = module.loadbalancer.vault_lb_zone_id 28 | } 29 | 30 | output "vault_lb_arn" { 31 | description = "ARN of Vault load balancer" 32 | value = module.loadbalancer.vault_lb_arn 33 | } 34 | 35 | output "vault_target_group_arn" { 36 | description = "Target group ARN to register Vault nodes with" 37 | value = module.loadbalancer.vault_target_group_arn 38 | } 39 | 40 | output "vault_sg_id" { 41 | description = "Security group ID of Vault cluster" 42 | value = module.vm.vault_sg_id 43 | } 44 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/aws-vpc/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "azs" { 9 | description = "availability zones to use in AWS region" 10 | type = list(string) 11 | } 12 | 13 | variable "common_tags" { 14 | type = map(string) 15 | description = "Tags for VPC resources" 16 | } 17 | 18 | variable "resource_name_prefix" { 19 | description = "Prefix for resource names (e.g. \"prod\")" 20 | type = string 21 | } 22 | 23 | variable "private_subnet_cidrs" { 24 | description = "CIDR blocks for private subnets" 25 | type = list(string) 26 | default = [ 27 | "10.0.0.0/19", 28 | "10.0.32.0/19", 29 | "10.0.64.0/19", 30 | ] 31 | } 32 | 33 | variable "public_subnet_cidrs" { 34 | description = "CIDR blocks for public subnets" 35 | type = list(string) 36 | default = [ 37 | "10.0.128.0/20", 38 | "10.0.144.0/20", 39 | "10.0.160.0/20", 40 | ] 41 | } 42 | 43 | variable "vpc_cidr" { 44 | description = "CIDR block for VPC" 45 | type = string 46 | default = "10.0.0.0/16" 47 | } 48 | 49 | -------------------------------------------------------------------------------- /modules/user_data/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "aws_region" { 9 | type = string 10 | description = "AWS region where Vault is being deployed" 11 | } 12 | 13 | variable "kms_key_arn" { 14 | type = string 15 | description = "KMS Key ARN used for Vault auto-unseal" 16 | } 17 | 18 | variable "leader_tls_servername" { 19 | type = string 20 | description = "One of the shared DNS SAN used to create the certs use for mTLS" 21 | } 22 | 23 | variable "resource_name_prefix" { 24 | type = string 25 | description = "Resource name prefix used for tagging and naming AWS resources" 26 | } 27 | 28 | variable "secrets_manager_arn" { 29 | type = string 30 | description = "Secrets manager ARN where TLS cert info is stored" 31 | } 32 | 33 | variable "user_supplied_userdata_path" { 34 | type = string 35 | description = "File path to custom userdata script being supplied by the user" 36 | default = null 37 | } 38 | 39 | variable "vault_version" { 40 | type = string 41 | description = "Vault version" 42 | } 43 | -------------------------------------------------------------------------------- /modules/vm/README.md: -------------------------------------------------------------------------------- 1 | # AWS VM Module 2 | 3 | ## Required variables 4 | 5 | * `aws_iam_instance_profile` - IAM instance profile name to use for Vault instances 6 | * `lb_type` - The type of load balancer being used to front Vault instances 7 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 8 | * `userdata_script` - Userdata script for EC2 instance. Must be base64-encoded. 9 | * `vault_lb_sg_id` - Security group ID of Vault load balancer (will not be read if you are using a network load balancer) 10 | * `vault_subnets` - Private subnets where Vault will be deployed 11 | * `vault_target_group_arn` - Target group ARN to register Vault nodes with 12 | * `vpc_id` - VPC ID where Vault will be deployed 13 | 14 | ## Example usage 15 | 16 | ```hcl 17 | module "vm" { 18 | source = "./modules/vm" 19 | 20 | aws_iam_instance_profile = var.aws_iam_instance_profile 21 | instance_type = var.instance_type 22 | lb_type = var.lb_type 23 | resource_name_prefix = var.resource_name_prefix 24 | userdata_script = var.userdata_script 25 | vault_lb_sg_id = var.vault_lb_sg_id 26 | vault_subnets = var.vault_subnet_ids 27 | vault_target_group_arn = var.vault_target_group_arn 28 | vpc_id = var.vpc_id 29 | } 30 | ``` 31 | -------------------------------------------------------------------------------- /.github/actions/integration_tests/action.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2014-2022 HashiCorp, Inc. 2 | # 3 | # This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | 6 | name: Run integration tests 7 | description: Deploy infrastructure, test it, and destroy it 8 | inputs: 9 | env_suffix: 10 | description: 'Environment suffix' 11 | required: true 12 | runs: 13 | using: "composite" 14 | steps: 15 | - run: echo "Installing dependencies" 16 | shell: bash 17 | - name: Install dependencies 18 | run: | 19 | TFENV_DL_TMP=$(mktemp -d) 20 | curl -Lo $TFENV_DL_TMP/tfenv.zip https://github.com/tfutils/tfenv/archive/2989f1a5560e313f70f7711be592ddb68418862b.zip 21 | unzip $TFENV_DL_TMP/tfenv.zip -d $TFENV_DL_TMP 22 | mv $TFENV_DL_TMP/tfenv-2989f1a5560e313f70f7711be592ddb68418862b ~/.tfenv 23 | echo "$HOME/.tfenv/bin" >> $GITHUB_PATH 24 | shell: bash 25 | - run: echo "Deploying and running tests" 26 | shell: bash 27 | - name: Deploy and run tests 28 | run: tfenv install && DEPLOY_ENV=inttest${{ inputs.env_suffix }} go test -v -timeout 120m 29 | working-directory: ./test 30 | shell: bash 31 | - run: echo "Integration tests succeeded" 32 | shell: bash 33 | -------------------------------------------------------------------------------- /modules/iam/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "aws_region" { 9 | type = string 10 | description = "Specific AWS region being used" 11 | } 12 | 13 | variable "kms_key_arn" { 14 | type = string 15 | description = "KMS Key ARN used for Vault auto-unseal permissions" 16 | } 17 | 18 | variable "permissions_boundary" { 19 | description = "(Optional) IAM Managed Policy to serve as permissions boundary for IAM Role" 20 | type = string 21 | default = null 22 | } 23 | 24 | variable "resource_name_prefix" { 25 | type = string 26 | description = "Resource name prefix used for tagging and naming AWS resources" 27 | } 28 | 29 | variable "secrets_manager_arn" { 30 | type = string 31 | description = "Secrets manager ARN where TLS cert info is stored" 32 | } 33 | 34 | variable "user_supplied_iam_role_name" { 35 | type = string 36 | description = "(OPTIONAL) User-provided IAM role name. This will be used for the instance profile provided to the AWS launch configuration. The minimum permissions must match the defaults generated by the IAM submodule for cloud auto-join and auto-unseal." 37 | default = null 38 | } 39 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/README.md: -------------------------------------------------------------------------------- 1 | # EXAMPLE: Prerequisite Configuration (VPC and Secrets) 2 | 3 | ## About This Example 4 | 5 | In order to deploy the Vault module, you must have an AWS VPC that 6 | meets the requirements [listed in the main 7 | README](../../README.md#how-to-use-this-module) along with TLS certs that can be 8 | used with the Vault nodes and load balancer. If you do not already have these 9 | resources, you can use the code provided in this directory to provision them. 10 | 11 | ## How to Use This Module 12 | 13 | 1. Ensure your AWS credentials are [configured 14 | correctly](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) 15 | 2. Configure required (and optional if desired) variables 16 | 3. Run `terraform init` and `terraform apply` 17 | 18 | ## Required variables 19 | 20 | * `resource_name_prefix` - string value to use as base for resource names 21 | 22 | ## Note 23 | 24 | - The default AWS region is `us-east-1` (as specified by the `aws_region` 25 | variable). You may change this if wish to deploy Vault elsewhere, but please 26 | be sure to change the value for the `azs` variable as well and specify the 27 | appropriate availability zones for your new region. 28 | 29 | ### Security Note: 30 | - The [Terraform State](https://www.terraform.io/docs/language/state/index.html) 31 | produced by this code has sensitive data (cert private keys) stored in it. 32 | Please secure your Terraform state using the [recommendations listed 33 | here](https://www.terraform.io/docs/language/state/sensitive-data.html#recommendations). 34 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "kms_key_id" { 9 | type = string 10 | description = "Specifies the ARN or ID of the AWS KMS customer master key (CMK) to be used to encrypt the secret values in the versions stored in this secret. If you don't specify this value, then Secrets Manager defaults to using the AWS account's default CMK (the one named aws/secretsmanager" 11 | default = null 12 | } 13 | 14 | variable "recovery_window" { 15 | type = number 16 | description = "Specifies the number of days that AWS Secrets Manager waits before it can delete the secret" 17 | default = 0 18 | } 19 | 20 | variable "resource_name_prefix" { 21 | type = string 22 | description = "Prefix for resource names (e.g. \"prod\")" 23 | } 24 | 25 | # variable related to TLS cert generation 26 | variable "shared_san" { 27 | type = string 28 | description = "This is a shared server name that the certs for all Vault nodes contain. This is the same value you will supply as input to the Vault installation module for the leader_tls_servername variable." 29 | default = "vault.server.com" 30 | } 31 | 32 | variable "tags" { 33 | type = map(string) 34 | description = "Tags for secrets manager secret" 35 | default = { 36 | Vault = "tls-data" 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /.github/workflows/ok-to-test.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2014-2022 HashiCorp, Inc. 2 | # 3 | # This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | 6 | # If someone with write access comments "/ok-to-test" on a pull request, emit a repository_dispatch event 7 | name: Ok To Test 8 | 9 | on: 10 | issue_comment: 11 | types: [created] 12 | 13 | jobs: 14 | ok-to-test: 15 | runs-on: ubuntu-latest 16 | # Only run for PRs, not issue comments 17 | if: ${{ github.event.issue.pull_request }} 18 | steps: 19 | # Generate a GitHub App installation access token from an App ID and private key 20 | # To create a new GitHub App: 21 | # https://developer.github.com/apps/building-github-apps/creating-a-github-app/ 22 | # See app.yml for an example app manifest 23 | - name: Generate token 24 | id: generate_token 25 | uses: tibdex/github-app-token@cdb5bfda87db263e4be5c6f570c4c39611ee952a # v1.4.0 26 | with: 27 | app_id: ${{ secrets.APP_ID }} 28 | private_key: ${{ secrets.PRIVATE_KEY }} 29 | 30 | - name: Slash Command Dispatch 31 | uses: peter-evans/slash-command-dispatch@fc430081ad51bb37d160fa3a3ee718c121e6b90d # v2.2.1 32 | env: 33 | TOKEN: ${{ steps.generate_token.outputs.token }} 34 | with: 35 | token: ${{ env.TOKEN }} # GitHub App installation access token 36 | # token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} # PAT or OAuth token will also work 37 | reaction-token: ${{ secrets.GITHUB_TOKEN }} 38 | issue-type: pull-request 39 | commands: ok-to-test 40 | named-args: true 41 | permission: write 42 | -------------------------------------------------------------------------------- /modules/load_balancer/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "allowed_inbound_cidrs" { 9 | type = list(string) 10 | description = "List of CIDR blocks to permit inbound traffic from to load balancer" 11 | default = null 12 | } 13 | 14 | variable "common_tags" { 15 | type = map(string) 16 | description = "(Optional) Map of common tags for all taggable AWS resources." 17 | default = {} 18 | } 19 | 20 | variable "lb_certificate_arn" { 21 | type = string 22 | description = "ARN of TLS certificate imported into ACM for use with LB listener" 23 | } 24 | 25 | variable "lb_deregistration_delay" { 26 | type = string 27 | description = "Amount time, in seconds, for Vault LB target group to wait before changing the state of a deregistering target from draining to unused." 28 | default = 300 29 | } 30 | 31 | variable "lb_health_check_path" { 32 | type = string 33 | description = "The endpoint to check for Vault's health status." 34 | } 35 | 36 | variable "lb_subnets" { 37 | type = list(string) 38 | description = "Subnets where load balancer will be deployed" 39 | } 40 | 41 | variable "lb_type" { 42 | description = "The type of load balancer to provison: network or application." 43 | type = string 44 | } 45 | 46 | variable "resource_name_prefix" { 47 | type = string 48 | description = "Resource name prefix used for tagging and naming AWS resources" 49 | } 50 | 51 | variable "ssl_policy" { 52 | type = string 53 | description = "SSL policy to use on LB listener" 54 | } 55 | 56 | variable "vault_sg_id" { 57 | type = string 58 | description = "Security group ID of Vault cluster" 59 | } 60 | 61 | variable "vpc_id" { 62 | type = string 63 | description = "VPC ID where Vault will be deployed" 64 | } 65 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Unreleased 2 | 3 | IMPROVEMENTS: 4 | 5 | * Update package name syntax in userdata script to prevent breakage when installing latest versions of Vault enterprise. 6 | * Update examples directory with quickstart file that reduces number of steps to 7 | provision pre-reqs 8 | * Remove data sources for AWS subnets and allow user to explicitly specify 9 | private subnet IDs in main module 10 | * Update main module outputs 11 | * Update default Vault version 12 | * Update Terraform version pin 13 | * Add `permissions_boundary` variable to support creating the IAM Role with a permissions boundary 14 | 15 | ## 1.0.0 (September 22, 2021) 16 | 17 | IMPROVEMENTS: 18 | 19 | * Updated README 20 | * Break code into submodules and add submodule READMEs 21 | * Deploy Vault nodes into private subnets for better security 22 | * Better reflect Vault reference architecture and deployment guide 23 | * Require TLS certs on nodes and load balancers 24 | * Remove lambda functions and use autopilot features for server cleanup 25 | * Tighten file/folder permissions created in userdata script 26 | * Add AWS Session Manager capability for logging into nodes 27 | 28 | ## 0.2.3 (February 04, 2021) 29 | 30 | IMPROVEMENTS: 31 | 32 | * Clarify README 33 | 34 | ## 0.2.2 (February 04, 2021) 35 | 36 | IMPROVEMENTS: 37 | 38 | * Increased `wait_for_capacity_timeout` in ASG to make sure `terraform apply` doesn't time out 39 | 40 | ## 0.2.1 (August 19, 2020) 41 | 42 | IMPROVEMENTS: 43 | 44 | * security: 45 | - added security group rule to expose API/UI to allowed CIDR blocks 46 | - exposed `elb_internal` variable to user 47 | * documentation: updated README 48 | 49 | ## 0.2.0 (August 13, 2020) 50 | 51 | IMPROVEMENTS: 52 | 53 | * Upgrading terraform block syntax for TF version 0.13.0+ 54 | * Pinning version number for `aws`, `random`, and `template` providers 55 | 56 | ## 0.1.2 (July 09, 2020) 57 | 58 | IMPROVEMENTS: 59 | 60 | * security: added security group rule for inbound on port 22 and variable for 61 | approved CIDR blocks 62 | 63 | ## 0.1.1 (July 2, 2020) 64 | 65 | IMPROVEMENTS: 66 | 67 | * documentation: updated refs and corrected links 68 | * documentation: added CHANGELOG 69 | 70 | ## 0.1.0 (July 2, 2020) 71 | 72 | * Initial release 73 | -------------------------------------------------------------------------------- /modules/vm/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "allowed_inbound_cidrs" { 9 | type = list(string) 10 | description = "List of CIDR blocks to permit inbound traffic from to load balancer" 11 | default = null 12 | } 13 | 14 | variable "allowed_inbound_cidrs_ssh" { 15 | type = list(string) 16 | description = "List of CIDR blocks to give SSH access to Vault nodes" 17 | default = null 18 | } 19 | 20 | variable "aws_iam_instance_profile" { 21 | type = string 22 | description = "IAM instance profile name to use for Vault instances" 23 | } 24 | 25 | variable "common_tags" { 26 | type = map(string) 27 | description = "(Optional) Map of common tags for all taggable AWS resources." 28 | default = {} 29 | } 30 | 31 | variable "instance_type" { 32 | type = string 33 | description = "EC2 instance type" 34 | default = "m5.xlarge" 35 | } 36 | 37 | variable "key_name" { 38 | type = string 39 | description = "key pair to use for SSH access to instance" 40 | default = null 41 | } 42 | 43 | variable "lb_type" { 44 | description = "The type of load balancer to provision: network or application." 45 | type = string 46 | } 47 | 48 | variable "node_count" { 49 | type = number 50 | description = "Number of Vault nodes to deploy in ASG" 51 | default = 5 52 | } 53 | 54 | variable "resource_name_prefix" { 55 | type = string 56 | description = "Resource name prefix used for tagging and naming AWS resources" 57 | } 58 | 59 | variable "userdata_script" { 60 | type = string 61 | description = "Userdata script for EC2 instance" 62 | } 63 | 64 | variable "user_supplied_ami_id" { 65 | type = string 66 | description = "AMI ID to use with Vault instances" 67 | default = null 68 | } 69 | 70 | variable "vault_lb_sg_id" { 71 | type = string 72 | description = "Security group ID of Vault load balancer" 73 | } 74 | 75 | variable "vault_subnets" { 76 | type = list(string) 77 | description = "Private subnets where Vault will be deployed" 78 | } 79 | 80 | variable "vault_target_group_arns" { 81 | type = list(string) 82 | description = "Target group ARN(s) to register Vault nodes with" 83 | } 84 | 85 | variable "vpc_id" { 86 | type = string 87 | description = "VPC ID where Vault will be deployed" 88 | } 89 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/tls.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | # Generate a private key so you can create a CA cert with it. 9 | resource "tls_private_key" "ca" { 10 | algorithm = "RSA" 11 | rsa_bits = 2048 12 | } 13 | 14 | # Create a CA cert with the private key you just generated. 15 | resource "tls_self_signed_cert" "ca" { 16 | private_key_pem = tls_private_key.ca.private_key_pem 17 | 18 | subject { 19 | common_name = "ca.vault.server.com" 20 | } 21 | 22 | validity_period_hours = 720 # 30 days 23 | 24 | allowed_uses = [ 25 | "cert_signing", 26 | "crl_signing", 27 | ] 28 | 29 | is_ca_certificate = true 30 | 31 | # provisioner "local-exec" { 32 | # command = "echo '${tls_self_signed_cert.ca.cert_pem}' > ./vault-ca.pem" 33 | # } 34 | } 35 | 36 | # Generate another private key. This one will be used 37 | # To create the certs on your Vault nodes 38 | resource "tls_private_key" "server" { 39 | algorithm = "RSA" 40 | rsa_bits = 2048 41 | 42 | # provisioner "local-exec" { 43 | # command = "echo '${tls_private_key.server.private_key_pem}' > ./vault-key.pem" 44 | # } 45 | } 46 | 47 | resource "tls_cert_request" "server" { 48 | private_key_pem = tls_private_key.server.private_key_pem 49 | 50 | subject { 51 | common_name = "vault.server.com" 52 | } 53 | 54 | dns_names = [ 55 | var.shared_san, 56 | "localhost", 57 | ] 58 | 59 | ip_addresses = [ 60 | "127.0.0.1", 61 | ] 62 | } 63 | 64 | resource "tls_locally_signed_cert" "server" { 65 | cert_request_pem = tls_cert_request.server.cert_request_pem 66 | ca_private_key_pem = tls_private_key.ca.private_key_pem 67 | ca_cert_pem = tls_self_signed_cert.ca.cert_pem 68 | 69 | validity_period_hours = 720 # 30 days 70 | 71 | allowed_uses = [ 72 | "client_auth", 73 | "digital_signature", 74 | "key_agreement", 75 | "key_encipherment", 76 | "server_auth", 77 | ] 78 | 79 | # provisioner "local-exec" { 80 | # command = "echo '${tls_locally_signed_cert.server.cert_pem}' > ./vault-crt.pem" 81 | # } 82 | } 83 | 84 | locals { 85 | tls_data = { 86 | vault_ca = base64encode(tls_self_signed_cert.ca.cert_pem) 87 | vault_cert = base64encode(tls_locally_signed_cert.server.cert_pem) 88 | vault_pk = base64encode(tls_private_key.server.private_key_pem) 89 | } 90 | } 91 | 92 | locals { 93 | secret = jsonencode(local.tls_data) 94 | } 95 | 96 | -------------------------------------------------------------------------------- /modules/user_data/templates/install_vault.sh.tpl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | imds_token=$( curl -Ss -H "X-aws-ec2-metadata-token-ttl-seconds: 30" -XPUT 169.254.169.254/latest/api/token ) 4 | instance_id=$( curl -Ss -H "X-aws-ec2-metadata-token: $imds_token" 169.254.169.254/latest/meta-data/instance-id ) 5 | local_ipv4=$( curl -Ss -H "X-aws-ec2-metadata-token: $imds_token" 169.254.169.254/latest/meta-data/local-ipv4 ) 6 | 7 | # install package 8 | 9 | curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add - 10 | apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" 11 | apt-get update 12 | apt-get install -y vault=${vault_version}-* awscli jq 13 | 14 | echo "Configuring system time" 15 | timedatectl set-timezone UTC 16 | 17 | # removing any default installation files from /opt/vault/tls/ 18 | rm -rf /opt/vault/tls/* 19 | 20 | # /opt/vault/tls should be readable by all users of the system 21 | chmod 0755 /opt/vault/tls 22 | 23 | # vault-key.pem should be readable by the vault group only 24 | touch /opt/vault/tls/vault-key.pem 25 | chown root:vault /opt/vault/tls/vault-key.pem 26 | chmod 0640 /opt/vault/tls/vault-key.pem 27 | 28 | secret_result=$(aws secretsmanager get-secret-value --secret-id ${secrets_manager_arn} --region ${region} --output text --query SecretString) 29 | 30 | jq -r .vault_cert <<< "$secret_result" | base64 -d > /opt/vault/tls/vault-cert.pem 31 | 32 | jq -r .vault_ca <<< "$secret_result" | base64 -d > /opt/vault/tls/vault-ca.pem 33 | 34 | jq -r .vault_pk <<< "$secret_result" | base64 -d > /opt/vault/tls/vault-key.pem 35 | 36 | cat << EOF > /etc/vault.d/vault.hcl 37 | ui = true 38 | disable_mlock = true 39 | 40 | storage "raft" { 41 | path = "/opt/vault/data" 42 | node_id = "$instance_id" 43 | retry_join { 44 | auto_join = "provider=aws region=${region} tag_key=${name}-vault tag_value=server" 45 | auto_join_scheme = "https" 46 | leader_tls_servername = "${leader_tls_servername}" 47 | leader_ca_cert_file = "/opt/vault/tls/vault-ca.pem" 48 | leader_client_cert_file = "/opt/vault/tls/vault-cert.pem" 49 | leader_client_key_file = "/opt/vault/tls/vault-key.pem" 50 | } 51 | } 52 | 53 | cluster_addr = "https://$local_ipv4:8201" 54 | api_addr = "https://$local_ipv4:8200" 55 | 56 | listener "tcp" { 57 | address = "0.0.0.0:8200" 58 | tls_disable = false 59 | tls_cert_file = "/opt/vault/tls/vault-cert.pem" 60 | tls_key_file = "/opt/vault/tls/vault-key.pem" 61 | tls_client_ca_file = "/opt/vault/tls/vault-ca.pem" 62 | } 63 | 64 | seal "awskms" { 65 | region = "${region}" 66 | kms_key_id = "${kms_key_arn}" 67 | } 68 | 69 | EOF 70 | 71 | # vault.hcl should be readable by the vault group only 72 | chown root:root /etc/vault.d 73 | chown root:vault /etc/vault.d/vault.hcl 74 | chmod 640 /etc/vault.d/vault.hcl 75 | 76 | systemctl enable vault 77 | systemctl start vault 78 | 79 | echo "Setup Vault profile" 80 | cat < c.name === process.env.job); 98 | 99 | const { data: result } = await github.checks.update({ 100 | ...context.repo, 101 | check_run_id: check[0].id, 102 | status: 'completed', 103 | conclusion: process.env.conclusion 104 | }); 105 | 106 | return result; 107 | -------------------------------------------------------------------------------- /test/deployment_test.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2014-2022 HashiCorp, Inc. 2 | // 3 | // This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | // 5 | 6 | package test 7 | 8 | import ( 9 | "fmt" 10 | "io/ioutil" 11 | "os" 12 | "path/filepath" 13 | "regexp" 14 | "runtime" 15 | "strings" 16 | "testing" 17 | 18 | "github.com/gruntwork-io/terratest/modules/logger" 19 | "github.com/gruntwork-io/terratest/modules/terraform" 20 | "github.com/stretchr/testify/assert" 21 | ) 22 | 23 | var tfcOrg string = "hc-tfc-dev" 24 | 25 | var repoName string = "terraform-aws-vault-starter" 26 | 27 | func TestClusterDeployment(t *testing.T) { 28 | var deployEnv string 29 | var region string 30 | var azs string 31 | 32 | if os.Getenv("AWS_DEFAULT_REGION") != "" { 33 | region = os.Getenv("AWS_DEFAULT_REGION") 34 | } else { 35 | logger.Log(t, "Defaulting to us-east-1 AWS region") 36 | region = "us-east-1" 37 | } 38 | azs = fmt.Sprintf("[\"%sa\", \"%sb\", \"%sc\"]", region, region, region) 39 | 40 | cwdPath, err := os.Getwd() 41 | if err != nil { 42 | logger.Log(t, "Unable to get current working directory") 43 | t.FailNow() 44 | } 45 | 46 | // TFC API token will be needed to update workspaces 47 | tfcToken := getTfeToken(t) 48 | if tfcToken == "" { 49 | t.FailNow() 50 | } 51 | 52 | if os.Getenv("DEPLOY_ENV") != "" { 53 | deployEnv = os.Getenv("DEPLOY_ENV") 54 | } else { 55 | if runtime.GOOS == "windows" { 56 | deployEnv = "test" + os.Getenv("USERNAME") 57 | } else { 58 | deployEnv = "test" + os.Getenv("USER") 59 | } 60 | } 61 | 62 | // Cleanup any characters that will cause problems in resource & workspace names 63 | deployEnv = strings.Replace(deployEnv, ".", "", -1) 64 | 65 | workspaceName := repoName + "-" + deployEnv 66 | 67 | // Run module, and setup its destruction during CI 68 | // (non-CI destruction is conditionally configured after tests below) 69 | terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{TerraformDir: cwdPath, Lock: true}) 70 | removeAutoTfvars(t, cwdPath) 71 | tfVars := fmt.Sprintf("azs = %s\ncommon_tags = { environment = \"%s\" }\nregion = \"%s\"\nresource_name_prefix = \"%s\"\n", azs, deployEnv, region, deployEnv) 72 | if os.Getenv("AWS_PERMISSIONS_BOUNDARY") != "" { 73 | tfVars = tfVars + fmt.Sprintf("permissions_boundary = \"%s\"\n", os.Getenv("AWS_PERMISSIONS_BOUNDARY")) 74 | } 75 | ioutil.WriteFile(filepath.Join(cwdPath, deployEnv+".auto.tfvars"), []byte(tfVars), 0644) 76 | if os.Getenv("GITHUB_ACTIONS") != "" { 77 | defer tfDestroyAndDeleteWorkspaceWithRetries(t, terraformOptions, tfcOrg, tfcToken, workspaceName, 3) 78 | } 79 | createTfcWorkspace(t, tfcOrg, tfcToken, workspaceName) 80 | os.Setenv("TF_WORKSPACE", workspaceName) 81 | terraform.Init(t, terraformOptions) 82 | if os.Getenv("GITHUB_ACTIONS") == "" { 83 | writeWorkspaceNameToTfDir(cwdPath, workspaceName) 84 | } 85 | terraform.ApplyAndIdempotent(t, terraformOptions) 86 | // Gather outputs 87 | vault_operator_raft_list_peers := terraform.Output(t, terraformOptions, "vault_operator_raft_list_peers") 88 | 89 | // Perform validation comparisons and collect pass/fail results 90 | _ = os.Unsetenv("TF_WORKSPACE") 91 | var testResults []bool 92 | 93 | // Check for the 5 peers 94 | instanceRegex := regexp.MustCompile("i-[0-9a-z]*") 95 | testResults = append(testResults, assert.Equal(t, 5, len(instanceRegex.FindAllString(vault_operator_raft_list_peers, -1)))) 96 | 97 | // Comparisons complete; conditionally exit 98 | if os.Getenv("GITHUB_ACTIONS") == "" { 99 | if anyFalse(testResults) { 100 | logger.Log(t, "") 101 | logger.Log(t, "One or more tests failed; skipping terraform destroy") 102 | logger.Log(t, "You should either:") 103 | logger.Log(t, "1) Fix the Terraform code and re-run the tests until they pass and automatically invoke terraform destroy, or") 104 | logger.Log(t, "2) Run terraform destroy \"manually\", i.e. via ./destroy.sh") 105 | logger.Log(t, "") 106 | } else { 107 | if os.Getenv("TEST_DONT_DESTROY_UPON_SUCCESS") == "" { 108 | logger.Log(t, "") 109 | logger.Log(t, "All tests passed succesfully; proceeding to terraform destroy") 110 | logger.Log(t, "") 111 | os.Setenv("TF_WORKSPACE", workspaceName) 112 | terraform.Destroy(t, terraformOptions) 113 | } else { 114 | logger.Log(t, "") 115 | logger.Log(t, "Tests were successful, but skipping terraform destroy because TEST_DONT_DESTROY_UPON_SUCCESS environment variable is set") 116 | logger.Log(t, "") 117 | } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "allowed_inbound_cidrs_lb" { 9 | type = list(string) 10 | description = "(Optional) List of CIDR blocks to permit inbound traffic from to load balancer" 11 | default = null 12 | } 13 | 14 | variable "allowed_inbound_cidrs_ssh" { 15 | type = list(string) 16 | description = "(Optional) List of CIDR blocks to permit for SSH to Vault nodes" 17 | default = null 18 | } 19 | 20 | variable "additional_lb_target_groups" { 21 | type = list(string) 22 | description = "(Optional) List of load balancer target groups to associate with the Vault cluster. These target groups are _in addition_ to the LB target group this module provisions by default." 23 | default = [] 24 | } 25 | 26 | variable "common_tags" { 27 | type = map(string) 28 | description = "(Optional) Map of common tags for all taggable AWS resources." 29 | default = {} 30 | } 31 | 32 | variable "instance_type" { 33 | type = string 34 | default = "m5.xlarge" 35 | description = "EC2 instance type" 36 | } 37 | 38 | variable "key_name" { 39 | type = string 40 | default = null 41 | description = "(Optional) key pair to use for SSH access to instance" 42 | } 43 | 44 | variable "kms_key_deletion_window" { 45 | type = number 46 | default = 7 47 | description = "Duration in days after which the key is deleted after destruction of the resource (must be between 7 and 30 days)." 48 | } 49 | 50 | variable "leader_tls_servername" { 51 | type = string 52 | description = "One of the shared DNS SAN used to create the certs use for mTLS" 53 | } 54 | 55 | variable "lb_certificate_arn" { 56 | type = string 57 | description = "ARN of TLS certificate imported into ACM for use with LB listener" 58 | } 59 | 60 | variable "lb_deregistration_delay" { 61 | type = string 62 | description = "Amount time, in seconds, for Vault LB target group to wait before changing the state of a deregistering target from draining to unused." 63 | default = 300 64 | } 65 | 66 | variable "lb_health_check_path" { 67 | type = string 68 | description = "The endpoint to check for Vault's health status." 69 | default = "/v1/sys/health?activecode=200&standbycode=200&sealedcode=200&uninitcode=200" 70 | } 71 | 72 | variable "lb_type" { 73 | description = "The type of load balancer to provision; network or application." 74 | type = string 75 | default = "application" 76 | 77 | validation { 78 | condition = contains(["application", "network"], var.lb_type) 79 | error_message = "The variable lb_type must be one of: application, network." 80 | } 81 | } 82 | 83 | variable "node_count" { 84 | type = number 85 | default = 5 86 | description = "Number of Vault nodes to deploy in ASG" 87 | } 88 | 89 | variable "permissions_boundary" { 90 | description = "(Optional) IAM Managed Policy to serve as permissions boundary for created IAM Roles" 91 | type = string 92 | default = null 93 | } 94 | 95 | variable "private_subnet_ids" { 96 | type = list(string) 97 | description = "Subnet IDs to deploy Vault into" 98 | } 99 | 100 | variable "resource_name_prefix" { 101 | type = string 102 | description = "Resource name prefix used for tagging and naming AWS resources" 103 | } 104 | 105 | variable "secrets_manager_arn" { 106 | type = string 107 | description = "Secrets manager ARN where TLS cert info is stored" 108 | } 109 | 110 | variable "ssl_policy" { 111 | type = string 112 | default = "ELBSecurityPolicy-TLS-1-2-2017-01" 113 | description = "SSL policy to use on LB listener" 114 | } 115 | 116 | variable "user_supplied_ami_id" { 117 | type = string 118 | description = "(Optional) User-provided AMI ID to use with Vault instances. If you provide this value, please ensure it will work with the default userdata script (assumes latest version of Ubuntu LTS). Otherwise, please provide your own userdata script using the user_supplied_userdata_path variable." 119 | default = null 120 | } 121 | 122 | variable "user_supplied_iam_role_name" { 123 | type = string 124 | description = "(Optional) User-provided IAM role name. This will be used for the instance profile provided to the AWS launch configuration. The minimum permissions must match the defaults generated by the IAM submodule for cloud auto-join and auto-unseal." 125 | default = null 126 | } 127 | 128 | variable "user_supplied_kms_key_arn" { 129 | type = string 130 | description = "(Optional) User-provided KMS key ARN. Providing this will disable the KMS submodule from generating a KMS key used for Vault auto-unseal" 131 | default = null 132 | } 133 | 134 | variable "user_supplied_userdata_path" { 135 | type = string 136 | description = "(Optional) File path to custom userdata script being supplied by the user" 137 | default = null 138 | } 139 | 140 | variable "vault_version" { 141 | type = string 142 | default = "1.11.0" 143 | description = "Vault version" 144 | } 145 | 146 | variable "vpc_id" { 147 | type = string 148 | description = "VPC ID where Vault will be deployed" 149 | } 150 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vault AWS Module 2 | 3 | This is a Terraform module for provisioning Vault with [integrated 4 | storage](https://www.vaultproject.io/docs/concepts/integrated-storage) on AWS. 5 | This module defaults to setting up a cluster with 5 Vault nodes (as recommended 6 | by the [Vault with Integrated Storage Reference 7 | Architecture](https://learn.hashicorp.com/vault/operations/raft-reference-architecture)). 8 | 9 | ## About This Module 10 | This module implements the [Vault with Integrated Storage Reference 11 | Architecture](https://learn.hashicorp.com/vault/operations/raft-reference-architecture#node) 12 | on AWS using the open source version of Vault 1.8+. 13 | 14 | ## How to Use This Module 15 | 16 | - Ensure your AWS credentials are [configured 17 | correctly](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) 18 | and have permission to use the following AWS services: 19 | - Amazon Certificate Manager (ACM) 20 | - Amazon EC2 21 | - Amazon Elastic Load Balancing (ALB) 22 | - AWS Identity & Access Management (IAM) 23 | - AWS Key Management System (KMS) 24 | - Amazon Secrets Manager 25 | - AWS Systems Manager Session Manager (optional - used to connect to EC2 26 | instances with session manager using the AWS CLI) 27 | - Amazon VPC 28 | 29 | - This module assumes you have an existing VPC along with an AWS secrets manager 30 | that contains TLS certs for the Vault nodes and load balancer. If you do not, 31 | you may use the following 32 | [quickstart](https://github.com/hashicorp/terraform-aws-vault-starter/tree/main/examples/prereqs_quickstart) 33 | to deploy these resources. 34 | 35 | - To deploy into an existing VPC, ensure the following components exist and are 36 | routed to each other correctly: 37 | - Three public subnets 38 | - Three [NAT 39 | gateways](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html) (one in each public subnet) 40 | - Three private subnets 41 | 42 | - Create a Terraform configuration that pulls in the Vault module and specifies 43 | values for the required variables: 44 | 45 | ```hcl 46 | provider "aws" { 47 | # your AWS region 48 | region = "us-east-1" 49 | } 50 | 51 | module "vault" { 52 | source = "hashicorp/vault-starter/aws" 53 | version = "~> 1.0" 54 | 55 | # prefix for tagging/naming AWS resources 56 | resource_name_prefix = "test" 57 | # VPC ID you wish to deploy into 58 | vpc_id = "vpc-abc123xxx" 59 | # private subnet IDs are required and allow you to specify which 60 | # subnets you will deploy your Vault nodes into 61 | private_subnet_ids = [ 62 | "subnet-0xyz", 63 | "subnet-1xyz", 64 | "subnet-2xyz", 65 | ] 66 | # AWS Secrets Manager ARN where TLS certs are stored 67 | secrets_manager_arn = "arn:aws::secretsmanager:abc123xxx" 68 | # The shared DNS SAN of the TLS certs being used 69 | leader_tls_servername = "vault.server.com" 70 | # The cert ARN to be used on the Vault LB listener 71 | lb_certificate_arn = "arn:aws:acm:abc123xxx" 72 | } 73 | ``` 74 | 75 | - Run `terraform init` and `terraform apply` 76 | 77 | - You must 78 | [initialize](https://www.vaultproject.io/docs/commands/operator/init#operator-init) 79 | your Vault cluster after you create it. Begin by logging into your Vault 80 | cluster using one of the following methods: 81 | - Using [Session 82 | Manager](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/session-manager.html) 83 | - SSH (you must provide the optional SSH key pair through the `key_name` 84 | variable and set a value for the `allowed_inbound_cidrs_ssh` variable. 85 | - Please note this Vault cluster is not public-facing. If you want to 86 | use SSH from outside the VPC, you are required to establish your own 87 | connection to it (VPN, etc). 88 | 89 | **Please Note**: if you are using Session Manager to connect to your nodes and 90 | will run vault commands as the default `ssm-user`, it is important you first run 91 | the following command to source the environment variables that Vault requires: 92 | 93 | ``` 94 | $ . /etc/profile 95 | ``` 96 | 97 | - To initialize the Vault cluster, run the following commands: 98 | 99 | ```bash 100 | vault operator init 101 | ``` 102 | 103 | - This should return back the following output which includes the recovery 104 | keys and initial root token (omitted here): 105 | 106 | ``` 107 | ... 108 | Success! Vault is initialized 109 | ``` 110 | 111 | - Please securely store the recovery keys and initial root token that Vault 112 | returns to you. 113 | - To check the status of your Vault cluster, export your Vault token and run 114 | the 115 | [list-peers](https://www.vaultproject.io/docs/commands/operator/raft#list-peers) 116 | command: 117 | 118 | ```bash 119 | export VAULT_TOKEN="" 120 | vault operator raft list-peers 121 | ``` 122 | 123 | - Please note that Vault does not enable [dead server 124 | cleanup](https://www.vaultproject.io/docs/concepts/integrated-storage/autopilot#dead-server-cleanup) 125 | by default. You must enable this to avoid manually managing the Raft 126 | configuration every time there is a change in the Vault ASG. To enable dead 127 | server cleanup, run the following command: 128 | 129 | ```bash 130 | vault operator raft autopilot set-config \ 131 | -cleanup-dead-servers=true \ 132 | -dead-server-last-contact-threshold=10 \ 133 | -min-quorum=3 134 | ``` 135 | 136 | - You can verify these settings after you apply them by running the following command: 137 | 138 | ```bash 139 | vault operator raft autopilot get-config 140 | ``` 141 | 142 | ## License 143 | 144 | This code is released under the Mozilla Public License 2.0. Please see 145 | [LICENSE](https://github.com/hashicorp/terraform-aws-vault-starter/blob/main/LICENSE) 146 | for more details. 147 | -------------------------------------------------------------------------------- /modules/vm/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | data "aws_ami" "ubuntu" { 9 | count = var.user_supplied_ami_id != null ? 0 : 1 10 | most_recent = true 11 | 12 | filter { 13 | name = "name" 14 | values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] 15 | } 16 | 17 | filter { 18 | name = "virtualization-type" 19 | values = ["hvm"] 20 | } 21 | 22 | owners = ["099720109477"] # Canonical 23 | } 24 | 25 | resource "aws_security_group" "vault" { 26 | name = "${var.resource_name_prefix}-vault" 27 | vpc_id = var.vpc_id 28 | 29 | tags = merge( 30 | { Name = "${var.resource_name_prefix}-vault-sg" }, 31 | var.common_tags, 32 | ) 33 | } 34 | 35 | resource "aws_security_group_rule" "vault_internal_api" { 36 | description = "Allow Vault nodes to reach other on port 8200 for API" 37 | security_group_id = aws_security_group.vault.id 38 | type = "ingress" 39 | from_port = 8200 40 | to_port = 8200 41 | protocol = "tcp" 42 | self = true 43 | } 44 | 45 | resource "aws_security_group_rule" "vault_internal_raft" { 46 | description = "Allow Vault nodes to communicate on port 8201 for replication traffic, request forwarding, and Raft gossip" 47 | security_group_id = aws_security_group.vault.id 48 | type = "ingress" 49 | from_port = 8201 50 | to_port = 8201 51 | protocol = "tcp" 52 | self = true 53 | } 54 | 55 | # The following data source gets used if the user has 56 | # specified a network load balancer. 57 | # This will lock down the EC2 instance security group to 58 | # just the subnets that the load balancer spans 59 | # (which are the private subnets the Vault instances use) 60 | 61 | data "aws_subnet" "subnet" { 62 | count = length(var.vault_subnets) 63 | id = var.vault_subnets[count.index] 64 | } 65 | 66 | locals { 67 | subnet_cidr_blocks = [for s in data.aws_subnet.subnet : s.cidr_block] 68 | } 69 | 70 | resource "aws_security_group_rule" "vault_network_lb_inbound" { 71 | count = var.lb_type == "network" ? 1 : 0 72 | description = "Allow load balancer to reach Vault nodes on port 8200" 73 | security_group_id = aws_security_group.vault.id 74 | type = "ingress" 75 | from_port = 8200 76 | to_port = 8200 77 | protocol = "tcp" 78 | cidr_blocks = local.subnet_cidr_blocks 79 | } 80 | 81 | resource "aws_security_group_rule" "vault_application_lb_inbound" { 82 | count = var.lb_type == "application" ? 1 : 0 83 | description = "Allow load balancer to reach Vault nodes on port 8200" 84 | security_group_id = aws_security_group.vault.id 85 | type = "ingress" 86 | from_port = 8200 87 | to_port = 8200 88 | protocol = "tcp" 89 | source_security_group_id = var.vault_lb_sg_id 90 | } 91 | 92 | resource "aws_security_group_rule" "vault_network_lb_ingress" { 93 | count = var.lb_type == "network" && var.allowed_inbound_cidrs != null ? 1 : 0 94 | description = "Allow specified CIDRs access to load balancer and nodes on port 8200" 95 | security_group_id = aws_security_group.vault.id 96 | type = "ingress" 97 | from_port = 8200 98 | to_port = 8200 99 | protocol = "tcp" 100 | cidr_blocks = var.allowed_inbound_cidrs 101 | } 102 | 103 | resource "aws_security_group_rule" "vault_ssh_inbound" { 104 | count = var.allowed_inbound_cidrs_ssh != null ? 1 : 0 105 | description = "Allow specified CIDRs SSH access to Vault nodes" 106 | security_group_id = aws_security_group.vault.id 107 | type = "ingress" 108 | from_port = 22 109 | to_port = 22 110 | protocol = "tcp" 111 | cidr_blocks = var.allowed_inbound_cidrs_ssh 112 | } 113 | 114 | resource "aws_security_group_rule" "vault_outbound" { 115 | description = "Allow Vault nodes to send outbound traffic" 116 | security_group_id = aws_security_group.vault.id 117 | type = "egress" 118 | from_port = 0 119 | to_port = 0 120 | protocol = "-1" 121 | cidr_blocks = ["0.0.0.0/0"] 122 | } 123 | 124 | resource "aws_launch_template" "vault" { 125 | name = "${var.resource_name_prefix}-vault" 126 | image_id = var.user_supplied_ami_id != null ? var.user_supplied_ami_id : data.aws_ami.ubuntu[0].id 127 | instance_type = var.instance_type 128 | key_name = var.key_name != null ? var.key_name : null 129 | user_data = var.userdata_script 130 | vpc_security_group_ids = [ 131 | aws_security_group.vault.id, 132 | ] 133 | 134 | block_device_mappings { 135 | device_name = "/dev/sda1" 136 | 137 | ebs { 138 | volume_type = "gp3" 139 | volume_size = 100 140 | throughput = 150 141 | iops = 3000 142 | delete_on_termination = true 143 | } 144 | } 145 | 146 | iam_instance_profile { 147 | name = var.aws_iam_instance_profile 148 | } 149 | 150 | metadata_options { 151 | http_endpoint = "enabled" 152 | http_tokens = "required" 153 | } 154 | } 155 | 156 | resource "aws_autoscaling_group" "vault" { 157 | name = "${var.resource_name_prefix}-vault" 158 | min_size = var.node_count 159 | max_size = var.node_count 160 | desired_capacity = var.node_count 161 | vpc_zone_identifier = var.vault_subnets 162 | target_group_arns = var.vault_target_group_arns 163 | 164 | launch_template { 165 | id = aws_launch_template.vault.id 166 | version = "$Latest" 167 | } 168 | 169 | tags = concat( 170 | [ 171 | { 172 | key = "Name" 173 | value = "${var.resource_name_prefix}-vault-server" 174 | propagate_at_launch = true 175 | } 176 | ], 177 | [ 178 | { 179 | key = "${var.resource_name_prefix}-vault" 180 | value = "server" 181 | propagate_at_launch = true 182 | } 183 | ], 184 | [ 185 | for k, v in var.common_tags : { 186 | key = k 187 | value = v 188 | propagate_at_launch = true 189 | } 190 | ] 191 | ) 192 | } 193 | -------------------------------------------------------------------------------- /test/utils.go: -------------------------------------------------------------------------------- 1 | // Copyright © 2014-2022 HashiCorp, Inc. 2 | // 3 | // This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | // 5 | 6 | package test 7 | 8 | import ( 9 | "bytes" 10 | "encoding/json" 11 | "fmt" 12 | "io/ioutil" 13 | "net/http" 14 | "os" 15 | "path/filepath" 16 | "strings" 17 | "testing" 18 | 19 | "github.com/gruntwork-io/terratest/modules/logger" 20 | "github.com/gruntwork-io/terratest/modules/terraform" 21 | "github.com/hashicorp/hcl" 22 | ) 23 | 24 | type TfConfig struct { 25 | Credentials map[string]map[string]interface{} `hcl:"credentials"` 26 | } 27 | 28 | type TfcCreateResponseData struct { 29 | Id string `json:"id"` 30 | } 31 | 32 | type TfcCreateResponse struct { 33 | Data TfcCreateResponseData `json:"data"` 34 | } 35 | 36 | func getTfeToken(t *testing.T) string { 37 | if os.Getenv("TF_TOKEN_app_terraform_io") != "" { 38 | return os.Getenv("TF_TOKEN_app_terraform_io") 39 | } else { 40 | homeDir, err := os.UserHomeDir() 41 | if err != nil { 42 | logger.Log(t, "") 43 | logger.Log(t, "Failed to determine home directory") 44 | return "" 45 | } 46 | 47 | terraformRcFilePath := filepath.Join(homeDir, ".terraformrc") 48 | if _, err := os.Stat(terraformRcFilePath); err == nil { 49 | terraformRcBytes, err := ioutil.ReadFile(terraformRcFilePath) 50 | if err != nil { 51 | logger.Log(t, "") 52 | logger.Log(t, err) 53 | } else { 54 | terraformRcObj, err := hcl.Parse(string(terraformRcBytes)) 55 | if err != nil { 56 | logger.Log(t, "") 57 | logger.Log(t, err) 58 | } else { 59 | parsedResult := &TfConfig{} 60 | if err := hcl.DecodeObject(&parsedResult, terraformRcObj); err != nil { 61 | logger.Log(t, "") 62 | logger.Log(t, err) 63 | } else { 64 | if appTfIoCreds, ok := parsedResult.Credentials["app.terraform.io"]; ok { 65 | if token, ok := appTfIoCreds["token"]; ok { 66 | return fmt.Sprintf("%v", token) 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | } 74 | logger.Log(t, "") 75 | logger.Log(t, "Failed to load Terraform Cloud credentials (have you run terraform login?)") 76 | return "" 77 | } 78 | 79 | func createTfcWorkspace(t *testing.T, tfcOrg string, tfcToken string, workspace string) { 80 | payload := []byte("{\"data\": {\"type\": \"workspaces\", \"attributes\": {\"execution-mode\": \"local\", \"name\": \"" + workspace + "\"}}}") 81 | client := &http.Client{} 82 | url := "https://app.terraform.io/api/v2/organizations/" + tfcOrg + "/workspaces" 83 | 84 | req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payload)) 85 | if err != nil { 86 | logger.Log(t, err) 87 | t.FailNow() 88 | } 89 | req.Header.Set("Authorization", "Bearer "+tfcToken) 90 | req.Header.Set("Content-Type", "application/vnd.api+json") 91 | 92 | resp, err := client.Do(req) 93 | if err != nil { 94 | // TODO: would be better to check the error and only silently continue if the workspace was already present 95 | logger.Log(t, err) 96 | } 97 | 98 | var res TfcCreateResponse 99 | json.NewDecoder(resp.Body).Decode(&res) 100 | if res.Data.Id != "" { 101 | logger.Log(t, "Tagging workspace") 102 | tagTfcWorkspace(t, tfcOrg, tfcToken, res.Data.Id) 103 | } 104 | } 105 | 106 | func deleteTfcWorkspace(t *testing.T, tfcOrg string, tfcToken string, workspace string) { 107 | client := &http.Client{} 108 | url := "https://app.terraform.io/api/v2/organizations/" + tfcOrg + "/workspaces/" + workspace 109 | 110 | req, err := http.NewRequest(http.MethodDelete, url, bytes.NewBuffer([]byte(""))) 111 | if err != nil { 112 | logger.Log(t, err) 113 | t.FailNow() 114 | } 115 | req.Header.Set("Authorization", "Bearer "+tfcToken) 116 | req.Header.Set("Content-Type", "application/vnd.api+json") 117 | 118 | _, err = client.Do(req) 119 | if err != nil { 120 | logger.Log(t, err) 121 | } 122 | } 123 | 124 | func tagTfcWorkspace(t *testing.T, tfcOrg string, tfcToken string, workspaceId string) { 125 | payload := []byte("{\"data\": [{\"type\": \"tags\", \"attributes\": { \"name\": \"integrationtest\" }}]}") 126 | client := &http.Client{} 127 | url := "https://app.terraform.io/api/v2/workspaces/" + workspaceId + "/relationships/tags" 128 | 129 | req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(payload)) 130 | if err != nil { 131 | logger.Log(t, err) 132 | t.FailNow() 133 | } 134 | req.Header.Set("Authorization", "Bearer "+tfcToken) 135 | req.Header.Set("Content-Type", "application/vnd.api+json") 136 | 137 | _, err = client.Do(req) 138 | if err != nil { 139 | // TODO: would be better to check the error and only silently continue if the tag(s) are already present 140 | logger.Log(t, err) 141 | } 142 | } 143 | 144 | func setWorkspaceToLocalMode(t *testing.T, tfcOrg string, tfcToken string, workspace string) { 145 | payload := []byte("{\"data\": {\"type\": \"workspaces\", \"attributes\": {\"execution-mode\": \"local\"}}}") 146 | client := &http.Client{} 147 | url := "https://app.terraform.io/api/v2/organizations/" + tfcOrg + "/workspaces/" + workspace 148 | 149 | req, err := http.NewRequest(http.MethodPatch, url, bytes.NewBuffer(payload)) 150 | if err != nil { 151 | logger.Log(t, err) 152 | t.FailNow() 153 | } 154 | req.Header.Set("Authorization", "Bearer "+tfcToken) 155 | req.Header.Set("Content-Type", "application/vnd.api+json") 156 | 157 | _, err = client.Do(req) 158 | if err != nil { 159 | logger.Log(t, err) 160 | t.FailNow() 161 | } 162 | } 163 | 164 | func tfDestroyAndDeleteWorkspace(t *testing.T, tfOptions *terraform.Options, tfcOrg string, tfcToken string, workspace string) { 165 | os.Setenv("TF_WORKSPACE", workspace) 166 | terraform.Destroy(t, tfOptions) 167 | logger.Log(t, "") 168 | logger.Log(t, "Terraform destroy successful; deleting TFC workspace "+workspace) 169 | logger.Log(t, "") 170 | deleteTfcWorkspace(t, tfcOrg, tfcToken, workspace) 171 | err := os.Unsetenv("TF_WORKSPACE") 172 | if err != nil { 173 | logger.Log(t, err) 174 | } 175 | } 176 | 177 | func tfDestroyAndDeleteWorkspaceWithRetries(t *testing.T, tfOptions *terraform.Options, tfcOrg string, tfcToken string, workspace string, attempts int) { 178 | os.Setenv("TF_WORKSPACE", workspace) 179 | tfDestroyWithRetries(t, tfOptions, attempts) 180 | logger.Log(t, "") 181 | logger.Log(t, "Terraform destroy successful; deleting TFC workspace "+workspace) 182 | logger.Log(t, "") 183 | deleteTfcWorkspace(t, tfcOrg, tfcToken, workspace) 184 | err := os.Unsetenv("TF_WORKSPACE") 185 | if err != nil { 186 | logger.Log(t, err) 187 | } 188 | } 189 | 190 | func anyFalse(s []bool) bool { 191 | for _, v := range s { 192 | if v == false { 193 | return true 194 | } 195 | } 196 | return false 197 | } 198 | 199 | // Remove any .auto.tfvars files present in path 200 | func removeAutoTfvars(t *testing.T, path string) { 201 | files, err := ioutil.ReadDir(path) 202 | if err != nil { 203 | logger.Log(t, "") 204 | logger.Log(t, "Error reading module directory to cleanup .auto.tfvars files") 205 | logger.Log(t, "") 206 | t.FailNow() 207 | } 208 | 209 | for _, file := range files { 210 | if file.IsDir() == false && strings.HasSuffix(file.Name(), ".auto.tfvars") { 211 | err = os.Remove(filepath.Join(path, file.Name())) 212 | if err != nil { 213 | logger.Log(t, "") 214 | logger.Log(t, "Error deleting .auto.tfvars file") 215 | logger.Log(t, "") 216 | t.FailNow() 217 | } 218 | } 219 | } 220 | } 221 | 222 | // Repeatedly call "terraform apply -destroy" and ignore errors until the final attempt 223 | // This can be used to work around resources that don't always destroy correctly on the first attempt 224 | func tfDestroyWithRetries(t *testing.T, terraformOpts *terraform.Options, attempts int) { 225 | for i := 1; i < attempts; i++ { 226 | _, err := terraform.DestroyE(t, terraformOpts) 227 | if err == nil { 228 | return 229 | } 230 | logger.Log(t, "Error encountered while running \"terraform apply -destroy\"; retrying...") 231 | } 232 | terraform.Destroy(t, terraformOpts) 233 | } 234 | 235 | // Persist Terraform Workspace name so users can run diagnostic 236 | // Terraform commands without setting the TF_WORKSPACE env var or 237 | // running "terraform workspace select" first 238 | func writeWorkspaceNameToTfDir(modulePath string, workspaceName string) { 239 | ioutil.WriteFile(filepath.Join(modulePath, ".terraform", "environment"), []byte(workspaceName), 0644) 240 | } 241 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | --------------------------------------------------------------------------------