Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor module
Browse files Browse the repository at this point in the history
snovikov committed Dec 10, 2024

Verified

This commit was signed with the committer’s verified signature.
snovikov Novikov Sergey
1 parent 831f2f2 commit 8a7fa3b
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 25 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ Description: A list of private subnet IDs into which Vault and Consul will be pr

Type: `list(string)`

### <a name="input_ssh_keys"></a> [ssh\_keys](#input\_ssh\_keys)

Description: A list of public ssh keys to add to authorized\_keys files.

Type: `list(string)`

### <a name="input_ssh_security_group_id"></a> [ssh\_security\_group\_id](#input\_ssh\_security\_group\_id)

Description: Security group ID of a bastion (or other EC2 instance) from which you will be allowed to ssh into Vault and Consul.
Expand Down Expand Up @@ -144,6 +138,22 @@ Type: `string`

Default: `""`

### <a name="input_ssh_user"></a> [ssh\_user](#input\_ssh\_user)

Description: User name used for SSH-connections.

Type: `string`

Default: `"ubuntu"`

### <a name="input_ssh_keys"></a> [ssh\_keys](#input\_ssh\_keys)

Description: A list of public ssh keys to add to authorized\_keys files.

Type: `list(string)`

Default: `[]`

### <a name="input_consul_instance_type"></a> [consul\_instance\_type](#input\_consul\_instance\_type)

Description: The type of EC2 Instance to run in the Consul ASG
Expand Down
4 changes: 0 additions & 4 deletions data.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
data "aws_region" "current" {}

data "aws_elb" "vault_elb" {
name = module.vault_elb.name
}
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module "vault_cluster" {
consul_cluster_tag_key = local.consul_cluster_tag_key
consul_cluster_tag_value = local.consul_cluster_tag_val
ssh_keys = join("\n", var.ssh_keys)
ssh_user = "ubuntu"
ssh_user = var.ssh_user
}))

vpc_id = var.vpc_id
Expand Down Expand Up @@ -71,7 +71,7 @@ module "vault_elb" {

resource "aws_autoscaling_attachment" "vault" {
autoscaling_group_name = module.vault_cluster.asg_name
elb = data.aws_elb.vault_elb.id
elb = module.vault_elb.id
}

module "consul_cluster" {
Expand All @@ -86,7 +86,7 @@ module "consul_cluster" {
consul_cluster_tag_key = local.consul_cluster_tag_key
consul_cluster_tag_value = local.consul_cluster_tag_val
ssh_keys = join("\n", var.ssh_keys)
ssh_user = "ubuntu"
ssh_user = var.ssh_user
}))

vpc_id = var.vpc_id
Expand Down
4 changes: 2 additions & 2 deletions modules/consul-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ rules.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_attach_security_group"></a> [attach\_security\_group](#module\_attach\_security\_group) | terraform-aws-modules/security-group/aws | 5.1.0 |
| <a name="module_attach_security_group"></a> [attach\_security\_group](#module\_attach\_security\_group) | terraform-aws-modules/security-group/aws | 5.2.0 |
| <a name="module_iam_policies"></a> [iam\_policies](#module\_iam\_policies) | github.com/hashicorp/terraform-aws-consul//modules/consul-iam-policies | v0.11.0 |
| <a name="module_lc_security_group"></a> [lc\_security\_group](#module\_lc\_security\_group) | terraform-aws-modules/security-group/aws | 5.1.0 |
| <a name="module_lc_security_group"></a> [lc\_security\_group](#module\_lc\_security\_group) | terraform-aws-modules/security-group/aws | 5.2.0 |

## Resources

Expand Down
2 changes: 1 addition & 1 deletion modules/consul-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ resource "aws_launch_template" "launch_template" {
block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = var.root_volume_size
volume_size = var.root_volume_size
delete_on_termination = var.root_volume_delete_on_termination
volume_type = var.root_volume_type
}
Expand Down
4 changes: 2 additions & 2 deletions modules/consul-cluster/security-groups.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "attach_security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
version = "5.2.0"

name = "${var.cluster_name}-att"
description = "Null Placeholder security group for other instances to use as destination to access ${var.cluster_name}"
Expand Down Expand Up @@ -38,7 +38,7 @@ module "attach_security_group" {

module "lc_security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
version = "5.2.0"

name = var.cluster_name
description = "Security group for the ${var.cluster_name} launch configuration"
Expand Down
4 changes: 2 additions & 2 deletions modules/vault-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ machines.

| Name | Source | Version |
|------|--------|---------|
| <a name="module_attach_security_group"></a> [attach\_security\_group](#module\_attach\_security\_group) | terraform-aws-modules/security-group/aws | 5.1.0 |
| <a name="module_lc_security_group"></a> [lc\_security\_group](#module\_lc\_security\_group) | terraform-aws-modules/security-group/aws | 5.1.0 |
| <a name="module_attach_security_group"></a> [attach\_security\_group](#module\_attach\_security\_group) | terraform-aws-modules/security-group/aws | 5.2.0 |
| <a name="module_lc_security_group"></a> [lc\_security\_group](#module\_lc\_security\_group) | terraform-aws-modules/security-group/aws | 5.2.0 |

## Resources

Expand Down
2 changes: 1 addition & 1 deletion modules/vault-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ resource "aws_launch_template" "launch_template" {
block_device_mappings {
device_name = "/dev/sda1"
ebs {
volume_size = var.root_volume_size
volume_size = var.root_volume_size
delete_on_termination = var.root_volume_delete_on_termination
volume_type = var.root_volume_type
}
Expand Down
4 changes: 2 additions & 2 deletions modules/vault-cluster/security-groups.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module "attach_security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
version = "5.2.0"

name = "${var.cluster_name}-att"
description = "Null Placeholder security group for other instances to use as destination to access ${var.cluster_name}"
Expand Down Expand Up @@ -38,7 +38,7 @@ module "attach_security_group" {

module "lc_security_group" {
source = "terraform-aws-modules/security-group/aws"
version = "5.1.0"
version = "5.2.0"

name = var.cluster_name
description = "Security group for the ${var.cluster_name} launch configuration"
Expand Down
2 changes: 1 addition & 1 deletion user-data/consul.sh.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set -x
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

# Add SSH keys
printf "${ssh_keys}\n" > "/home/${ssh_user}/.ssh/authorized_keys"
printf "${ssh_keys}\n" >> "/home/${ssh_user}/.ssh/authorized_keys"
chmod 600 "/home/${ssh_user}/.ssh/authorized_keys"
chown ${ssh_user}:${ssh_user} "/home/${ssh_user}/.ssh/authorized_keys"

Expand Down
2 changes: 1 addition & 1 deletion user-data/vault.sh.tftpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set -x
exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1

# Add SSH keys
printf "${ssh_keys}\n" > "/home/${ssh_user}/.ssh/authorized_keys"
printf "${ssh_keys}\n" >> "/home/${ssh_user}/.ssh/authorized_keys"
chmod 600 "/home/${ssh_user}/.ssh/authorized_keys"
chown ${ssh_user}:${ssh_user} "/home/${ssh_user}/.ssh/authorized_keys"

Expand Down
7 changes: 7 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ variable "vault_route53_public_dns_name" {
type = string
}

variable "ssh_user" {
description = "User name used for SSH-connections."
type = string
default = "ubuntu"
}

variable "ssh_keys" {
description = "A list of public ssh keys to add to authorized_keys files."
type = list(string)
default = []
}

variable "consul_instance_type" {
Expand Down

0 comments on commit 8a7fa3b

Please sign in to comment.