Skip to content
This repository was archived by the owner on Feb 15, 2024. It is now read-only.

Commit 1aaf487

Browse files
authoredNov 9, 2021
Squashed commit of the following: (#24)
* Local Terraform state is now default implementation. * Added import/export zip functions to makefile for local tfstate, cerds and tfvars. * Added Documentation to prerequisites explaining Terraform State stores and the import and export commands.
1 parent b649e0d commit 1aaf487

File tree

11 files changed

+66
-77
lines changed

11 files changed

+66
-77
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ certs/
99
Chart.lock
1010
output.json
1111
eudcc-ie/rules/out
12+
exports/
13+
*.zip

‎Makefile

+27-12
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ Enjoy! 😀
3131
endef
3232
export COMPLETION_TEXT_BODY
3333

34-
ifeq ($(strip $(PREFIX)),)
35-
WORKSPACE = "default"
36-
else
37-
WORKSPACE = $(PREFIX)
38-
endif
3934

4035
.PHONY: all
4136
all: checks certs terraform
@@ -52,12 +47,6 @@ checks:
5247
certs:
5348
$(ROOT_DIR)/scripts/generate-certs.sh
5449

55-
.PHONY: workspace
56-
workspace: checks
57-
WORKSPACE=$(WORKSPACE) $(MAKE) -C eudcc-dev workspace
58-
WORKSPACE=$(WORKSPACE) $(MAKE) -C eudcc-eu workspace
59-
WORKSPACE=$(WORKSPACE) $(MAKE) -C eudcc-ie workspace
60-
6150
.PHONY: dev
6251
dev: checks
6352
$(MAKE) -C eudcc-dev terraform
@@ -72,7 +61,7 @@ ie: checks
7261
$(MAKE) -C eudcc-ie all
7362

7463
.PHONY: terraform
75-
terraform: workspace dev eu ie print-completion-msg
64+
terraform: dev eu ie print-completion-msg
7665

7766
.PHONY: terraform-destroy
7867
terraform-destroy: checks
@@ -103,3 +92,29 @@ print-hostnames:
10392
.PHONY: print-completion-msg
10493
print-completion-msg:
10594
@echo "$$COMPLETION_TEXT_BODY"
95+
96+
.PHONY: state-export
97+
state-export:
98+
@mkdir -p exports
99+
@mkdir -p exports/eudcc-dev
100+
@mkdir -p exports/eudcc-eu
101+
@mkdir -p exports/eudcc-ie
102+
@[[ -d certs ]] && rsync -avhW --no-compress --progress certs/ exports/certs/
103+
@[[ -f eudcc-dev/terraform.tfstate ]] && rsync -avhW --no-compress --progress eudcc-dev/terraform.tfstate exports/eudcc-dev/terraform.tfstate
104+
@[[ -f eudcc-eu/terraform.tfstate ]] && rsync -avhW --no-compress --progress eudcc-eu/terraform.tfstate exports/eudcc-eu/terraform.tfstate
105+
@[[ -f eudcc-ie/terraform.tfstate ]] && rsync -avhW --no-compress --progress eudcc-ie/terraform.tfstate exports/eudcc-ie/terraform.tfstate
106+
@[[ -f terraform.tfvars ]] && rsync -avhW --no-compress --progress terraform.tfvars exports/terraform.tfvars
107+
@zip -r exports.zip exports/
108+
@rm -rf exports/
109+
@echo "Export Complete!"
110+
111+
.PHONY: state-import
112+
state-import:
113+
@unzip import.zip
114+
@[[ -d import/certs ]] && rsync -avhW --no-compress --progress import/certs/ certs/
115+
@[[ -f import/eudcc-dev/terraform.tfstate ]] && rsync -avhW --no-compress --progress import/eudcc-dev/terraform.tfstate eudcc-dev/terraform.tfstate
116+
@[[ -f import/eudcc-eu/terraform.tfstate ]] && rsync -avhW --no-compress --progress import/eudcc-eu/terraform.tfstate eudcc-eu/terraform.tfstate
117+
@[[ -f import/eudcc-ie/terraform.tfstate ]] && rsync -avhW --no-compress --progress import/eudcc-ie/terraform.tfstate eudcc-ie/terraform.tfstate
118+
@[[ -f import/terraform.tfvars ]] && rsync -avhW --no-compress --progress import/terraform.tfvars terraform.tfvars
119+
@rm -rf import/
120+
@echo "Import Complete!"

‎docs/content/en/prerequisites/common.md

+24
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,27 @@ az feature show --namespace "<NAME_SPACE>" --name "<Feature_Flag>"
4141
```
4242

4343
Read about [setting up Azure DNS]({{< relref "azure-dns.md" >}}) in the next section.
44+
45+
### Terraform State Managment
46+
47+
This reference architecture uses Terraform's state store to manage the infrastructure and configuration lifecycle.
48+
49+
This state is used by Terraform to map real world resources to your configuration, keep track of metadata, and to improve performance for large infrastructures.
50+
51+
Ideally the state store should be stored and accessed remotely, but for simplicity for this blueprint Terraform's state store locally in files named `terraform.tfstate`.
52+
53+
#### Export Terraform State Store, Terraform Varable and Certs
54+
55+
Runing this command will generate a `export.zip` in the root on the project, while you can right click on and download if on Github Codespaces.
56+
57+
```bash
58+
$ make state-export
59+
```
60+
61+
#### Import Terraform State Store, Terraform Varable and Certs
62+
63+
Importing a zip file called `import.zip` in the root on the project.
64+
65+
```bash
66+
$ make state-import
67+
```

‎eudcc-dev/Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ SUB_ID = $(shell cat $(ROOT_DIR)/../terraform.tfvars| grep ^subscription_id | cu
55
.PHONY: all
66
all: terraform ssh-config
77

8-
.PHONY: workspace
9-
workspace:
10-
terraform init
11-
terraform workspace select $(WORKSPACE) || terraform workspace new $(WORKSPACE)
12-
138
.PHONY: terraform
149
terraform:
1510
terraform init

‎eudcc-dev/backend.tf

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
terraform {
2-
backend "azurerm" {
3-
storage_account_name = "eudgctfstate"
4-
container_name = "eudgc-dev"
5-
key = "terraform.tfstate"
2+
backend "local" {
63

7-
use_azuread_auth = true
84
}
9-
}
5+
}

‎eudcc-eu/Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ print-ssh-cmd:EU_RG = $(shell cat $(ROOT_DIR)/../eudcc-dev/jumpbox-ssh-configs/o
2525
print-ssh-cmd:
2626
@echo "az ssh vm --subscription $(SUB_ID) -g $(EU_RG) -n $(EU_RG)-jumpbox-vm"
2727

28-
.PHONY: workspace
29-
workspace:
30-
terraform init
31-
terraform workspace select $(WORKSPACE) || terraform workspace new $(WORKSPACE)
32-
3328
.PHONY: terraform
3429
terraform:
3530
find $(ROOT_DIR)/../charts/ -name \*.tgz -delete -or -name Chart.lock -delete

‎eudcc-eu/backend.tf

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
terraform {
2-
backend "azurerm" {
3-
storage_account_name = "eudgctfstate"
4-
container_name = "eudgc-eu"
5-
key = "terraform.tfstate"
6-
7-
use_azuread_auth = true
2+
backend "local" {
83
}
9-
}
4+
}

‎eudcc-eu/main.tf

+2-9
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@ provider "azurerm" {
66

77
# Load the Dev Env Remote State
88
data "terraform_remote_state" "dev" {
9-
backend = "azurerm"
10-
workspace = terraform.workspace
9+
backend = "local"
1110
config = {
12-
storage_account_name = "eudgctfstate"
13-
container_name = "eudgc-dev"
14-
key = "terraform.tfstate"
15-
16-
use_azuread_auth = true
17-
subscription_id = var.subscription_id
18-
tenant_id = var.tenant_id
11+
path = "../eudcc-dev/terraform.tfstate"
1912
}
2013
}
2114

‎eudcc-ie/Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ print-ssh-cmd:IE_RG = $(shell cat $(ROOT_DIR)/../eudcc-dev/jumpbox-ssh-configs/o
2525
print-ssh-cmd:
2626
@echo "az ssh vm --subscription $(SUB_ID) -g $(IE_RG) -n $(IE_RG)-jumpbox-vm"
2727

28-
.PHONY: workspace
29-
workspace:
30-
terraform init
31-
terraform workspace select $(WORKSPACE) || terraform workspace new $(WORKSPACE)
32-
3328
.PHONY: terraform
3429
terraform:
3530
find $(ROOT_DIR)/../charts/ -name \*.tgz -delete -or -name Chart.lock -delete

‎eudcc-ie/backend.tf

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
terraform {
2-
backend "azurerm" {
3-
storage_account_name = "eudgctfstate"
4-
container_name = "eudgc-ie"
5-
key = "terraform.tfstate"
6-
7-
use_azuread_auth = true
2+
backend "local" {
83
}
9-
}
4+
}

‎eudcc-ie/main.tf

+5-21
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,17 @@ provider "azuread" {
1010

1111
# Load the Dev Env Remote State
1212
data "terraform_remote_state" "dev" {
13-
backend = "azurerm"
14-
workspace = terraform.workspace
15-
13+
backend = "local"
1614
config = {
17-
storage_account_name = "eudgctfstate"
18-
container_name = "eudgc-dev"
19-
key = "terraform.tfstate"
20-
21-
use_azuread_auth = true
22-
subscription_id = var.subscription_id
23-
tenant_id = var.tenant_id
15+
path = "../eudcc-dev/terraform.tfstate"
2416
}
2517
}
2618

27-
# Load the EU Env Remote State
19+
# # Load the EU Env Remote State
2820
data "terraform_remote_state" "eu" {
29-
backend = "azurerm"
30-
workspace = terraform.workspace
31-
21+
backend = "local"
3222
config = {
33-
storage_account_name = "eudgctfstate"
34-
container_name = "eudgc-eu"
35-
key = "terraform.tfstate"
36-
37-
use_azuread_auth = true
38-
subscription_id = var.subscription_id
39-
tenant_id = var.tenant_id
23+
path = "../eudcc-eu/terraform.tfstate"
4024
}
4125
}
4226

0 commit comments

Comments
 (0)
This repository has been archived.