Skip to content

Commit a02cc1b

Browse files
committed
Refactoring terraform provisioning infra
1 parent e888ff1 commit a02cc1b

File tree

147 files changed

+44471
-564
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+44471
-564
lines changed

terraform/environment/providers/aws/infra/resources/ec2/jumphost/ec2-jumphost.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ resource "aws_instance" "jumphost" {
8383

8484
root_block_device {
8585
volume_size = "30"
86-
volume_type = "gp2"
86+
volume_type = "gp3"
8787
delete_on_termination = true
8888
encrypted = true
8989
kms_key_id = data.aws_kms_key.cmk_key.arn

terraform/environment/providers/aws/infra/resources/ec2/psql/ec2-psql.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ resource "aws_instance" "psql" {
7575

7676
root_block_device {
7777
volume_size = "30"
78-
volume_type = "gp2"
78+
volume_type = "gp3"
7979
delete_on_termination = true
8080
encrypted = true
8181
kms_key_id = data.aws_kms_key.cmk_key.arn

terraform/environment/providers/aws/infra/resources/ec2/psql/userdata/amazon-linux.sh

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ wget -O terraform_${TERRAFORM_VERSION}_linux_amd64.zip \
5656
rm -f packer_${PACKER_VERSION}_linux_amd64.zip
5757

5858
python3 -m pip install pip==21.3.1 &&
59-
pip3 install --upgrade pip cffi awscli &&
59+
pip3 install --upgrade pip cffi &&
6060
# install ansible
6161
pip3 install --no-cache-dir ansible-core==${ANSIBLE_VERSION} \
6262
ansible-tower-cli==3.3.4 \
@@ -65,22 +65,22 @@ python3 -m pip install pip==21.3.1 &&
6565
httplib2 \
6666
six \
6767
requests \
68-
boto3 \
69-
awscli
68+
boto3
7069

7170
## install tfenv
72-
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
73-
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >>~/.bash_profile
74-
ln -sf ~/.tfenv/bin/* /usr/local/bin
75-
mkdir -p ~/.local/bin/
76-
. ~/.profile
77-
ln -sf ~/.tfenv/bin/* ~/.local/bin
71+
git clone https://github.com/tfutils/tfenv.git $HOME/.tfenv
72+
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> $HOME/.bash_profile
73+
sudo ln -sf $HOME/.tfenv/bin/* /usr/local/bin
74+
sudo mkdir -p $HOME/.local/bin/
75+
. $HOME/.profile
76+
ln -sf $HOME/.tfenv/bin/* $HOME/.local/bin
7877

79-
##### CUSTOMIZE ~/.profile #####
80-
echo '' >>~/.profile
78+
##### CUSTOMIZE $HOME/.profile #####
79+
touch $HOME/.profile
80+
echo '' >> $HOME/.profile
8181
echo '### Docker ###
8282
export DOCKER_CLIENT_TIMEOUT=300
83-
export COMPOSE_HTTP_TIMEOUT=300' >>~/.profile
83+
export COMPOSE_HTTP_TIMEOUT=300' >> $HOME/.profile
8484

8585
##### CONFIGURE DOCKER #####
8686
sudo usermod -a -G docker ec2-user
@@ -94,9 +94,10 @@ chmod +x ./install
9494
./install auto
9595

9696
## Set Locale
97-
sudo echo 'LANG=en_US.utf-8' >>/etc/environment
98-
sudo echo 'LC_ALL=en_US.utf-8' >>/etc/environment
97+
sudo touch /etc/environment
98+
sudo echo 'LANG=en_US.utf-8' >> /etc/environment
99+
sudo echo 'LC_ALL=en_US.utf-8' >> /etc/environment
99100

100101
## Adding Custom Sysctl
101-
sudo echo 'vm.max_map_count=524288' >>/etc/sysctl.conf
102-
sudo echo 'fs.file-max=131072' >>/etc/sysctl.conf
102+
sudo echo 'vm.max_map_count=524288' >> /etc/sysctl.conf
103+
sudo echo 'fs.file-max=131072' >> /etc/sysctl.conf

terraform/environment/providers/aws/infra/resources/ec2/psql/userdata/ubuntu.sh

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ sudo apt-get install -y \
8181
rm -f packer_${PACKER_VERSION}_linux_amd64.zip
8282

8383
python3 -m pip install pip==21.3.1 &&
84-
pip3 install --upgrade pip cffi awscli &&
84+
pip3 install --upgrade pip cffi &&
8585
# install ansible
8686
pip3 install --no-cache-dir ansible-core==${ANSIBLE_VERSION} \
8787
ansible-tower-cli==3.3.4 \
@@ -95,22 +95,23 @@ python3 -m pip install pip==21.3.1 &&
9595
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10
9696

9797
## install tfenv
98-
git clone https://github.com/tfutils/tfenv.git ~/.tfenv
99-
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >>~/.bash_profile
100-
ln -sf ~/.tfenv/bin/* /usr/local/bin
101-
mkdir -p ~/.local/bin/
102-
. ~/.profile
103-
ln -sf ~/.tfenv/bin/* ~/.local/bin
98+
git clone https://github.com/tfutils/tfenv.git $HOME/.tfenv
99+
echo 'export PATH="$HOME/.tfenv/bin:$PATH"' >> $HOME/.bash_profile
100+
ln -sf $HOME/.tfenv/bin/* /usr/local/bin
101+
sudo mkdir -p $HOME/.local/bin/
102+
. $HOME/.profile
103+
ln -sf $HOME/.tfenv/bin/* $HOME/.local/bin
104104

105105
# Cleanup Cache
106106
sudo apt-get clean &&
107107
sudo apt-get autoremove -y
108108

109-
##### CUSTOMIZE ~/.profile #####
110-
echo '' >>~/.profile
109+
##### CUSTOMIZE $HOME/.profile #####
110+
touch $HOME/.profile
111+
echo '' >> $HOME/.profile
111112
echo '### Docker ###
112113
export DOCKER_CLIENT_TIMEOUT=300
113-
export COMPOSE_HTTP_TIMEOUT=300' >>~/.profile
114+
export COMPOSE_HTTP_TIMEOUT=300' >> $HOME/.profile
114115

115116
##### CONFIGURE DOCKER #####
116117
sudo usermod -a -G docker ubuntu
@@ -124,9 +125,10 @@ chmod +x ./install
124125
./install auto
125126

126127
## Set Locale
127-
sudo echo 'LANG=en_US.utf-8' >>/etc/environment
128-
sudo echo 'LC_ALL=en_US.utf-8' >>/etc/environment
128+
sudo touch /etc/environment
129+
sudo echo 'LANG=en_US.utf-8' >> /etc/environment
130+
sudo echo 'LC_ALL=en_US.utf-8' >> /etc/environment
129131

130132
## Adding Custom Sysctl
131-
sudo echo 'vm.max_map_count=524288' >>/etc/sysctl.conf
132-
sudo echo 'fs.file-max=131072' >>/etc/sysctl.conf
133+
sudo echo 'vm.max_map_count=524288' >> /etc/sysctl.conf
134+
sudo echo 'fs.file-max=131072' >> /etc/sysctl.conf

terraform/environment/providers/aws/infra/resources/eks-adot-collector/iam.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ resource "aws_iam_role_policy_attachment" "adot_collector_xray" {
3838
resource "aws_iam_role_policy_attachment" "adot_collector_cloudwatch" {
3939
policy_arn = "arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy"
4040
role = aws_iam_role.adot_collector.name
41-
}
41+
}
42+
43+
resource "aws_iam_role_policy_attachment" "adot_collector_cloudwatch_logs" {
44+
policy_arn = "arn:aws:iam::aws:policy/AWSOpsWorksCloudWatchLogs"
45+
role = aws_iam_role.adot_collector.name
46+
}

terraform/environment/providers/aws/infra/resources/eks-adot-collector/manifest/addons-otel-permissions.yaml

100644100755
File mode changed.

terraform/environment/providers/aws/infra/resources/eks-adot-collector/manifest/addons-otel.yml renamed to terraform/environment/providers/aws/infra/resources/eks-adot-collector/manifest/addons-otel.yaml

File renamed without changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: adot-collector
5+
namespace: observability
6+
spec:
7+
type: NodePort
8+
selector:
9+
app: adot-collector-daemonset
10+
ports:
11+
- name: http
12+
port: 8888
13+
targetPort: 8888

terraform/environment/providers/aws/infra/resources/eks-adot-collector/manifest/eksctl-adot-collector.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ eksctl create iamserviceaccount \
2020
--attach-policy-arn arn:aws:iam::aws:policy/AmazonPrometheusRemoteWriteAccess \
2121
--attach-policy-arn arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess \
2222
--attach-policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy \
23+
--attach-policy-arn arn:aws:iam::aws:policy/AWSOpsWorksCloudWatchLogs \
2324
--approve \
2425
--override-existing-serviceaccounts
2526

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/sh
2+
3+
export AWS_REGION="us-west-2"
4+
export ACCOUNT_ID="YOUR_AWS_ACCOUNT"
5+
export EKS_CLUSTER="devopscorner-prod"
6+
export EKS_VPC_ID="vpc-0987612345"
7+
8+
cat <<EOF > adot-collector-service.yaml
9+
apiVersion: v1
10+
kind: Service
11+
metadata:
12+
name: adot-collector
13+
namespace: observability
14+
spec:
15+
type: NodePort
16+
selector:
17+
app: adot-collector-daemonset
18+
ports:
19+
- name: http
20+
port: 8888
21+
targetPort: 8888
22+
EOF
23+
24+
cat <<EOF > ingress-nginx-adot-collector.yaml
25+
apiVersion: networking.k8s.io/v1
26+
kind: Ingress
27+
metadata:
28+
name: adot-collector
29+
namespace: observability
30+
annotations:
31+
ingress.kubernetes.io/whitelist-source-range: 32.0.0.0/32
32+
meta.helm.sh/release-name: adot-collector
33+
meta.helm.sh/release-namespace: observability
34+
kubernetes.io/ingress.class: nginx
35+
nginx.ingress.kubernetes.io/affinity: cookie
36+
nginx.ingress.kubernetes.io/cors-allow-headers: '*'
37+
nginx.ingress.kubernetes.io/cors-allow-methods: '*'
38+
nginx.ingress.kubernetes.io/cors-allow-origin: '*'
39+
nginx.ingress.kubernetes.io/enable-cors: 'true'
40+
nginx.ingress.kubernetes.io/from-to-www-redirect: 'true'
41+
spec:
42+
rules:
43+
- host: adot-collector.observability.svc.cluster.local
44+
http:
45+
paths:
46+
- path: /
47+
pathType: Prefix # Prefix -or - ImplementationSpecific
48+
backend:
49+
service:
50+
name: adot-collector
51+
port:
52+
number: 8888
53+
54+
tls:
55+
- hosts:
56+
- adot-collector.observability.svc.cluster.local
57+
EOF
58+
59+
kubectl config use-context arn:aws:eks:${AWS_REGION}:${ACCOUNT_ID}:cluster/${EKS_CLUSTER}
60+
kubectl -f adot-collector-service.yaml apply
61+
kubectl -f ingress-nginx-adot-collector.yaml apply

0 commit comments

Comments
 (0)