Unable to authenticate with Terraform AWS provider



  • I am trying to use terraform to spin up a new instance of a server.

    Using the AWS provider , I get this error:

    ╷
    │ Warning: Resource targeting is in effect
    │ 
    │ You are creating a plan with the -target option, which means that the result of this plan may not represent all of the changes requested by the current configuration.
    │ 
    │ The -target option is not for routine use, and is provided only for exceptional situations such as recovering from errors or mistakes, or when Terraform specifically suggests to use it as part of an
    │ error message.
    ╵
    ╷
    │ Error: error configuring Terraform AWS Provider: failed to get shared config profile, 2auth
    │ 
    │   with provider["registry.terraform.io/hashicorp/aws"],
    │   on main.tf line 1, in provider "aws":
    │    1: provider "aws" {
    │ 
    

    first off , I have no idea where this 2auth profile it is referencing is.

    Also I have tried setting my credentials with in both the tf file

    provider "aws" {
       region = var.aws_region
       shared_credentials_file = "/Users/samueldare/.aws/credentials"
    }
    

    and as environment variables, but it still doesnt work.

    I would appreciate pointers as to what I am doing wrong.



  • If you have multiple profiles in your credentials file, you need to state which profile you want to use, otherwise it will use [default]:

    credentials file:

    [default]
    aws_access_key_id = xxxxxxxx
    aws_secret_access_key = xxxxxxxx
    [profile2]
    aws_access_key_id = yyyyyyyy
    aws_secret_access_key = yyyyyyyyy
    

    terraform code:

    provider "aws" {
       region = var.aws_region
       shared_credentials_file = "/Users/samueldare/.aws/credentials"
       profile = "profile2"
    }
    

    As stated in the https://registry.terraform.io/providers/hashicorp/aws/latest/docs#shared-configuration-and-credentials-files




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2