Skip to content

Commit db83119

Browse files
committed
feat: prepare aws-client-vpn to EUSC AWS partition, migrate Terragrunt cli usage
1 parent 3d23857 commit db83119

File tree

4 files changed

+134
-18
lines changed

4 files changed

+134
-18
lines changed

terraform/aws/aws-client-vpn/Makefile

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,48 @@ SHELL := /usr/bin/env bash
44
DEBUG := false
55
ifeq ($(strip $(DEBUG)),true)
66
TF_LOG := DEBUG
7-
TG_FLAGS := --terragrunt-debug
7+
TG_FLAGS := --inputs-debug
88
endif
99

1010
MODE := apply
1111
ifeq ($(strip $(MODE)),apply)
12-
MODE_STR := apply -auto-approve
12+
MODE_STR := --non-interactive -- apply -auto-approve
1313
else ifeq ($(strip $(MODE)),destroy)
14-
MODE_STR := destroy -auto-approve
14+
MODE_STR := --non-interactive -- destroy -auto-approve
1515
else
16-
MODE_STR := plan
16+
MODE_STR := --non-interactive -- plan
1717
endif
1818

19+
PARTITION := aws
20+
1921
ENV := dev
2022

21-
init:
22-
cd stage/$(ENV) && terragrunt init -upgrade=true --backend-bootstrap --non-interactive
23+
ifeq ($(strip $(PARTITION)),eusc)
24+
DEPLOY_PATH := stage/eusc/$(ENV)
25+
else
26+
DEPLOY_PATH := $(DEPLOY_PATH)
27+
endif
2328

29+
init:
30+
cd $(DEPLOY_PATH) && terragrunt run -- init -upgrade=true
2431

2532
run: init ## setup Client VPN: make run [ENV=dev] [MODE=apply]
26-
@cd stage/$(ENV) && terragrunt validate && terragrunt $(MODE_STR) --non-interactive $(TG_FLAGS)
33+
@cd $(DEPLOY_PATH) && terragrunt run validate && terragrunt run $(MODE_STR) $(TG_FLAGS)
2734

2835
open-webconsole: ## open ARO web console
29-
ARO_CONSOLE_URL="$(shell cd stage/$(ENV) && terragrunt output -raw console_url 2>/dev/null)" && \
36+
ARO_CONSOLE_URL="$(shell cd $(DEPLOY_PATH) && terragrunt output -raw console_url 2>/dev/null)" && \
3037
xdg-open "$${ARO_CONSOLE_URL}" || sensible-browser "$${ARO_CONSOLE_URL}" || x-www-browser "$${ARO_CONSOLE_URL}" || gnome-open "$${ARO_CONSOLE_URL}"
3138

3239

3340

3441
get-client-ovpn: ## create target/client.ovpn file needed to connect to VPN
3542
mkdir -p target && cd target && \
36-
REGION="$(shell cd stage/$(ENV) && terragrunt output -raw region 2>/dev/null)" && \
37-
CLIENT_VPN_ENDPOINT_ID="$(shell cd stage/$(ENV) && terragrunt output -raw client_vpn_endpoint_id 2>/dev/null)" && \
43+
REGION="$(shell cd $(DEPLOY_PATH) && terragrunt output -raw region 2>/dev/null)" && \
44+
CLIENT_VPN_ENDPOINT_ID="$(shell cd $(DEPLOY_PATH) && terragrunt output -raw client_vpn_endpoint_id 2>/dev/null)" && \
3845
aws ec2 export-client-vpn-client-configuration --output text \
3946
--region "$${REGION}" \
4047
--client-vpn-endpoint-id "$${CLIENT_VPN_ENDPOINT_ID}" > client.ovpn
41-
cd stage/$(ENV) && \
48+
cd $(DEPLOY_PATH) && \
4249
terragrunt output -raw client-ovpn-extension-config 2>/dev/null >> ../../target/client.ovpn
4350

4451
connect-to-vpn: get-client-ovpn ## connect to Open VPN peer
@@ -47,7 +54,7 @@ connect-to-vpn: get-client-ovpn ## connect to Open VPN peer
4754

4855

4956
show-state: ## show state
50-
cd stage/$(ENV) && terragrunt state list && terragrunt show
57+
cd $(DEPLOY_PATH) && terragrunt state list && terragrunt show
5158

5259
clean: ## clean cached plugins and data
5360
find . -name ".terra*" -exec rm -rf {} +

terraform/aws/aws-client-vpn/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,18 @@ sudo apparmor_parser -r /etc/apparmor.d/openvpn
3636

3737
```bash
3838
# setup Client Side VPN
39-
make run ENV=dev MODE=apply
39+
make run MODE=apply [ENV=dev] [PARTITION=aws]
4040

4141
# create target/client.ovpn file needed to connect to VPN
4242
# mode is either all (default), aka all trafic goes via VPN
43-
# or private - when only GCP VPC traffic routed via VPN
43+
# or private - when only VPC traffic routed via VPN
4444
make get-client-ovpn ENV=dev
4545

4646
# connect to to VPN, press Ctrl+C to disconnect
4747
# mode is either all (default), aka all trafic goes via VPN
48-
# or private - when only GCP VPC traffic routed via VPN
48+
# or private - when only VPC traffic routed via VPN
4949
make connect-to-vpn
5050

5151
# show Terraform state
5252
make show-state
53-
54-
# terminates all AWS resource created with apply task
55-
make destroy
5653
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
locals {
2+
bucket = "${local.account}-terraform-state"
3+
account = "${run_cmd("--terragrunt-quiet", "aws", "sts", "get-caller-identity", "--query", "\"Account\"", "--output", "text")}"
4+
region = "eusc-de-east-1"
5+
zone = "eusc-de-east-1a"
6+
}
7+
8+
remote_state {
9+
backend = "s3"
10+
generate = {
11+
path = "state.tf"
12+
if_exists = "overwrite_terragrunt"
13+
}
14+
config = {
15+
bucket = local.bucket
16+
key = "${basename(abspath("${get_parent_terragrunt_dir()}/.."))}/${basename(get_parent_terragrunt_dir())}/${path_relative_to_include()}/terraform.tfstate"
17+
region = local.region
18+
# TODO play with it... maybe not in free tier
19+
# encrypt = true
20+
# dynamodb_table = "my-lock-table"
21+
}
22+
}
23+
24+
25+
generate "provider" {
26+
path = "provider.tf"
27+
if_exists = "overwrite_terragrunt"
28+
contents = <<EOF
29+
variable "aws_tags" {
30+
type = map
31+
}
32+
33+
provider "aws" {
34+
region = var.region
35+
default_tags {
36+
tags = var.aws_tags
37+
}
38+
}
39+
40+
EOF
41+
}
42+
43+
terraform {
44+
extra_arguments "common_vars" {
45+
commands = get_terraform_commands_that_need_vars()
46+
47+
env_vars = {
48+
TF_VAR_terraform_state_bucket = local.bucket
49+
}
50+
}
51+
}
52+
53+
inputs = {
54+
account = local.account
55+
region = local.region
56+
zone = local.zone
57+
58+
partition = "aws-eusc"
59+
60+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# TODO as of now EUSC does not support Client VPN, so this is just a placeholder for when it will be supported.
2+
#
3+
# Error: creating EC2 Client VPN Endpoint: operation error EC2: CreateClientVpnEndpoint,
4+
# https response error StatusCode: 400, RequestID: ...,
5+
# api error InvalidAction: The action CreateClientVpnEndpoint is not valid for this web service.
6+
7+
locals {
8+
pub_ssh = file("~/.ssh/id_rsa.aws.vm.pub")
9+
ssh_key = file("~/.ssh/id_rsa.aws.vm")
10+
# current_ip = "${run_cmd("--terragrunt-quiet", "dig", "+short", "myip.opendns.com", "@resolver1.opendns.com")}"
11+
region = "eusc-de-east-1"
12+
zone = "eusc-de-east-1a"
13+
}
14+
15+
include "root" {
16+
path = find_in_parent_folders("eusc.hcl")
17+
}
18+
19+
terraform {
20+
# https://github.com/gruntwork-io/terragrunt/issues/1675
21+
source = "${find_in_parent_folders("module")}///"
22+
}
23+
24+
25+
inputs = {
26+
env = "dev"
27+
region = local.region
28+
zone = local.zone
29+
# external_access_range = "${local.current_ip}/32"
30+
security_group_names = ["dev-${local.region}-ssh-http-from-vpc", "dev-${local.region}-http-from-external-access-range"]
31+
vpc = "dev-${local.region}"
32+
# using internal VPC DNS resolver, TODO use Route53 internal endpoints
33+
dns_servers = ["10.16.0.2"]
34+
# configuration for Linux/Ubuntu to reconfigure client host DNS resolveconf configuration
35+
vpn_additional_config = <<EOL
36+
script-security 2
37+
up /etc/openvpn/update-resolv-conf
38+
up-restart
39+
down /etc/openvpn/update-resolv-conf
40+
down-pre
41+
EOL
42+
subnet = "private"
43+
zones = ["${local.region}a", "${local.region}b",
44+
# TODO eusc does not have 3 AZs yet
45+
# "${local.region}c"
46+
]
47+
aws_tags = {
48+
Env = "dev"
49+
Region = local.region
50+
}
51+
52+
}

0 commit comments

Comments
 (0)