I am trying to pass the access key ID, secret key, and session key returned by a call to sts.AssumeRole() to my Terraform Cloud workspace. After reviewing the documentation and several posts, here is my current approach which is failing with a “No valid credential sources found for AWS Provider”:
-
Remote backend correctly configured to point to my TF Cloud Workspace and authenticate using an API token obtained from terraform login.
-
Variables in a credentials.auto.tfvars file in the same directory as my main.tf file:
aws_access_key = "ASIA......"
aws_secret_key = "[my_secret_key]"
aws_session_token = "[my_session_token]"
- variables in my main.tf file:
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "aws_session_token" {}
- Use those variables to create tfe_variables of category “env” in my remote workspace:
locals {
common_variables = {
AWS_ACCESS_KEY_ID = var.aws_access_key
AWS_SECRET_ACCESS_KEY = var.aws_secret_key
AWS_SESSION_TOKEN = var.aws_session_token
}
}
resource "tfe_organization" "my-tfe-org" {
name = "my-org-name"
email = "myemail@company.com"
}
resource "tfe_workspace" "my-tfe-workspace" {
name = "my-workspace-name"
organization = tfe_organization.my-tfe-org.id
resource "tfe_variable" "shared" {
for_each = local.common_variables
workspace_id = tfe_workspace.my-tfe-workspace.id
category = "env"
key = each.key
value = each.value
sensitive = true
}
- Then I reference the aws provider and create some resources:
provider "aws" {
region = "us-east-1"
}
resource "aws_iam_role" "role" {
...
}
As stated above the error is: “Error: No valid credential sources found for AWS Provider.”