TerraShelf

Catalog · CI/CD · v1.0.0

github-oidc-role

GitHub Actions role whose trust policy allows one branch or one environment.

Tests passed 6 of 6. Failed 0.

Inputs

NameTypeRequiredDescription
create_oidc_providerboolnoCreate the GitHub OIDC provider. Set false and pass existing_oidc_provider_arn when the account already has one.
existing_oidc_provider_arnstringnoARN of an existing GitHub OIDC provider. Required when create_oidc_provider is false.
github_orgstringyesGitHub organization or user that may assume the role. Wildcards are rejected.
github_repostringyesSingle GitHub repository name that may assume the role. Wildcards are rejected.
inline_policy_jsonstringnoOptional inline policy JSON. Null skips the inline policy. A bare star action is rejected.
managed_policy_arnslist(string)noManaged policy ARNs to attach to the role.
max_session_durationnumbernoMaximum role session duration in seconds.
namestringyesIAM role name. Do not encode an environment into this name.
oidc_thumbprintslist(string)noSHA-1 thumbprints for the GitHub OIDC provider. The provider resource requires at least one.
subject_refstringyesBranch name when subject_type is branch, or environment name when subject_type is environment. Wildcards are rejected.
subject_typestringyesWhether the trust subject pins a branch or a GitHub environment.
tagsmap(string)noExtra tags merged onto every taggable resource. ManagedBy and Module are always set by the module.

Outputs

NameDescription
caller_contextAccount, partition, and region resolved from data sources.
inline_policy_countNumber of inline policies. Zero when inline_policy_json is null.
managed_policy_countNumber of managed policy attachments.
max_session_durationRole max session duration in seconds.
oidc_provider_createdTrue when this module creates the GitHub OIDC provider.
role_arnARN of the IAM role.
role_nameName of the IAM role.
tag_auditTags on every taggable resource this module creates.
trust_audienceExact token.actions.githubusercontent.com:aud value written into the trust policy.
trust_subjectExact token.actions.githubusercontent.com:sub value written into the trust policy.

Example

The caller supplies the region. This example does not embed an account id.

module "gha" {
  source = "../.."

  name         = "gha-demo-role"
  github_org   = "example-org"
  github_repo  = "example-repo"
  subject_type = "branch"
  subject_ref  = "main"
  tags = {
    Example = "basic"
  }
}

Tests

Mock plan excerpt

mocked provider: ARNs and IDs are simulated. This excerpt is from terraform test with a mocked provider, not a live plan.

mocked provider: ARNs and IDs are simulated. This is terraform test -verbose, not a live plan.

tests\github-oidc-role.tftest.hcl... in progress
  run "branch_subject"... pass

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_iam_openid_connect_provider.github[0] will be created
  + resource "aws_iam_openid_connect_provider" "github" {
      + arn             = (known after apply)
      + client_id_list  = [
          + "sts.amazonaws.com",
        ]
      + id              = (known after apply)
      + tags            = {
          + "ManagedBy" = "terraform"
          + "Module"    = "github-oidc-role"
          + "Owner"     = "platform"
        }
      + tags_all        = (known after apply)
      + thumbprint_list = [
          + "6938fd4d98bab03faadb97b34396831e3780aea1",
        ]
      + url             = "https://token.actions.githubusercontent.com"
    }

  # aws_iam_role.this will be created
  + resource "aws_iam_role" "this" {
      + arn                  = (known after apply)
      + assume_role_policy   = (known after apply)
      + create_date          = (known after apply)
      + description          = "GitHub Actions role for repo:example-org/example-repo:ref:refs/heads/main in partition aws."
      + id                   = (known after apply)
      + managed_policy_arns  = (known after apply)
      + max_session_duration = 3600
      + name                 = "gha-demo-role"

Resources

graphviz dot was not installed. The figure is a python-hcl2 resource list.

Resource list for github-oidc-role

Changelog

Changelog

All notable changes to this module are documented in this file.

The format is based on Keep a Changelog, and this module uses Semantic Versioning.

[1.0.0] - 2026-10-03

Added

Billable item names

Names only. This page does not quote a price. Example amounts, including a budget limit, are placeholders and are not recommendations. GuardDuty and Security Hub stay off unless a module switch is set, because those services are billable.