Hey all! I have a question about the `aws-github-r...
# atmos
r
Hey all! I have a question about the
aws-github-repository
component. I'm trying to get started with the component by importing a couple repos. When I run
atmos terraform plan
on my local machine, where I'm logged into GitHub, the plan runs without issue. For CI / CD, we use the GitHub Actions provided by atmos. When I raise a PR, the workflow fails with the following error:
Copy code
Planning failed. Terraform encountered an error while generating this plan.


Error: Cannot import non-existent remote object

While attempting to import an existing object to
"module.repository.github_repository.default[0]", the provider detected that
no object exists with the given id. Only pre-existing objects can be
imported; check that the id is correct and that it is associated with the
provider's configured region or endpoint, or use "terraform apply" to create
a new remote object for this resource.

# Error                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
exit status 1
Looking elsewhere online, I think this is due to how the GitHub Token is configured. Since I started getting this error, I've tried passing in the
GITHUB_TOKEN
secret as an environment variable to the action. Is there any guidance on how to authenticate the Atmos GitHub Actions workflows with the Terraform GitHub provider? Let me know if you need more info, config files, etc. Thanks!
✅ 1
w
https://atmos.tools/integrations/github-actions/component-updater#requirements Looks like they use a headless github app for auth. I haven't gone through that myself, but its on my team's list to get running.
Also, I haven't myself employed atmos, but have been pouring over the docs for the past few days bc I also wanted to use the
aws-github-repository
component lol
r
Thanks @Wacey, I already have these settings enabled and it works fine with the AWS and Kubernetes providers, so I figure there's something specific to the GitHub provider that I'm missing
w
Sorry, left off some links when I copypasta'd lol https://registry.terraform.io/providers/integrations/github/latest/docs#app_auth-1 provider "github" { owner = var.github_organization app_auth {} # When using
GITHUB_APP_XXX
environment variables } https://github.com/suzuki-shunsuke/ghtkn?tab=readme-ov-file
👀 1
i wish i had more time to implement all this in my workflows... but here is how I worked it w/o atmos previously:
Copy code
name: "Terraform"

on:
  workflow_call:
...    
    secrets:
      GH_TOKEN_RW:
        required: false
      GH_TOKEN_RO:
        required: false      
...
    - name: Terraform Plan
        id: plan
        env:
          GITHUB_TOKEN: ${{ secrets.GH_TOKEN_RW }}
          TF_CLI_ARGS_plan: "-lock-timeout=10m -no-color -input=false -var-file=envs/${{ inputs.environment }}.tfvars -out=tfplan_${{ inputs.environment }}"
        run: |
          terraform plan
        continue-on-error: true
e
cc @Igor Rodionov @Dan Miller (Cloud Posse)
w
its been about a year since i wrote the above workflow, but I THINK I ran into issues defining a secret named GITHUB_* because those were reserved. So i just named it GH_TOKEN_RW or GH_TOKEN_RO lol
d
You’ll need set up authentication with the GitHub provider from GitHub Actions to access the repo where you’d like to apply changes (opposed to the repo where you’re running the workflow). We’d recommend using a GitHub App to create a token before running Terraform. I can share an example in a few
Here's an example of an apply workflow. The "Create GitHub App Token for Acme Apply" step creates a token from a GitHub App with write permission in the organization, and then passes that token to
env.GITHUB_TOKEN
before running Terraform
The apply app would need these: • Organization Level Permission: ◦ "Members": "Read only" • Repository level: ◦ "Actions": "Read only" ◦ "Administration": "Read - Write" ◦ "Contents": "Read - Write" ◦ "Custom properties": "Read - Write" ◦ "Environments": "Read - Write" ◦ "Issues": "Read - Write" ◦ "Repository security advisories": "Read only" ◦ "Secret scanning alerts": "Read only" ◦ "Secrets": "Read - Write" ◦ "Variables": "Read - Write" ◦ "Webhooks": "Read - Write" And a plan only app would need these: • Organization Level Permission: ◦ "Members": "Read only" • Repository level: ◦ "Actions": "Read only" ◦ "Administration": "Read only" ◦ "Contents": "Read only" ◦ "Custom properties": "Read only" ◦ "Environments": "Read only" ◦ "Issues": "Read only" ◦ "Repository security advisories": "Read only" ◦ "Secret scanning alerts": "Read only" ◦ "Secrets": "Read only" ◦ "Variables": "Read only" ◦ "Webhooks": "Read only"
r
That worked for me, thanks for the detailed example!
🙌 1
np 1