Verify Terraform can see an Environment variab

I’m using Drone for my CI/CD pipeline. I’ve configured it to generate environment variables that contains my secrets for AWS.
I’ve follewed the documentation regarding environment variables and as far as I can tell, they should be visible to terraform.

Is there a way I can verify this somehow. Here is my code:

#james bennett1
terraform {
  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 3.0"
    }
  }
}

variable "AWS_ACCESS_KEY_ID" {
  default = ""
}

variable "AWS_SECRET_ACCESS_KEY" {
  default = ""
}


# Configure the AWS Provider
provider "aws" {
  region  = "us-east-1"

 
  
 access_key = "${var.AWS_ACCESS_KEY_ID}"

 secret_key = "${var.AWS_SECRET_ACCESS_KEY}"
}

resource "aws_s3_bucket" "bmw-bucket-a" {
  bucket = "my-tf-test-bucket"
  acl    = "private"

  tags = {
    
    Name        = "MW test big Bucket"
    Environment = "Dev"
  }
}


#}

The error when I run the code is

Error: NoCredentialProviders: no valid providers
caused by: EnvAccessKeyNotFound: failed to find credentials in the environment.

Terraform doesn’t map environment variables to var. on its own, so it’s not set (string “”).
You could use TF_VAR_AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID which means that terraform will pick it from the environment and map it into the terraform input variable.

This has fixed it - nothing else needs to happen if the Env variables are named as below. The -env command lists the variables as being there too :slight_smile:
kind: pipeline
name: default
steps:

  • name: test
    image: jmccann/drone-terraform
    environment:
    AWS_ACCESS_KEY_ID:
    from_secret: AWS_ACCESS_KEY_ID
    AWS_SECRET_ACCESS_KEY:
    from_secret: AWS_SECRET_ACCESS_KEY
    #commands:
    #- env
    #trigger