Terraform init fails

terraform {
required_providers {
aws = {
source = “hashicorp/aws”
version = “~>3.0”
}
}
}

configure the ws provider

provider “aws” {
region = “us-east-1”

}
resource “aws_vpc” “MyLab-VPC” {
cidr_block = “172.20.0.0/16”
tags = {
Name = “MyLab-VPC”
}
}

create subnet ( public )

resource “aws_subnet” “MyLab-Subnet1” {
vpc_id = aws_vpc.MyLab-VPC.id
cidr_block = “172.20.10.0/24”
tags = {
Name = “MyLab-Subnet1”
}

}

create internet gateway

resource “aws_internet_gateway” “MyLab-IntGW” {
vpc_id = aws_vpc.MyLab-VPC.id
tags = {
Name = “MyLab-InternetGW”
}

}
resource “security_group” “Mylab_Sec_group” {
name = “MyLab Security Group”
description = “to allow inbound and outbound traffic to mylab”
vpc_id = aws_vpc.MyLab-VPC.id
ingres {
from_port = 22
to_port = 22
protocol = “tcp”
cidr_blocks = [“0.0.0.0/0”]
}

egress {
     from_port = 0 
     to_port = 0 
     protocol = "-1"
     cidr_blocks = ["0.0.0.0/0"]

 }
 
 tags = {
    Name = "allow traffic"
    }

}

terraform init

Initializing the backend…

Initializing provider plugins…

  • Finding hashicorp/aws versions matching “~> 3.0”…
  • Finding latest version of hashicorp/security…
  • Installing hashicorp/aws v3.76.1…
  • Installed hashicorp/aws v3.76.1 (signed by HashiCorp)

    │ Error: Failed to query available provider packages

    │ Could not retrieve the list of available versions for provider hashicorp/security: provider
    │ registry registry.terraform.io does not have a provider named
    Terraform Registry

    │ All modules should specify their required_providers so that external consumers will get the
    │ correct providers when using a module. To see which modules are currently depending on
    │ hashicorp/security, run the following command:
    │ terraform providers

    Not sure from where v3.76.1 is creeping in (kinda - unscope-creeping)

Hi @abhingar :wave:

Did you mean resource "aws_security_group"... and not resource "security_group"...? I think that may be causing your error.

As for the provider version, the AWS provider is now on the major version 5.X. Version 3.76.1 is likely the latest release of the 3.X version, and so is the newest one that meets the requirement you’ve set out in your version constraint (I’m guessing).