hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.81k stars 9.16k forks source link

issue for terraform plan is not working #28934

Open muralikrishna9581 opened 1 year ago

muralikrishna9581 commented 1 year ago

Description

Actually, I'm creating vpc by using terraform in vs code. I think max i written code correctly. terraform init command is also successfully worked. then I entered into terraform plan command in vs code. i got below error.c please see attached pic. can anyone help me.

i written code as below format.

provider "aws" {
  region = "ap-south-1"
}

resource "aws_vpc" "dev" {
  cidr_block           = "10.0.0.0/16"
  instance_tenancy     = "default"
  enable_dns_support   = "true"
  enable_dns_hostnames = "true"
  tags = {
    Name = "dev"
  }
}

resource "aws_subnet" "dev-public-1" {
  vpc_id                  = aws_vpc.dev.id
  cidr_block              = "10.0.1.0/24"
  map_public_ip_on_launch = "true"
  availability_zone       = "ap-south-1a"

  tags = {
    Name = "dev-public-1"
  }
}

resource "aws_subnet" "dev-public-2" {
  vpc_id                  = aws_vpc.dev.id
  cidr_block              = "10.0.2.0/24"
  map_public_ip_on_launch = "true"
  availability_zone       = "ap-south-1b"

  tags = {
    Name = "dev-public-2"
  }
}

resource "aws_internet_gateway" "dev-gw" {
  vpc_id = aws_vpc.dev.id

  tags = {
    Name = "dev"
  }
}

resource "aws_route_table" "dev-public" {
  vpc_id = aws_vpc.dev.id

  route {
    cidr_block = "0.0.0.0/0"
    gateway_id = aws_internet_gateway.dev-gw.id
  }

  tags = {
    Name = "dev-public-1"
  }
}

resource "aws_route_table_association" "dev-public-1-a" {
  subnet_id      = aws_subnet.dev-public-1.id
  route_table_id = aws_route_table.dev-public.id
}

resource "aws_route_table_association" "dev-public-1-b" {
  subnet_id      = aws_subnet.dev-public-2.id
  route_table_id = aws_route_table.dev-public.id
}

resource "aws_instance" "public_inst-1" {
  ami           = "ami-0cca134ec43cf708f"
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.dev-public-1.id
  key_name      = "key11"
  tags = {
    Name = "public_inst-1"
  }
}

resource "aws_instance" "public_inst-2" {
  ami           = "ami-0cca134ec43cf708f"
  instance_type = "t2.micro"
  subnet_id     = aws_subnet.dev-public-2.id
  key_name      = "key11"
  tags = {
    Name = "public_inst-2"
  }
}

I got below error.

 Error: configuring Terraform AWS Provider: error validating provider credentials: error calling sts:GetCallerIdentity: operation error STS: GetCallerIdentity, https response error StatusCode: 403, RequestID: 21554fea-1fad-43f1-86d5-019660d45383, api error InvalidClientTokenId: The security token included in the request is invalid.
with provider["registry.terraform.io/hashicorp/aws"],
   on vpcterraform.tf line 1, in provider "aws":
   1: provider "aws" {

References

vpc terraform

No response

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 1 year ago

Hey @muralikrishna9581 👋 Thank you for taking the time to raise this! In this case, it looks like you need to take a look at the token that you're providing to authenticate the provider, as the error is indicating that it's not valid:

api error InvalidClientTokenId: The security token included in the request is invalid.
muralikrishna9581 commented 1 year ago

Thank you lot sharing the info.next how to i will do.can you please share steps

quixoticmonk commented 1 year ago

@muralikrishna9581 Your configuration requires the AWS credentials in the filesystem which is running the terraform commands. If your aws provider block is how it is in your code, you would need to provide your AWS credentials in one of the ways specified here.

muralikrishna9581 commented 1 year ago

I entered to terraform apply command in vs code. but i got below error. pls suggest Error: creating EC2 Instance: UnauthorizedOperation: You are not authorized to perform this operation. Encoded authorization failure message: jx3jPZ-rb36N6LwLJFtO6vmNpV9eH2o1bwVmEh66ux_cIglZ5hrC3JGyOoknv8ya4chXCQCJX59kjM68Mkze8MbYJgJDA1S0FY-FOIonO7HXIXNhkHK-US5wCd95zWPtBxdF7kfY1PoBoXY9QGrKyHM4Z5mkaOwjYvSdtT5vrP4Vv0uBlzgsCxUWvxR7KAdJbtu-4TJitqQcvEzG_sbDDtes3KyZOrGx6JebzAVKKQlIrw7bc2kYZEksBqwSAc28pbiC-5Mn9d_djgP-NZ4WWmbzeNqDLtt4tIytKYDdfyKmb2PgDNSuqkI3G4ZMXfIWyHCgmBdkP_k3b0d7w49sxbeqtqlnRKBAh-qkovtxqqlIdR7a9lI_E1bGbfvpC2mQIrd2mS_Gcc66hoRkz9kkw_y0yFp4Ut1bfA0CYDWb_D_90cFPSYz5QCIAuKFvu9zNRnsxd4UkdUtXNcDWGzd3e5c9a08QtmxTsoBRSB2nxph-YqDRr8m65wGGAuQMrtUl9ZQRkVNEfZYUh99q-X9zpj_nW4OhGyu6YM1-ZH0nX_F_xXKOALkkR15ijQhikHv8842IM2hX5JENIB2Q6WFEqmTbdrz9A9ly9N0IP_mMTcFe6VYwRtt296g3PEQVsSJRk3fmu7abNFBXuS9jWP4yzNSTQx-dDg status code: 403, request id: 64dcfc82-d4fe-4c29-956f-00bcf4bd2cdb

with aws_instance.public_inst-2,on vpcterraform.tf line 88, in resource "aws_instance" "public_inst-2"88: resource "aws_instance" "public_inst-2" {

mattburgess commented 1 year ago

What does this command reveal:

aws sts decode-authorization-message --encoded-message 'jx3jPZ-rb36N6LwLJFtO6vmNpV9eH2o1bwVmEh66ux_cIglZ5hrC3JGyOoknv8ya4chXCQCJX59kjM68Mkze8MbYJgJDA1S0FY-FOIonO7HXIXNhkHK-US5wCd95zWPtBxdF7kfY1PoBoXY9QGrKyHM4Z5mkaOwjYvSdtT5vrP4Vv0uBlzgsCxUWvxR7KAdJbtu-4TJitqQcvEzG_sbDDtes3KyZOrGx6JebzAVKKQlIrw7bc2kYZEksBqwSAc28pbiC-5Mn9d_djgP-NZ4WWmbzeNqDLtt4tIytKYDdfyKmb2PgDNSuqkI3G4ZMXfIWyHCgmBdkP_k3b0d7w49sxbeqtqlnRKBAh-qkovtxqqlIdR7a9lI_E1bGbfvpC2mQIrd2mS_Gcc66hoRkz9kkw_y0yFp4Ut1bfA0CYDWb_D_90cFPSYz5QCIAuKFvu9zNRnsxd4UkdUtXNcDWGzd3e5c9a08QtmxTsoBRSB2nxph-YqDRr8m65wGGAuQMrtUl9ZQRkVNEfZYUh99q-X9zpj_nW4OhGyu6YM1-ZH0nX_F_xXKOALkkR15ijQhikHv8842IM2hX5JENIB2Q6WFEqmTbdrz9A9ly9N0IP_mMTcFe6VYwRtt296g3PEQVsSJRk3fmu7abNFBXuS9jWP4yzNSTQx-dDg'
muralikrishna9581 commented 1 year ago

ok. you can tell how to do .pls suggest

mattburgess commented 1 year ago

You'll need the AWS CLI tool which you can install following the instructions at https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html. Then just copy and paste the command I wrote above.

muralikrishna9581 commented 1 year ago

ok tq u so much ur hlp