Skip to content

Commit f1f12d8

Browse files
authored
Merge pull request #1 from dragonflydb/tar/setup
feat(setup): add a helper script
2 parents 797fe2f + 40dc850 commit f1f12d8

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
# terraform-provider-dfcloud
1+
# terraform-provider-dfcloud
2+
3+
Run the setup script to download the provider into your local terraform folder:
4+
5+
```bash
6+
wget -qO- https://raw.githubusercontent.com/dragonflydb/terraform-provider-dfcloud/man/setup.sh | sh
7+
8+
# or
9+
10+
curl https://raw.githubusercontent.com/dragonflydb/terraform-provider-dfcloud/man/setup.sh | sh
11+
```

setup.sh

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/bash
2+
3+
# Configuration
4+
ORGANIZATION_NAME="dragonflydb"
5+
PROVIDER_NAME="terraform-provider-dfcloud"
6+
TF_PROVIDER_NAME="dfcloud"
7+
8+
# Fetch latest version from GitHub API
9+
VERSION=$(curl -s "https://api.github.com/repos/${ORGANIZATION_NAME}/${PROVIDER_NAME}/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/' | sed 's/^v//')
10+
if [ -z "$VERSION" ]; then
11+
echo "Error: Could not fetch latest version"
12+
exit 1
13+
fi
14+
echo "Latest version of the provider is: $VERSION"
15+
16+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
17+
ARCH=$(uname -m)
18+
19+
# Normalize OS name
20+
case "$OS" in
21+
linux)
22+
OS="linux"
23+
;;
24+
darwin)
25+
OS="darwin"
26+
;;
27+
*)
28+
echo "Unsupported OS: $OS"
29+
exit 1
30+
;;
31+
esac
32+
33+
# Normalize architecture name
34+
case "$ARCH" in
35+
x86_64)
36+
ARCH="amd64"
37+
;;
38+
arm64|aarch64)
39+
ARCH="arm64"
40+
;;
41+
*)
42+
echo "Unsupported architecture: $ARCH"
43+
exit 1
44+
;;
45+
esac
46+
47+
# Installation directories
48+
DEV_OVERRIDES_PATH="$HOME/bin"
49+
PLUGIN_DIR="$DEV_OVERRIDES_PATH"
50+
51+
# Create necessary directories
52+
mkdir -p "$PLUGIN_DIR"
53+
54+
# Download URL construction
55+
DOWNLOAD_URL="https://github.com/${ORGANIZATION_NAME}/${PROVIDER_NAME}/releases/download/v${VERSION}/${PROVIDER_NAME}_${VERSION}_${OS}_${ARCH}.zip"
56+
57+
# Download and extract
58+
echo "Downloading provider version ${VERSION} from: $DOWNLOAD_URL"
59+
curl -L "$DOWNLOAD_URL" -o "$PLUGIN_DIR/provider.zip"
60+
unzip -o "$PLUGIN_DIR/provider.zip" -d "$PLUGIN_DIR"
61+
rm "$PLUGIN_DIR/provider.zip"
62+
63+
# Ensure the binary is executable
64+
chmod +x "$PLUGIN_DIR/terraform-provider-${TF_PROVIDER_NAME}_v${VERSION}"
65+
66+
# Configure ~/.terraformrc with dev_overrides
67+
TERRAFORMRC="$HOME/.terraformrc"
68+
69+
# Backup existing ~/.terraformrc if it exists
70+
if [ -f "$TERRAFORMRC" ]; then
71+
echo "Backing up existing ~/.terraformrc to ~/.terraformrc.bak"
72+
cp "$TERRAFORMRC" "$TERRAFORMRC.bak"
73+
fi
74+
75+
echo "Updating ~/.terraformrc with dev_overrides"
76+
cat > "$TERRAFORMRC" <<EOF
77+
provider_installation {
78+
dev_overrides {
79+
"registry.terraform.io/${ORGANIZATION_NAME}/${TF_PROVIDER_NAME}" = "$DEV_OVERRIDES_PATH"
80+
}
81+
direct {}
82+
}
83+
EOF
84+
85+
echo "Provider downloaded and installed successfully in: $PLUGIN_DIR"

0 commit comments

Comments
 (0)