Skip to content
Sandny Blog
  • Home
  • Java
  • JavaScript
  • AWS
  • Embedded
  • About
Create Lambda function with Terraform Terraform

How to read AWS credential profiles with Terraform

  • October 4, 2022October 4, 2022
  • by Coder Kai

We often use AWS credentials file when using AWS CLI to switch between different accounts. You can also read AWS credential profiles with Terraform and use it to work with the terraform CLI commands. For that the cleanest method is to use the provider in .tf file to define the config in your aws provider.

In your main.tf file where the aws provider is defined, you can provide the AWS credentials file you want to use.

provider "aws" {
  region  = "us-east-1" # region of the deployment
  profile = "test" # name of the profile in credentials file
}

The credentials file should look like following. The default location of the credential file is ~/.aws/credentials


aws_access_key_id=****
aws_secret_access_key=********
region=**-****-*

[test]
aws_access_key_id=****
aws_secret_access_key=********
region=**-****-*

[production-app]
aws_access_key_id=****
aws_secret_access_key=********
region=**-****-*

Profile name is what we have inside the square brackets. For example in the above credentials file we have default, test, production-app as profiles. Each profile will contain the access_key and the secret_key to authenticate the CLI.

If you have a seperate location for the aws credentials file you can provide following as the path of the credential file.

"aws" {
  region  = "us-east-1" # region of the deployment
  profile = "test" # name of the profile in credentials file
  shared_credentials_file = "/home/users/test/aws/credentials" # path of the credentials file
}

Now you can call terraform apply and it will choose the relevant profile from the credentials file to apply.

You can check more details in the official documentation for AWS Terraform to see what can be configured in the providers blog.

Using multiple refs for an array of React Elements
How to create Lambda function with Terraform
Coder Kai
A humble developer
aws credentials terraform aws terraform Terraform terraform cli authentication

Related articles

Create Lambda function with Terraform
How to create Lambda function…

Categories

  • android 3
  • Apollo Client 1
  • AWS 8
    • AppSync 5
    • EC2 1
    • EKS 1
    • Route53 1
    • S3 1
  • AWS Amplify 1
  • Chakra UI 1
  • Docker 1
  • Embedded 1
  • EmberJS 1
  • FCM 1
  • Godaddy 1
  • GraphQL 3
  • ios 1
  • Jasper 1
  • Java 10
    • Java 11 1
    • Java 14 1
  • JavaEE 2
  • JavaScript 39
    • Express.js 4
    • Javascript Guide 7
    • Node.js 3
    • react-native 4
    • React.js 17
    • Typescript 1
  • Kubernetes 1
  • machine learning 1
  • Maven 2
  • OCaml 3
  • PostgreSQL 1
  • Python 2
  • react-native 4
  • ReactJS 3
  • sass 1
  • Server 6
  • spark 1
  • Terraform 2
  • Ubuntu 4
  • Uncategorized 1
  • webpack 2

Recent Comments

  • binance註冊 on Java 13 Switch Expressions
  • binance register on Chakra UI Animations
  • binance account on SSL Websocket proxy with Nginx for Graphql Subscriptions

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Archives

  • October 2022 3
  • September 2022 7
  • May 2022 1
  • December 2021 1
  • August 2021 1
  • July 2021 6
  • June 2021 3
  • February 2021 1
  • July 2020 1
  • December 2019 5
  • November 2019 6
  • October 2019 3
  • August 2019 1
  • March 2019 1
  • February 2019 1
  • January 2019 2
  • December 2018 1
  • September 2018 2
  • August 2018 1
  • June 2018 1
  • February 2018 1
  • November 2017 2
  • October 2017 5
  • September 2017 1
  • June 2017 1
  • May 2017 10
Sandny Blog space
Theme by Colorlib Powered by WordPress