O'Reilly logo

Getting Started with Terraform - Second Edition by Kirill Shirinkin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Credentials file

If Terraform can't find keys in the template or environment variables, it will try to fetch them from the credentials file, which is typically stored in the ~/.aws/ credentials. If you have previously installed and configured AWS CLI, then you already have a credentials file generated for you. If you have not done this, then you can add it yourself, with the content as follows:

[default] 
aws_access_key_id =  xxxxxxxxxxxxx 
aws_secret_access_key =  xxxxxxxxxxxxx 

You should always avoid setting credentials directly in the template. It's up to you whether you use environment variables or a credentials file. Whichever method you picked, let's add the following configuration to template.tf:

 provider "aws" { region = "eu-central-1" ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required