Skip to content

Commit 02705fc

Browse files
authored
Initial commit
0 parents  commit 02705fc

44 files changed

Lines changed: 8573 additions & 0 deletions

Some content is hidden

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

.devcontainer/.tool-versions.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"terraform": "1.14.1",
3+
"awscli": "2.15.0",
4+
"ansible": "latest",
5+
"terragrunt": "v0.57.4",
6+
"terrascan": "1.18.4",
7+
"tflint": "0.50.3",
8+
"tfsec": "1.28.5",
9+
"trivy": "0.51.1",
10+
"infracost": "0.10.30",
11+
"tfupdate": "0.8.1",
12+
"hcledit": "0.2.5",
13+
"nodejs": "20",
14+
"http-server": "14.1.1",
15+
"gcloud": "latest",
16+
"azurecli": "latest"
17+
}

.devcontainer/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM mcr.microsoft.com/devcontainers/base:ubuntu
2+
3+
COPY install-tools.sh /usr/local/bin/install-tools.sh
4+
5+
RUN chmod +x /usr/local/bin/install-tools.sh && /usr/local/bin/install-tools.sh --tools=all
6+
7+
RUN apt-get update && apt-get install -y \
8+
curl \
9+
unzip \
10+
git \
11+
jq \
12+
software-properties-common \
13+
gnupg \
14+
lsb-release \
15+
ca-certificates \
16+
&& rm -rf /var/lib/apt/lists/*

.devcontainer/devcontainer.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "Terraform Tools Dev Container",
3+
"build": {
4+
"dockerfile": "Dockerfile"
5+
},
6+
"remoteEnv": {
7+
"AWS_ACCESS_KEY_ID": "${localEnv:AWS_ACCESS_KEY_ID}",
8+
"AWS_SECRET_ACCESS_KEY": "${localEnv:AWS_SECRET_ACCESS_KEY}",
9+
"AWS_DEFAULT_REGION": "${localEnv:AWS_DEFAULT_REGION}",
10+
"TERRAFORM_SA_KEY": "${localEnv:TERRAFORM_SA_KEY}"
11+
},
12+
"postCreateCommand": "/usr/local/bin/install-tools.sh --tools=all > /tmp/post-create.log 2>&1",
13+
"postStartCommand": "bash .devcontainer/write-tf-sa-key.sh > /tmp/devcontainer-poststart.log 2>&1 || true",
14+
"customizations": {
15+
"vscode": {
16+
"extensions": [
17+
"hashicorp.terraform",
18+
"ms-azuretools.vscode-docker",
19+
"GitHub.copilot",
20+
"ms-python.python",
21+
"mechatroner.rainbow-csv",
22+
"vscode.json-language-features",
23+
"ms-vscode.vscode-node-azure-pack"
24+
],
25+
"settings": {
26+
"terminal.integrated.defaultProfile.linux": "bash"
27+
}
28+
}
29+
},
30+
"features": {
31+
"ghcr.io/devcontainers/features/go:1": {
32+
"version": "1.21"
33+
}
34+
}
35+
}

.devcontainer/install-tools.sh

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
LOG_FILE="install-tools.log"
5+
SUMMARY_FILE="${SUMMARY_FILE:-install-summary.json}"
6+
VERSIONS_FILE="${VERSIONS_FILE:-.devcontainer/.tool-versions.json}"
7+
DRY_RUN=false
8+
INSTALL_TOOLS=(all)
9+
10+
for arg in "$@"; do
11+
case $arg in
12+
--dry-run)
13+
DRY_RUN=true
14+
echo "[Dry Run] No changes will be made. Commands will be printed only."
15+
;;
16+
--tools=*)
17+
IFS=',' read -ra INSTALL_TOOLS <<< "${arg#*=}"
18+
;;
19+
--summary-path=*)
20+
SUMMARY_FILE="${arg#*=}"
21+
;;
22+
esac
23+
done
24+
25+
exec > >(tee -a "$LOG_FILE") 2>&1
26+
27+
RED='\033[0;31m'
28+
GREEN='\033[0;32m'
29+
YELLOW='\033[1;33m'
30+
NC='\033[0m'
31+
32+
SUMMARY_JSON="{}"
33+
EXPECTED_JSON="{}"
34+
35+
if [[ -f "$VERSIONS_FILE" ]]; then
36+
EXPECTED_JSON=$(<"$VERSIONS_FILE")
37+
fi
38+
39+
log_step() {
40+
echo -e "\n${YELLOW}🔧 $(date '+%Y-%m-%d %H:%M:%S') - $1${NC}"
41+
}
42+
43+
run_cmd() {
44+
log_step "$1"
45+
shift
46+
if $DRY_RUN; then
47+
echo "[Dry Run] $*"
48+
else
49+
if "$@"; then
50+
echo -e "${GREEN}✅ Success: $1${NC}"
51+
else
52+
echo -e "${RED}❌ Failed: $1${NC}"
53+
exit 1
54+
fi
55+
fi
56+
}
57+
58+
add_summary() {
59+
local name=$1
60+
local version=$2
61+
SUMMARY_JSON=$(echo "$SUMMARY_JSON" | jq --arg name "$name" --arg ver "$version" '. + {($name): $ver}')
62+
63+
local expected_version
64+
expected_version=$(echo "$EXPECTED_JSON" | jq -r --arg name "$name" '.[$name] // empty')
65+
66+
if [[ -n "$expected_version" && "$version" != "$expected_version" ]]; then
67+
echo -e "${RED}⚠️ Version mismatch for $name: expected $expected_version, got $version${NC}"
68+
fi
69+
}
70+
71+
get_expected_version() {
72+
local name=$1
73+
echo "$EXPECTED_JSON" | jq -r --arg name "$name" '.[$name] // empty'
74+
}
75+
76+
should_run() {
77+
[[ " ${INSTALL_TOOLS[*]} " =~ " all " || " ${INSTALL_TOOLS[*]} " =~ " $1 " ]]
78+
}
79+
80+
# OS dependencies
81+
log_step "Installing OS dependencies"
82+
run_cmd "Install OS dependencies" sudo apt-get update -y && sudo apt-get install -y \
83+
curl unzip git jq gnupg software-properties-common ca-certificates lsb-release tar build-essential apt-transport-https
84+
85+
# Terraform (manual installation)
86+
if should_run terraform; then
87+
log_step "Installing Terraform"
88+
version=$(get_expected_version terraform)
89+
version="${version:-1.8.4}"
90+
91+
if ! $DRY_RUN; then
92+
run_cmd "Download Terraform" curl -sLo terraform.zip "https://releases.hashicorp.com/terraform/${version}/terraform_${version}_linux_amd64.zip"
93+
run_cmd "Unzip Terraform" unzip -o terraform.zip
94+
run_cmd "Move Terraform" sudo mv terraform /usr/local/bin/
95+
rm -f terraform.zip
96+
fi
97+
98+
TERRAFORM_VERSION=$(terraform version -json | jq -r .terraform_version)
99+
add_summary terraform "$TERRAFORM_VERSION"
100+
fi
101+
102+
# AWS CLI
103+
if should_run awscli; then
104+
log_step "Installing AWS CLI"
105+
run_cmd "Download AWS CLI" curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
106+
run_cmd "Unzip AWS CLI" unzip -o awscliv2.zip
107+
run_cmd "Install AWS CLI" sudo ./aws/install --update
108+
rm -rf awscliv2.zip aws
109+
AWS_VERSION=$(aws --version 2>&1 | awk '{print $1}' | cut -d/ -f2)
110+
add_summary awscli "$AWS_VERSION"
111+
fi
112+
113+
# Ansible
114+
if should_run ansible; then
115+
log_step "Installing Ansible"
116+
version=$(get_expected_version ansible)
117+
118+
if ! $DRY_RUN; then
119+
run_cmd "Update apt" sudo apt-get update -y
120+
run_cmd "Install Python pip" sudo apt-get install -y python3-pip
121+
if [[ -n "$version" && "$version" != "latest" ]]; then
122+
run_cmd "Install Ansible" sudo pip3 install --break-system-packages "ansible==${version}"
123+
else
124+
run_cmd "Install Ansible" sudo pip3 install --break-system-packages ansible
125+
fi
126+
fi
127+
128+
ANSIBLE_VERSION=$(ansible --version 2>/dev/null | head -n1 | awk '{print $2}' | tr -d '[]' || echo "installed")
129+
add_summary ansible "$ANSIBLE_VERSION"
130+
fi
131+
132+
# Node.js
133+
if should_run nodejs; then
134+
log_step "Installing Node.js"
135+
136+
if ! $DRY_RUN; then
137+
# Check if nodejs is already installed from base image
138+
if command -v node &> /dev/null; then
139+
log_step "Node.js already installed, ensuring npm is available"
140+
# Install npm separately if nodejs exists but npm doesn't
141+
if ! command -v npm &> /dev/null; then
142+
run_cmd "Install npm" sudo apt-get update && sudo apt-get install -y npm
143+
fi
144+
else
145+
# Fresh installation from NodeSource
146+
version=$(get_expected_version nodejs)
147+
version="${version:-20}"
148+
run_cmd "Download NodeSource setup script" curl -fsSL https://deb.nodesource.com/setup_${version}.x -o nodesource_setup.sh
149+
run_cmd "Run NodeSource setup" sudo -E bash nodesource_setup.sh
150+
run_cmd "Install Node.js and npm" sudo apt-get install -y nodejs
151+
rm -f nodesource_setup.sh
152+
fi
153+
fi
154+
155+
NODE_VERSION=$(node -v 2>/dev/null | sed 's/v//')
156+
NPM_VERSION=$(npm -v 2>/dev/null || echo "not installed")
157+
add_summary nodejs "$NODE_VERSION"
158+
add_summary npm "$NPM_VERSION"
159+
fi
160+
161+
# http-server (npm package)
162+
if should_run http-server; then
163+
log_step "Installing http-server"
164+
run_cmd "Install http-server globally" sudo npm install -g http-server
165+
HTTPSERVER_VERSION=$(http-server --version 2>/dev/null || echo "installed")
166+
add_summary http-server "$HTTPSERVER_VERSION"
167+
fi
168+
169+
# Google Cloud SDK
170+
if should_run gcloud; then
171+
log_step "Installing Google Cloud SDK"
172+
173+
if ! $DRY_RUN; then
174+
log_step "Add gcloud apt key"
175+
curl -fsSL https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --yes --dearmor -o /usr/share/keyrings/cloud.google.gpg
176+
echo -e "${GREEN}✅ Success: Add gcloud apt key${NC}"
177+
log_step "Add gcloud repository"
178+
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list > /dev/null
179+
echo -e "${GREEN}✅ Success: Add gcloud repository${NC}"
180+
run_cmd "Update apt" sudo apt-get update -y
181+
run_cmd "Install gcloud" sudo apt-get install -y google-cloud-cli
182+
fi
183+
184+
GCLOUD_VERSION=$(gcloud version --format="value(version)" 2>/dev/null || echo "installed")
185+
add_summary gcloud "$GCLOUD_VERSION"
186+
fi
187+
188+
# Azure CLI
189+
if should_run azurecli; then
190+
log_step "Installing Azure CLI"
191+
192+
if ! $DRY_RUN; then
193+
run_cmd "Install Azure CLI dependencies" sudo apt-get update && sudo apt-get install -y ca-certificates curl apt-transport-https lsb-release gnupg
194+
log_step "Download Microsoft signing key"
195+
curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --yes --dearmor -o /etc/apt/keyrings/microsoft.gpg
196+
echo -e "${GREEN}✅ Success: Download Microsoft signing key${NC}"
197+
run_cmd "Set key permissions" sudo chmod go+r /etc/apt/keyrings/microsoft.gpg
198+
log_step "Add Azure CLI repository"
199+
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/microsoft.gpg] https://packages.microsoft.com/repos/azure-cli/ $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/azure-cli.list > /dev/null
200+
echo -e "${GREEN}✅ Success: Add Azure CLI repository${NC}"
201+
run_cmd "Update apt" sudo apt-get update -y
202+
run_cmd "Install Azure CLI" sudo apt-get install -y azure-cli
203+
fi
204+
205+
AZCLI_VERSION=$(az version --output json 2>/dev/null | jq -r '."azure-cli"' || echo "installed")
206+
add_summary azurecli "$AZCLI_VERSION"
207+
fi
208+
209+
# Write summary
210+
if ! $DRY_RUN; then
211+
echo "$SUMMARY_JSON" | jq . > "$SUMMARY_FILE"
212+
echo -e "\n${GREEN}📦 Tool summary written to $SUMMARY_FILE${NC}"
213+
fi
214+
215+
echo -e "\n${GREEN}✅ All tools installed successfully at $(date '+%Y-%m-%d %H:%M:%S')${NC}"

.devcontainer/write-tf-sa-key.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Write TERRAFORM_SA_KEY into the repository relative path tf/tf-sa-key/terraform-sa-key.json
5+
# The script assumes it's run from the repository root (devcontainer postStartCommand does this).
6+
7+
LOG="/tmp/devcontainer-poststart.log"
8+
TARGET_DIR="$(pwd)/infra/gcp/tf/tf-sa-key"
9+
TARGET_FILE="$TARGET_DIR/terraform-sa-key.json"
10+
11+
echo "$(date -Is) - write-tf-sa-key.sh starting" >> "$LOG"
12+
mkdir -p "$TARGET_DIR"
13+
14+
if [ -n "${TERRAFORM_SA_KEY:-}" ]; then
15+
printf '%s' "$TERRAFORM_SA_KEY" > "$TARGET_FILE"
16+
chmod 600 "$TARGET_FILE"
17+
echo "$(date -Is) - Wrote $TARGET_FILE (permissions 600)" >> "$LOG"
18+
else
19+
echo "$(date -Is) - TERRAFORM_SA_KEY not set; skipping creation of $TARGET_FILE" >> "$LOG"
20+
fi
21+
22+
echo "$(date -Is) - write-tf-sa-key.sh finished" >> "$LOG"
23+
24+
exit 0

.editorconfig

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# EditorConfig is awesome: http://EditorConfig.org
2+
# Uses editorconfig to maintain consistent coding styles
3+
4+
# top-most EditorConfig file
5+
root = true
6+
7+
# Unix-style newlines with a newline ending every file
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_size = 2
12+
indent_style = space
13+
insert_final_newline = true
14+
max_line_length = 80
15+
trim_trailing_whitespace = true
16+
17+
[*.{tf,tfvars}]
18+
indent_size = 2
19+
indent_style = space
20+
21+
[*.md]
22+
max_line_length = 0
23+
trim_trailing_whitespace = false
24+
25+
[Makefile]
26+
tab_width = 2
27+
indent_style = tab
28+
29+
[COMMIT_EDITMSG]
30+
max_line_length = 0

.github/dependabot.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: 2
2+
updates:
3+
# 1. GitHub Actions
4+
- package-ecosystem: "github-actions"
5+
directory: "/" # Location of your GitHub workflows
6+
schedule:
7+
interval: "weekly"
8+
day: "monday"
9+
time: "04:00"
10+
open-pull-requests-limit: 5
11+
12+
# 2. JavaScript / Node.js (npm/yarn)
13+
- package-ecosystem: "npm"
14+
directory: "/" # Location of package.json
15+
schedule:
16+
interval: "weekly"
17+
day: "monday"
18+
time: "04:00"
19+
open-pull-requests-limit: 5
20+
commit-message:
21+
prefix: "chore"
22+
include: "scope"

0 commit comments

Comments
 (0)