feat(workspace): be able to use this stack by multiple people within same aws account

main
flavien 2023-12-20 15:13:10 +01:00
parent 4f9ecd66fc
commit 4cb08101d2
No known key found for this signature in database
3 changed files with 9 additions and 2 deletions

View File

@ -2,7 +2,7 @@ BACKEND_CONFIG:=backend.tfvars
TERRAFORM_PLAN:=out.tfplan
OVPN_CONFIG:=aws_vpn.ovpn
DEPLOYED_REGION_FILE:=.deployed_region
AWS_REGIONS_FILE:=aws_region.txt
AWS_REGIONS_FILE:=aws_regions.txt
INSTANCE_SIZE ?= micro
PUBLIC_IP ?= $(shell curl -s ifconfig.me)
@ -36,8 +36,12 @@ help:
init: .terraform.lock.hcl
.terraform.lock.hcl: $(BACKEND_CONFIG) providers.tf
ifndef WORKSPACE
$(error WORKSPACE is not set)
endif
@rm -f $@
@terraform init -reconfigure -backend-config $(BACKEND_CONFIG)
@(terraform workspace new $(WORKSPACE) || terraform workspace select $(WORKSPACE))
.PHONY: plan
## plan terraform deployment in random region or REGION if set
@ -59,6 +63,7 @@ deploy: plan
@echo "deploy server in region ${GREEN}$(shell head -n 1 $(DEPLOYED_REGION_FILE))${NC}..."
# always remove plan file after apply because... bug ? => always considered as stale if re-applied
@(terraform apply -input=false $(TERRAFORM_PLAN) && rm $(TERRAFORM_PLAN)) || (rm $(TERRAFORM_PLAN) && exit 1)
@cp $(OVPN_CONFIG) ~/Desktop/$(OVPN_CONFIG)
.PHONY: destroy
## destroy the server deployment

View File

@ -5,8 +5,10 @@ Terraform code to deploy a temporary openvpn server in a specified region only a
### help
`make help` will print the available makefile rules.
### deploy
`make deploy REGION=<aws-region> INSTANCE_SIZE=<nano/micro/...>`
`make deploy WORKSPACE=<...> REGION=<aws-region> INSTANCE_SIZE=<nano/micro/...>`
The provider will use the current aws profile, set a profile with sufficient permissions.
WORKSPACE should be set, it will identify your personal terraform state.
⚠️ Use the same workspace for deploy and destroy!
If REGION is not set, a random region is selected from the regions declared in the file `aws_regions.txt`.
If INSTANCE_SIZE is not set, will use `micro` by default.
PUBLIC_IP can be set manually but is set by default to your current public ip.