Skip to content

Instantly share code, notes, and snippets.

@RoseSecurity
Last active February 7, 2025 20:32
Show Gist options
  • Save RoseSecurity/6ddda7bded58d8c795e01a8fe0fc2d68 to your computer and use it in GitHub Desktop.
Save RoseSecurity/6ddda7bded58d8c795e01a8fe0fc2d68 to your computer and use it in GitHub Desktop.
A collection of utilies for finding, navigating, and downloading Cloud Posse modules and components.

Cloud Posse Module and Component Utilities

A collection of utilies for finding, navigating, and downloading Cloud Posse modules and components.

Important

The following dependencies are required to run these scripts: jq, gh, and fzf

utils

Module Finder

  • Quickly browse Cloud Posse Terraform modules.
#!/usr/bin/env bash

# A utility for listing and opening upstream components from Cloud Posse's service catalog

# Variables
ORG="cloudposse"

# List Cloud Posse Terraform Components and display in FZF
MODULE=$(gh repo list "$ORG" --json name -L 300 | jq -r '.[].name' | grep -e '^terraform-' | fzf)

# Open the module in the browser
gh browse -R "$ORG"/"$MODULE"

Component Finder

  • Quickly browse components and their latest versions with ease.
#!/usr/bin/env bash

# A utility for listing and opening upstream components from Cloud Posse's service catalog

# Variables
ORG="cloudposse-terraform-components"

# List Cloud Posse Terraform Components and display in FZF
COMPONENT=$(
  gh repo list "$ORG" --json name,latestRelease -L 300 |
  jq -r '.[] | [ .name, (.latestRelease.tagName // "no-release") ] | @tsv' |
  column -t |
  fzf |
  awk '{print $1}'
)

# Open the component in the browser
gh browse -R "$ORG"/"$COMPONENT"

Component Cloner

  • Clone components for local development and community contributions.
#!/usr/bin/env bash

# A utility for listing and cloning upstream components for contribution work

# Variables
COMPONENT_DIR="$HOME/Desktop/me/components/"
ORG="cloudposse-terraform-components"

# List Cloud Posse Terraform Components and display in FZF
COMPONENT=$(gh repo list "$ORG" --json name -L 300 | jq -r '.[].name' | fzf)

# Clone component into component directory and change into directory
gh repo clone "$ORG"/"$COMPONENT" "$COMPONENT_DIR"/"$COMPONENT" && cd "$COMPONENT_DIR"/"$COMPONENT" || exit

Component Scaffolding

  • Lay the foundation for components by generating the scaffolding for new components.
#!/usr/bin/env bash

# This script provisions the general scaffolding for a Terraform component.

# Define the Terraform files to be created.
terraform_files=("main.tf" "variables.tf" "outputs.tf" "providers.tf" "versions.tf")

# Create Terraform file scaffolding.
echo "Creating Terraform file scaffolding..."
for file in "${terraform_files[@]}"; do
  if [[ ! -f "$file" ]]; then
    touch "$file"
    echo "Created $file"
  else
    echo "$file already exists"
  fi
done

# Download context.tf if not already present.
context_file="context.tf"
context_url="https://raw.githubusercontent.com/cloudposse/terraform-aws-utils/refs/heads/main/context.tf"

if [[ ! -f "$context_file" ]]; then
  echo "Downloading $context_file..."
  curl -O "$context_url"
else
  echo "$context_file already exists"
fi

# Append to README.md.
readme_file="README.md"
echo "Updating $readme_file..."
cat <<EOF >>"$readme_file"

# Component: <component_name>

This component is responsible for provisioning ...

## Usage

**Stack Level**: <component_level>

Here's an example snippet for how to use this component.

\`\`\`yaml
components:
  terraform:
    <component_name>:
      vars:
        enabled: true
\`\`\`

EOF

echo "Scaffolding complete."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment