-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path04.intentions.consul.sh
executable file
·131 lines (106 loc) · 3.1 KB
/
04.intentions.consul.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env bash
#-------------------------------------------------------------------------------
# Script Variables
#-------------------------------------------------------------------------------
_COL='\033[1;32m'
_ERR='\033[0;31m'
_NC='\033[0m' # No
echo -e "${_COL}Configure environment.${_NC}"
source ../../aws/datacenter.env
export CONSUL_CACERT="../../aws/certs/datacenter_ca.cert"
export NOMAD_CACERT="../../aws/certs/datacenter_ca.cert"
## Configuration file destinations
_int_DB_FILE="/tmp/intention-db.hcl"
_int_PROD_API_FILE="/tmp/intention-product_api.hcl"
_int_PAY_API_FILE="/tmp/intention-payments_api.hcl"
_int_PUB_API_FILE="/tmp/intention-public_api.hcl"
_int_FE_FILE="/tmp/intention-frontend.hcl"
_int_NGINX_FILE="/tmp/intention-nginx.hcl"
_int_API_GW_FILE="/tmp/intention-api_gateway.hcl"
#-------------------------------------------------------------------------------
# Clean previous configurations
#-------------------------------------------------------------------------------
echo -e "${_COL}Clean previous configurations.${_NC}"
consul config delete -kind service-intentions -name database
consul config delete -kind service-intentions -name product-api
consul config delete -kind service-intentions -name payments-api
consul config delete -kind service-intentions -name public-api
consul config delete -kind service-intentions -name frontend
consul config delete -kind service-intentions -name nginx
if [ "$1 " == "-clean " ]; then
echo -e "${_ERR}Only cleaning selected...Exiting.${_NC}"
exit 0
fi
### ----------------------------------------------------------------------------
### Configure Consul Intentions
### ----------------------------------------------------------------------------
# References:
# - https://developer.hashicorp.com/consul/docs/connect/config-entries/service-intentions
echo -e "${_COL}Create Consul intentions for Hashicups and API Gateway${_NC}"
tee ${_int_DB_FILE} > /dev/null << EOF
Kind = "service-intentions"
Name = "database"
Sources = [
{
Name = "product-api"
Action = "allow"
}
]
EOF
tee ${_int_PROD_API_FILE} > /dev/null << EOF
Kind = "service-intentions"
Name = "product-api"
Sources = [
{
Name = "public-api"
Action = "allow"
}
]
EOF
tee ${_int_PAY_API_FILE} > /dev/null << EOF
Kind = "service-intentions"
Name = "payments-api"
Sources = [
{
Name = "public-api"
Action = "allow"
}
]
EOF
tee ${_int_PUB_API_FILE} > /dev/null << EOF
Kind = "service-intentions"
Name = "public-api"
Sources = [
{
Name = "nginx"
Action = "allow"
}
]
EOF
tee ${_int_FE_FILE} > /dev/null << EOF
Kind = "service-intentions"
Name = "frontend"
Sources = [
{
Name = "nginx"
Action = "allow"
}
]
EOF
tee ${_int_NGINX_FILE} > /dev/null << EOF
Kind = "service-intentions"
Name = "nginx"
Sources = [
{
Name = "api-gateway"
Action = "allow"
}
]
EOF
consul config write ${_int_DB_FILE}
consul config write ${_int_PROD_API_FILE}
consul config write ${_int_PAY_API_FILE}
consul config write ${_int_PUB_API_FILE}
consul config write ${_int_FE_FILE}
consul config write ${_int_NGINX_FILE}
# consul config write ${_int_API_GW_FILE}