Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"name": "Terraform Provider GitHubx",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",

"features": {
"ghcr.io/devcontainers/features/git:1": {},
"ghcr.io/devcontainers/features/github-cli:1": {},
"ghcr.io/devcontainers/features/go:1": {},
"ghcr.io/devcontainers/features/terraform:1": {}
},

"customizations": {
"vscode": {
"extensions": [
"davidanson.vscode-markdownlint",
"golang.go",
"hashicorp.terraform",
"Gruntfuggly.todo-tree",
"ms-azuretools.vscode-docker",
"vscode-icons-team.vscode-icons",
"ms-vscode.makefile-tools"
],
"settings": {
"workbench.iconTheme": "vscode-icons",
"go.useLanguageServer": true,
"go.formatTool": "goimports",
"go.lintTool": "golangci-lint",
"go.lintOnSave": "package",
"[go]": {
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"[terraform]": {
"editor.formatOnSave": true
},
"terraform.format.enable": true,
"terraform.languageServer.enable": true
}
}
},

"postCreateCommand": ".devcontainer/scripts/postCreate.sh",

"remoteUser": "root",

"mounts": [
"source=${localEnv:HOME}/.config/gh,target=/root/.config/gh,type=bind,consistency=cached"
]
}
207 changes: 207 additions & 0 deletions .devcontainer/scripts/postCreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
#!/bin/bash
# Don't use set -e to allow script to continue even if some steps fail
# set -e

export DEBIAN_FRONTEND=noninteractive
export GIT_TERMINAL_PROMPT=0

# Ensure we're running as root (no sudo needed)
if [ "$(id -u)" -ne 0 ]; then
echo "⚠️ Warning: Not running as root. Some operations may fail."
fi

echo "🚀 Setting up Terraform Provider GitHubx development environment..."

# Install bash-completion if not already installed
if ! command -v bash-completion &> /dev/null && [ ! -f /usr/share/bash-completion/bash_completion ]; then
echo "📦 Installing bash-completion..."
apt-get update -y && apt-get install -y bash-completion && rm -rf /var/lib/apt/lists/*
fi

# Setup bashrc with aliases and history settings
echo "⚙️ Configuring bash environment..."
cat >> /root/.bashrc << 'BASHRC_EOF'

# Devcontainer bashrc configuration
# History and completion settings

# Enable arrow key history navigation
set -o emacs
bind "\e[A": history-search-backward
bind "\e[B": history-search-forward

# History settings
HISTCONTROL=ignoredups:erasedups
HISTSIZE=10000
HISTFILESIZE=20000
shopt -s histappend

# Save and reload history after each command
PROMPT_COMMAND="history -a; history -c; history -r; $PROMPT_COMMAND"

# Enable bash completion
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi

# Additional useful aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'

# Git aliases
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline --graph --decorate'

# Terraform aliases
alias tf='terraform'
alias tfi='terraform init'
alias tfa='terraform apply'
alias tfaa='terraform apply -auto-approve'
alias tfp='terraform plan'
alias tfd='terraform destroy'
alias tfda='terraform destroy -auto-approve'

alias rmtl='rm -rf .terraform.lock.hcl'

BASHRC_EOF
echo "✅ Bash environment configured"

# Display system information
echo "📋 System Information:"
uname -a
if command -v go &> /dev/null; then
echo "Go version: $(go version)"
echo "Go path: $(go env GOPATH)"
else
echo "⚠️ Go not found - will be installed by devcontainer feature"
fi

# Verify Terraform installation
echo "🔧 Verifying Terraform..."
if command -v terraform &> /dev/null; then
echo "✅ Terraform installed: $(terraform version)"
else
echo "⚠️ Terraform not found - will be installed by devcontainer feature"
fi

# Setup GitHub CLI authentication from host OS
echo "🔧 Setting up GitHub CLI authentication..."
if command -v gh &> /dev/null; then
echo "✅ GitHub CLI installed: $(gh --version | head -n 1)"

# Ensure the config directory exists
GH_CONFIG_DIR="/root/.config/gh"
mkdir -p "${GH_CONFIG_DIR}"

# Check if host config is mounted (from devcontainer mount)
# The devcontainer.json should mount ${localEnv:HOME}/.config/gh to /root/.config/gh
if [ -d "${GH_CONFIG_DIR}" ] && [ -n "$(ls -A ${GH_CONFIG_DIR} 2>/dev/null)" ]; then
echo "📁 Found mounted GitHub CLI config from host OS"
# Ensure proper permissions (config files should be readable)
chmod -R u+rw "${GH_CONFIG_DIR}" 2>/dev/null || true
find "${GH_CONFIG_DIR}" -type f -name "*.yaml" -exec chmod 600 {} \; 2>/dev/null || true

# Verify authentication
if gh auth status &> /dev/null; then
echo "✅ GitHub CLI is authenticated (using host OS auth)"
gh auth status 2>&1 | head -n 3 || true
else
echo "⚠️ GitHub CLI config found but not authenticated."
echo " Please run 'gh auth login' on your host OS to authenticate."
fi
else
echo "⚠️ GitHub CLI config not found at ${GH_CONFIG_DIR}"
echo " The devcontainer should mount your host's ~/.config/gh directory."
echo " If the mount failed, ensure you have authenticated with 'gh auth login' on your host OS."
echo " You can also run 'gh auth login' inside the container, but it won't persist across rebuilds."

# Check if auth works anyway (might be using a different method)
if gh auth status &> /dev/null; then
echo "✅ GitHub CLI is authenticated (using alternative method)"
gh auth status 2>&1 | head -n 3 || true
fi
fi
else
echo "⚠️ GitHub CLI not found"
fi

# Install Terraform Plugin Framework docs generator
echo "📚 Installing Terraform Plugin Framework documentation generator..."
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@latest || echo "⚠️ Failed to install tfplugindocs (may retry later)"

# Verify Go tools (non-blocking, may not be installed yet)
echo "🔧 Verifying Go tools..."
command -v golangci-lint >/dev/null && echo "golangci-lint: $(golangci-lint version)" || echo "⚠️ golangci-lint not found"
command -v goimports >/dev/null && echo "goimports: $(which goimports)" || echo "⚠️ goimports not found"
command -v gopls >/dev/null && echo "gopls: $(which gopls)" || echo "⚠️ gopls not found"

# Download Go dependencies
echo "📥 Downloading Go dependencies..."
cd /workspaces/terraform-provider-githubx || cd /workspace
go mod download || echo "⚠️ Go mod download failed (may retry later)"
go mod verify || echo "⚠️ Go mod verify failed"

# Build the provider to verify everything works
echo "🔨 Building provider..."
go build -buildvcs=false -o terraform-provider-githubx || echo "⚠️ Build failed (may retry later)"

# Install provider locally for Terraform to use (only if build succeeded)
echo "📦 Installing provider locally for Terraform..."
if [ -f terraform-provider-githubx ]; then
VERSION="0.1.0"
PLATFORM="linux_amd64"
PLUGIN_DIR="${HOME}/.terraform.d/plugins/registry.terraform.io/tfstack/githubx/${VERSION}/${PLATFORM}"
mkdir -p "${PLUGIN_DIR}"
cp terraform-provider-githubx "${PLUGIN_DIR}/" && echo "✅ Provider installed to ${PLUGIN_DIR}" || echo "⚠️ Failed to install provider"
else
echo "⚠️ Provider binary not found, skipping installation"
fi

# Initialize Terraform in examples (non-blocking, may fail if variables needed)
echo "🔧 Initializing Terraform examples..."
for dir in examples/data-sources/*/ examples/resources/*/ examples/provider/; do
if [ -f "${dir}data-source.tf" ] || [ -f "${dir}resource.tf" ] || [ -f "${dir}provider.tf" ] || [ -f "${dir}main.tf" ] || [ -f "${dir}"*.tf ]; then
echo " Initializing ${dir}..."
(cd "${dir}" && terraform init -upgrade -input=false > /dev/null 2>&1 && echo " ✅ ${dir} initialized" || echo " ⚠️ ${dir} skipped (may need variables)")
fi
done

# Load .env file if it exists
echo "🔐 Loading environment variables from .env file..."
if [ -f /workspaces/terraform-provider-githubx/.env ]; then
set -a
source /workspaces/terraform-provider-githubx/.env
set +a
echo "✅ Environment variables loaded from .env"
elif [ -f /workspace/.env ]; then
set -a
source /workspace/.env
set +a
echo "✅ Environment variables loaded from .env"
else
echo "⚠️ No .env file found. Create one from .env.example if needed."
fi

echo ""
echo "✅ Development environment setup complete!"
echo ""
echo "Available commands:"
echo " make build - Build the provider"
echo " make install - Install the provider"
echo " make install-local - Install provider locally for Terraform testing"
echo " make init-examples - Initialize Terraform in all examples"
echo " make init-example - Initialize a specific example (EXAMPLE=path)"
echo " make test - Run tests"
echo " make fmt - Format code"
echo " make docs - Generate documentation"
echo ""
echo "💡 The provider is already installed locally and examples are initialized!"
echo " Navigate to any example directory and run 'terraform plan' or 'terraform apply'."
Empty file added .env.example
Empty file.
5 changes: 5 additions & 0 deletions .github/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Code of Conduct

HashiCorp Community Guidelines apply to you when interacting with the community here on GitHub and contributing code.

Please read the full text at https://www.hashicorp.com/community-guidelines
21 changes: 21 additions & 0 deletions .github/workflows/issue-comment-triage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# DO NOT EDIT - This GitHub Workflow is managed by automation
# https://github.com/hashicorp/terraform-devex-repos
name: Issue Comment Triage

on:
issue_comment:
types: [created]

jobs:
issue_comment_triage:
runs-on: ubuntu-latest
env:
# issue_comment events are triggered by comments on issues and pull requests. Checking the
# value of github.event.issue.pull_request tells us whether the issue is an issue or is
# actually a pull request, allowing us to dynamically set the gh subcommand:
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment-on-issues-only-or-pull-requests-only
COMMAND: ${{ github.event.issue.pull_request && 'pr' || 'issue' }}
GH_TOKEN: ${{ github.token }}
steps:
- name: 'Remove waiting-response on comment'
run: gh ${{ env.COMMAND }} edit ${{ github.event.issue.html_url }} --remove-label waiting-response
21 changes: 21 additions & 0 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# DO NOT EDIT - This GitHub Workflow is managed by automation
# https://github.com/hashicorp/terraform-devex-repos
name: 'Lock Threads'

on:
schedule:
- cron: '43 20 * * *'

jobs:
lock:
runs-on: ubuntu-latest
steps:
# NOTE: When TSCCR updates the GitHub action version, update the template workflow file to avoid drift:
# https://github.com/hashicorp/terraform-devex-repos/blob/main/modules/repo/workflows/lock.tftpl
- uses: dessant/lock-threads@1bf7ec25051fe7c00bdd17e6a7cf3d7bfb7dc771 # v5.0.1
with:
github-token: ${{ github.token }}
issue-inactive-days: '30'
issue-lock-reason: resolved
pr-inactive-days: '30'
pr-lock-reason: resolved
45 changes: 45 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Terraform Provider release workflow.
name: Release

on:
workflow_run:
workflows: ["Terraform Tag"]
types:
- completed
branches:
- main

# Releases need permissions to read and write the repository contents.
# GitHub considers creating releases and uploading assets as writing contents.
permissions:
contents: write

jobs:
goreleaser:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
# Allow goreleaser to access older tag information.
fetch-depth: 0
# Checkout the commit from the triggering workflow run
ref: ${{ github.event.workflow_run.head_sha }}
- uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
go-version-file: 'go.mod'
cache: true
- name: Import GPG key
uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 # v6.1.0
id: import_gpg
with:
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }}
passphrase: ${{ secrets.PASSPHRASE }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@286f3b13b1b49da4ac219696163fb8c1c93e1200 # v6.0.0
with:
args: release --clean
env:
# GitHub sets the GITHUB_TOKEN secret automatically.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
15 changes: 15 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Terraform Tag
on:
workflow_run:
workflows: ["Tests"]
types:
- completed
branches:
- main

permissions:
contents: write
jobs:
terraform-tag:
if: ${{ github.event.workflow_run.conclusion == 'success' }}
uses: actionsforge/actions/.github/workflows/terraform-tag.yml@main
Loading
Loading