AWS Terraform Authentication

  • To run terraform on your local system for your AWS, you will need to first configure AWS on your local system.
  • Create a folder .aws/credential and store the AWS credential details at C:\Users\<yourhome folder>\.aws
  • You can do the above also through AWS command line > aws configure
  • You can define credentials in four different ways,
    • Static
    • Environment Variable
    • Shared Credential file
    • EC2 Role 
  • Static – it is basic method, we directly hard code the credentials in the .tf file provider section.
  • Environment Variable – Run the below command for windows machine, for Linux system use export commands.
  • Once configured the environmental variables, you can all the keys through provider sections.

  • Shared Credential files – You can access the credential files created using aws configure command. The file is by default at location $HOME/.aws/credentials.  You can call the shared file like below in the provider section.
  • EC2 Role – If running under EC2, then you can directly create and assign role to EC2, this avoids use of hard coded credentials.
  • Assume role – We can provide role ARN, terraform will attempt this role. You can call the role ARN in provider section.