DEV Community

Zach Mowrey
Zach Mowrey

Posted on

Terraform V4 AWS Provider, Github Actions, and Named Profiles

Environment: Github Actions
Authentication: configure-aws-credentials action, using OIDC.
Terraform AWS Provider: >= 4

The Context

We want to use a named AWS profile for convenience in our local environments, but the named profile doesn't exist in our CI/CD pipelines, and we can't create it there (the necessary location isn't writable).

The Issue

The V3 AWS Provider for Terraform would gracefully fall back in an attempt to find valid AWS credentials when it couldn't find credentials for a named profile.

The V4 AWS Provider does not. Instead of following the AWS-CLI workflow for locating credentials, the V4 provider halts and returns an error:

error configuring Terraform AWS Provider: failed to get shared config profile, XYZ

Image description

The Resolution

We set the profile dynamically in our Terraform code:

  1. Create a new variable. Make it a bool, with a default of false. I called mine "pipeline".

Image description

  1. Modify your provider's profile. If we're in a pipeline, set the profile to "". Otherwise, you can set it to whatever value you had before.

Image description

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

Top comments (0)