I'm trying to configure a GitHub OIDC provider and...
# atmos
d
I'm trying to configure a GitHub OIDC provider and several roles to use with the provider, using atmos and two modules from
cloudposse-terraform-components
. I'm running into a snag when I try to pass the OIDC provider ARN to the OIDC role module. I'm not sure if this is an atmos bug or a configuration problem on my end. Here are the details: two vendored modules: aws-github-oidc-provider, and aws-github-oidc-role I have included these in my
dev
stack with these configurations: ./stacks/dev/dev-github-oidc-provider.yaml
Copy code
import:
  - ./_defaults
components:
  terraform:
    dev-github-oidc-provider:
      metadata:
        component: "github-oidc-provider"
      vars:
        name: "dev-github-oidc-provider"
.stacks/dev/cicd-platform-oidc-role.yaml
Copy code
import:
  - ./_defaults
components:
  terraform:
    cicd-platform-oidc-role:
      metadata:
        component: "github-oidc-role"
      vars:
        github_oidc_provider_id: !terraform.output dev-github-oidc-provider oidc_provider_arn
        organization: "REDACTED"
        github_actions_allowed_repos: ["REDACTED"]
        iam_policy:
          - version: "2012-10-17"
            statements:
              - effect: "Allow"
                actions:
                  - "ecr:CompleteLayerUpload"
                  - "ecr:GetAuthorizationToken"
                  - "ecr:UploadLayerPart"
                  - "ecr:InitiateLayerUpload"
                  - "ecr:BatchCheckLayerAvailability"
                  - "ecr:PutImage"
                resources:
                  - !terraform.output ecr-platform-api global repository_arn
when I try to run
atmos terraform apply cicd-platform-oidc-role -s dev
, the Terraform apply fails with this message:
Copy code
Terraform has been successfully initialized!
Switched to workspace "dev-cicd-platform-oidc-role".
ā•·
│ Error: Failed to read variables file
│ 
│ Given variables file dev-github-oidc-provider.terraform.tfvars.json does not exist.
a
do you see the generated
dev-github-oidc-provider.terraform.tfvars.json
file?
d
This feels related to the
!terraform.output
call which is trying to get the OIDC provider ARN to set
github_oidc_provider_id
. It feels like (perhaps) atmos expects the output to have been captured in a file named after the source component
@Andriy Knysh (Cloud Posse) no. it is not created
a
also, the file does not have the stack name in it, just the component name
please show the
stacks
section from
atmos.yaml
d
the component name is
dev-github-oidc-provider
. maybe this is causing an issue...?
atmos.yaml
Copy code
stacks:
  base_path: "stacks"
  included_paths:
    - "deploy/**/*"
  excluded_paths:
    - "**/_defaults.yaml"
  name_pattern: "{stage}"
a
the component name should not be an issue, what is an issue is that the genaerated varfile name should include the stack
dev-dev-github-oidc-provider.terraform.tfvars.json
d
neither file exists though šŸ˜„
a
run
atmos describe component cicd-platform-oidc-role -s dev --process-functions
to check the variables
instead of
!terraform.output
you can use
!terraform.state
if you are using
s3
backend
it's much much faster than
!terraform.output
šŸ‘ 1
what do you see when you run
atmos describe component cicd-platform-oidc-role -s dev --process-functions
d
sorry, I am cleaning up that output. I have to REDACT mention of my company, client, and project 😐
is there a specific value I am looking for? It is a big yaml dump
I see this:
Copy code
github_oidc_provider_id:
      final_value: arn:aws:iam::REDACTED:oidc-provider/token.actions.githubusercontent.com
      name: github_oidc_provider_id
      stack_dependencies:
        - dependency_type: inline
          stack_file: deploy/dev/cicd-platform-oidc-role
          stack_file_section: components.terraform.vars
          variable_value: arn:aws:iam::REDACTED:oidc-provider/token.actions.githubusercontent.com
so it appears that it is able to resolve the value
a
what's the valus of
github_oidc_provider_id: !terraform.output dev-github-oidc-provider oidc_provider_arn
d
I expect there is a
-varfile
argument being passed to terraform which is not correct... ?
it is the value in
final_value
above
a
this is strange (might be a bug in Atmos). can you rename the component
dev-github-oidc-provider
to maybe
github-oidc-provider
and try again?
d
yes
trying now
a
in any case, you prob should not include stack names in the component names b/c it makes them not reusable
you define a component and include/import it into a stack
d
yes, I was confused on this point. I want to make several of the oidc providers, and several roles. I am/was confused about the scope of component names. I will try to destroy what I have and correct that. perhaps it is contributing to the problem
a
if removing
dev-
from the component name solves the problem, let me know (might be an interesting bug in Atmos when the stack name is already included in the component name). If not, let me know anyway šŸ™‚
d
it did not solve the problem
it is still looking for the same file and the file has not been generated
I am confused when I declare a component which is the unique name and which is the canonical name. If I have this:
components/terraform/github-oidc-provider
then in stacks/catalog/github-oidc-provider.yaml, I have this:
Copy code
components:
  terraform:
    github-oidc-provider:
      metadata:
        component: github-oidc-provider
How can I create two providers in the same stack? Can I do this?
Copy code
import:
  - catalog/github-oicd-provider
components:
  terraform:
    my-custom-name1:
      metadata:
        component: github-oidc-provider
    my-custom-name2:
      metadata:
        component: github-oidc-provider
I am confused about the user of components.terraform.* versus the value of components.terraform.*.metadata.component
a
d
thanks
a
metadata.component
is a pointer to the Terraform component (code)
try in Debug mode and see what is beign generated for the varfile name
Copy code
atmos terraform plan cicd-platform-oidc-role -s dev --logs-level=Debug
d
I continue to get the same error. the only mention of the varfile is in the error message. I do not see any other mention in the log output. this is bizarre
a
Copy code
atmos terraform plan dev-github-oidc-provider -s dev --logs-level=Debug
you should see the generated varfile in the message
Executing command:
d
it has nothing to do with the !terraform.output call. I have deleted it and the error is still occurring. I can only assume there is a bug in my configuration.
a
also try
Copy code
atmos terraform generate varfile dev-github-oidc-provider -s dev --logs-level=Debug
d
right. but i am applying cicd-platform-oidc-role, and it is complaining that it cannot find the varfile for the dev-github-oidc-provider
i see the file generated in components/terraform/github-oidc-provider. it is created when I apply that component. I just do not understand why atmos is expecting that varfile when I apply a different component
so.. I expect I have messed up which component is specified in one of the files... 🤷
AAAAH! I am in a
terraform shell
and have not realized it
hahaha. it all makes sense. there are TF_CLI_ARGS arguments pinning the configuration to the other module
thank you for your help... this is the error
šŸš€ 1