AWS recently introduced local zones (ap-south-1-del-1). I am trying to use the region to deploy an EC2 instance. I have enabled the region and the local zone in my AWS account.
This is my terraform provider file :-
provider "aws" {
region = "ap-south-1-del-1"
}
terraform {
required_version = "> 0.11"
required_providers {
aws = "~> 4.0"
}
}
but i keep running into the following :-
Error: error configuring Terraform AWS Provider: error validating provider credentials:
error calling sts:GetCallerIdentity: operation error STS: GetCallerIdentity, exceeded maximum
number of attempts, 9, https response error StatusCode: 0, RequestID: , request send failed,
Post "https://sts.ap-south-1-del-1.amazonaws.com/": dial tcp: lookup sts.ap-south-1-del-
1.amazonaws.com: no such host
│
│ with provider["registry.terraform.io/hashicorp/aws"],
│ on provider.tf line 1, in provider "aws":
│ 1: provider "aws" {
│
╵
and this is my EC2 instance for anyone curious. Super basic.
resource "aws_instance" "web" {
ami = "ami-0ef82eeba2c7a0eeb"
instance_type = "t2.micro"
tags = {
Name = "HelloWorld"
}
}
Has anyone tried it? Is it supported? Thank you.
You do not change the provider's region. It is still ap-south-1. To create EC2 instance in a LZ, you have to follow three steps:
Enable a Local Zone using aws_ec2_availability_zone_group
Create subnet in the LZ enabled uzing aws_subnet
Create instance in the subnet using aws_instance.
I think you need to update the provider version for aws to work with new local zones. You can go to official provider page and upgrade the version to a newer version for aws provider
Related
I am new here and also a new learner into terraform and AWS.
I have a question regarding the "terraform plan" command which does not work and gets me some kind of error about validating provider credentials. The OS I am using is Windows 10.
The error that is shown is:
Error: configuring Terraform AWS Provider: error validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, https response error StatusCode: 403, RequestID: 2ecdd9ef-e5d6-4d69-9953-43b9d9482af8, api error InvalidClientTokenId: The security token included in the request is invalid.
│
with provider["registry.terraform.io/hashicorp/aws"],
on main.tf line 10, in provider "aws":
10: provider "aws" {
I have made the credentials firstly with command prompt using command:
SET VARIABLE="xxxxxxxxxxxxxx"
SET VARIABLE xxxxxxxxxxxxxx
The terraform file has this content:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_s3_bucket" "my_s3_bucket-123" {
bucket = "my-s3-bucket-123"
}
Because i got this error above i made the environment variables with power shell using this command:
$env:AWS_ACCESS_KEY_ID="xxxxxxxxxxxxxx"
$env:AWS_SECRET_ACCESS_KEY="xxxxxxxxxxxxxx"
I tried searching the internet for this kind of problem but did not find the same problem as i have it.
To avoid this install AWS CLI on your computer and setup aws config for your account. Then you are good to go.
Like this -
[default]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
You can also save for different users/accounts in one file -
[mac]
aws_access_key_id=AKIAIOSFODNN7EXAMPLE
aws_secret_access_key=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
[jack]
aws_access_key_id=akjshfkjasdhfkjasdfhaksjd
aws_secret_access_key=adsjfh/adjfh/adfshjgasdjh
Best wishes.
Just started using IntelliJ with AWS and this error pops after using the terraform apply command and the code is just a simple deployment of an EC2 instance.
Error: error configuring Terraform AWS Provider: no valid credential sources for Terraform AWS Provider found.
│
│ Please see https://registry.terraform.io/providers/hashicorp/aws
│ for more information about providing credentials.
│
│ Error: failed to refresh cached credentials, no EC2 IMDS role found, operation error ec2imds: GetMetadata, request send failed, Get "http://169.254.169.2
54/latest/meta-data/iam/security-credentials/": dial tcp 169.254.169.254:80: i/o timeout
│
│
│ with provider["registry.terraform.io/hashicorp/aws"],
│ on main.tf line 1, in provider "aws":
│ 1: provider "aws" {
│
╵
Credentials with AWS Explorer are correct Using an IAM user in Admin group. Terraform is installed IntelliJ plug-ins for Terraform and AWS are installed There is a connection between IntelliJ and AWS
Using Windows 10 Can't use admin operations on Windows I feel like Terraform and AWS cant be connected (as the error says), but I can't understand why.
Any ideas how can I deploy this instance? Any help is appreciated. I am here to answer any questions you may have. I expected to deploy an EC2 instance. I've tried creating a new project, reinstalling IntelliJ, using other IDE like VS Code.
So I had to run:
$ export AWS_ACCESS_KEY_ID=(your access key id)
$ export AWS_SECRET_ACCESS_KEY=(your secret access key)
With my keys in the Ubuntu terminal in IntelliJ and it worked!
Alternatively, you can configure your provider block as follows:
provider "aws" {
region = "aws_region_to_create_resources"
profile = "aws_profile_to_use"
}
or if your aws credentials file is in another path other than the default $HOME/.aws :
provider "aws" {
region = "aws_region_to_create_resources"
shared_credentials_file = "path_to_aws_credentials_file"
profile = "aws_profile_to_use"
}
Specifying a profile has the advantage of allowing you to use different AWS accounts for different environments. You can also use this method to deploy resources in the same terraform module to different accounts or regions by using aliases.
Terraform newbie here.
I am using the Terraform in Action book here. When I run the terraform apply, I get a VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC error. I have installed both the AWS CLI and configured my AWS credentials using aws configure. My AWS credentials are present in %UserProfile%\.aws\credentials file.
What am I missing?
main.tf
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "helloworld" {
ami = "ami-09dd2e08d601bff67"
instance_type = "t2.micro"
tags = {
Name = "HelloWorld"
}
}
Error stackTrace:
aws_instance.helloworld: Creating...
╷
│ Error: Error launching source instance: VPCIdNotSpecified: No default VPC for this user. GroupName is only supported for EC2-Classic and default VPC.
│ status code: 400, request id: 1e0911db-300b-4c00-aea1-dad588bbe40e
│
│ with aws_instance.helloworld,
│ on main.tf line 4, in resource "aws_instance" "helloworld":
│ 4: resource "aws_instance" "helloworld" {
│
it seems like you don't have a default VPC in the us-west-2 region.
Since you have mentioned you are just starting off with Terraform; I would highly recommend, referring to official Terraform documentation when you want to use a particular resource/module/provider.
In this case, for Resource: aws_instance, you can see what all attributes are supported.
If I were you I would first check if there's a default VPC in the aforementioned region. It's highly likely there's none. If I know the VPC subnet ID then I would simply pass on that value to the subnet_id attribute and Terraform will ensure that my instance will come up in the correct network.
Context :
I have set my aws credentials using aws configure.
I use terraform remote backend to store the terraform state
Using the following terraform configuration.
terraform {
backend "remote" {
hostname = "app.terraform.io"
organization = "test"
workspaces {
prefix = "networking-"
}
}
}
provider "aws" {
region = "eu-west-3"
}
Problem:
When I run terraform apply I have this error.
╷
│ Error: No valid credential sources found for AWS Provider.
│ Please see https://terraform.io/docs/providers/aws/index.html for more information on
│ providing credentials for the AWS Provider
│
│ with provider["registry.terraform.io/hashicorp/aws"],
│ on main.tf line 13, in provider "aws":
│ 13: provider "aws" {
│
╵
If you are using terraform cloud remote backend by default when you create a workspace, the terraform plan command in executed on the remote backend and not of your local machine. This is why, terraform can not find your credentials, because they are not set in the remote machine. To fix this problem, you need to order terraform to run the plan on your machine. To do so
go in your workspace
then go in the general settings
then switch from remote execution mode to local
Then try to run again your plan on your machine
while running terraform script to launch aws instance getting this error
Error: Invalid AWS Region: us-west-2a
on provider.tf line 1, in provider "aws":
1: provider "aws" {
This is my provider.tf
provider "aws" {
region = "${var.region}"
version = "~> 2.0"
}
can anybody help out?
us-west-2a is an availability zone inside the us-west-2 region. You need to fix your var.region value.