Skip to content

Generate

Generate #44

Workflow file for this run

name: Generate
on:
schedule:
# Trigger the workflow every Friday at 4:00 UTC.
- cron: '0 4 * * 5'
push:
branches:
- main
paths:
- "generators/ephemeral_resources/providers.tf"
workflow_dispatch: # Allow manual triggering
permissions:
contents: write
pull-requests: write
env:
TERRAFORM_VERSION: "1.11.0"
BRANCH_PREFIX: "generate-ephemeral-resources"
jobs:
ephemeral-resources:
name: Ephemeral Resources
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v5
with:
fetch-depth: 0 # Fetch full history for better git operations
- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TERRAFORM_VERSION }}
- name: Cache Terraform providers
uses: actions/cache@v4
with:
path: |
generators/ephemeral_resources/.terraform
generators/ephemeral_resources/.terraform.lock.hcl
key: terraform-${{ env.TERRAFORM_VERSION }}-${{ hashFiles('generators/ephemeral_resources/providers.tf') }}
restore-keys: |
terraform-${{ env.TERRAFORM_VERSION }}-
- name: Setup Git configuration
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Create and switch to feature branch
id: branch
run: |
BRANCH_NAME="${{ env.BRANCH_PREFIX }}-${{ github.run_id }}"
echo "branch_name=${BRANCH_NAME}" >> $GITHUB_OUTPUT
git checkout -b "${BRANCH_NAME}"
git push -u origin "${BRANCH_NAME}"
- name: Initialize Terraform
working-directory: generators/ephemeral_resources
run: terraform init
- name: Generate ephemeral and write-only resources
working-directory: generators/ephemeral_resources
run: |
echo "Generating ephemeral resources from providers (excluding deprecated)..."
terraform providers schema -json | \
jq '{
"ephemeral": [
.provider_schemas |
to_entries[] as $provider |
$provider.value.ephemeral_resource_schemas? |
select(.) |
to_entries[] |
select(
(.value.block.deprecated? != true) and
((.value.block.description? // "" | test("deprecated|obsolete|removed"; "i")) | not)
) |
.key
]
}' \
> ../../data/ephemeral/gen_schema_ephemerals.json
echo "Generating list of deprecated ephemeral resources for reference..."
terraform providers schema -json | \
jq '{
"deprecated_ephemeral": [
.provider_schemas |
to_entries[] as $provider |
$provider.value.ephemeral_resource_schemas? |
select(.) |
to_entries[] |
select(
(.value.block.deprecated? == true) or
((.value.block.description? // "" | test("deprecated|obsolete|removed"; "i")))
) |
{
provider: $provider.key,
resource: .key,
deprecated: .value.block.deprecated?,
deprecation_message: .value.block.deprecation_message?,
reason: (if .value.block.deprecated? then "explicitly_deprecated" else "description_indicates_deprecated" end)
}
]
}' \
> ../../data/ephemeral/deprecated_ephemerals.json
echo "Generating write-only resources from providers..."
terraform providers schema -json | \
jq '.provider_schemas | to_entries |
map(.value.resource_schemas | to_entries |
map(select(.value.block.attributes != null)) |
map(select(.value.block.attributes | keys[] | test("^(?!has_).*_wo$"))) |
map({key: .key, value: (.value.block.attributes | keys[] | select(test("^(?!has_).*_wo$")))})) |
flatten | map({key: .key, value: .value}) | from_entries' \
> ../../data/write-only/gen_write_only.json
- name: Combine JSON files into ephemerality.json
run: |
echo "Combining generated files into ephemerality.json..."
# Extract arrays and objects from source files
EPHEMERAL_ARRAY=$(jq -r '.ephemeral' data/ephemeral/gen_schema_ephemerals.json)
RESOURCES_ARRAY=$(jq -r '.resources' data/ephemeral/manual_resources.json)
WRITE_ONLY_OBJECT=$(jq -r '.' data/write-only/gen_write_only.json)
# Combine into final structure with sorted arrays
jq -n \
--argjson ephemeral "$EPHEMERAL_ARRAY" \
--argjson resources "$RESOURCES_ARRAY" \
--argjson write_only "$WRITE_ONLY_OBJECT" \
'{
ephemeral: ($ephemeral | sort),
resources: ($resources | sort),
write_only: $write_only
}' > data/ephemerality.json
echo "Combined ephemerality.json created with:"
echo "- Ephemeral resources: $(jq '.ephemeral | length' data/ephemerality.json) (deprecated filtered out)"
echo "- Deprecated ephemeral resources: $(jq '.deprecated_ephemeral | length' data/ephemeral/deprecated_ephemerals.json) (tracked separately)"
echo "- Manual resources: $(jq '.resources | length' data/ephemerality.json)"
echo "- Write-only attributes: $(jq '.write_only | keys | length' data/ephemerality.json)"
- name: Check for changes and determine action
id: changes
run: |
# Show what files have changed for debugging
echo "Git status:"
git status --porcelain
if [[ -z $(git status --porcelain) ]]; then
echo "change_type=none" >> $GITHUB_OUTPUT
echo "No changes detected"
elif [[ -z $(git status --porcelain | grep "^[DR]") ]]; then
echo "change_type=additions" >> $GITHUB_OUTPUT
echo "New resources added"
else
echo "change_type=deletions" >> $GITHUB_OUTPUT
echo "Deletions detected - requires review"
fi
- name: Commit and push changes
if: steps.changes.outputs.change_type != 'none'
run: |
# Add all generated files explicitly
git add data/ephemeral/gen_schema_ephemerals.json
git add data/ephemeral/deprecated_ephemerals.json
git add data/write-only/gen_write_only.json
git add data/ephemerality.json
# Show what we're about to commit
echo "Files to be committed:"
git diff --cached --name-only
git commit -m "robot: update list of ephemeral resources (excluding deprecated)
- Generated ephemeral resources: $(jq '.ephemeral | length' data/ephemerality.json) entries (deprecated filtered out)
- Deprecated ephemeral resources: $(jq '.deprecated_ephemeral | length' data/ephemeral/deprecated_ephemerals.json) entries (for reference)
- Manual resources: $(jq '.resources | length' data/ephemerality.json) entries
- Generated write-only resources: $(jq '.write_only | keys | length' data/ephemerality.json) entries
- Change type: ${{ steps.changes.outputs.change_type }}
Files updated:
- data/ephemeral/gen_schema_ephemerals.json (non-deprecated only)
- data/ephemeral/deprecated_ephemerals.json (deprecated resources for reference)
- data/write-only/gen_write_only.json
- data/ephemerality.json (combined)"
git push
- name: Create Pull Request
if: steps.changes.outputs.change_type != 'none'
env:
GH_TOKEN: ${{ github.token }}
run: |
PR_TITLE="Update ephemeral resources (${{ steps.changes.outputs.change_type }})"
PR_BODY="## Automated Resource Update
This PR was automatically generated to update the ephemeral and write-only resource definitions.
**Change Type:** ${{ steps.changes.outputs.change_type }}
**Generated Files:**
- \`data/ephemeral/gen_schema_ephemerals.json\` (non-deprecated resources only)
- \`data/ephemeral/deprecated_ephemerals.json\` (deprecated resources for reference)
- \`data/write-only/gen_write_only.json\`
- \`data/ephemerality.json\` (combined file)
**Resource Counts:**
- Ephemeral resources: $(jq '.ephemeral | length' data/ephemerality.json) (deprecated filtered out)
- Deprecated ephemeral resources: $(jq '.deprecated_ephemeral | length' data/ephemeral/deprecated_ephemerals.json) (for reference)
- Manual resources: $(jq '.resources | length' data/ephemerality.json)
- Write-only attributes: $(jq '.write_only | keys | length' data/ephemerality.json)
**Deprecation Filtering:**
- Resources marked with \`deprecated: true\` are excluded
- Resources with descriptions containing 'deprecated', 'obsolete', or 'removed' are excluded
- Deprecated resources are tracked separately in \`deprecated_ephemerals.json\`
**Terraform Version:** ${{ env.TERRAFORM_VERSION }}
**Workflow Run:** ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
${{ steps.changes.outputs.change_type == 'deletions' && '⚠️ **Review Required:** This PR contains deletions and should be reviewed before merging.' || '✅ **Safe to Merge:** This PR only contains additions.' }}"
gh pr create \
--base main \
--head "${{ steps.branch.outputs.branch_name }}" \
--title "${PR_TITLE}" \
--body "${PR_BODY}" \
--label "automated" \
${{ steps.changes.outputs.change_type == 'additions' && '--label "auto-merge"' || '--label "needs-review"' }}