Showing posts with label Terraform. Show all posts
Showing posts with label Terraform. Show all posts

Thursday, February 10, 2022

Terraform Error: Failed to query available provider packages

Terraform error when executing terraform init command

 Terraform Error: Failed to query available provider packages

Could not retrieve the list of available versions for provider hashicorp/oci: no available releases match the given constraints >= 4.41.0, ~> 4.59.0


Background:

I got a working terraform project from a friend, when I tried to run in my environment, I am getting this error.


My development environment is oracle developer instance, which is already packed with terraform.


After copying the terraform project, I am trying to do a terraform init


[root@shivin-dev-sg terraform]# terraform init

Initializing modules...

Downloading registry.terraform.io/oracle-terraform-modules/vcn/oci 3.2.0 for vcn...

- vcn in .terraform/modules/vcn

- vcn.drg_from_vcn_module in .terraform/modules/vcn/modules/drg


Initializing the backend...


Initializing provider plugins...

- Finding hashicorp/kubernetes versions matching "~> 2.4.1"...

- Finding latest version of hashicorp/local...

- Finding hashicorp/oci versions matching ">= 4.41.0, ~> 4.59.0"...

- Installing hashicorp/kubernetes v2.4.1...

- Installed hashicorp/kubernetes v2.4.1 (signed by HashiCorp)

- Installing hashicorp/local v2.1.0...

- Installed hashicorp/local v2.1.0 (signed by HashiCorp)

Error: Failed to query available provider packages

 

Could not retrieve the list of available versions for provider hashicorp/oci: no available releases match the given constraints >= 4.41.0, ~> 4.59.0


[root@shivin-dev-sg terraform]#


What is the issue and how to fix it?


As you can see from the initalizing provider plugins part, the oci plugin version is 4.41.0 but in our provider.tf the version is 4.59.0. This means somewhere in my machine there is a plugin cache. I need to find delete it for fixing this issue.


Steps to solve the issue:


cd /usr/share/terraform/

rm -rf plugins


cd /root

rm -rf .terraform


cd /path-to-your-terraform

rm -rf .terraform.d


Now, do a terraform init, it will works!!

Sunday, March 15, 2020

Terraform for Absolute Beginners - Create your first EC2 instance

Objective : Today, I will help you to create your EC2 instance using terraform.

Terraform

Terraform is an Infrastructure as code (IaC) tool made by Hashicorp for building, changing and versioning of infrastructures. Now a days the demand of Terraform is getting higher. Terraform can be used with the popular cloud providers like AWS, Azure, Google, Oracle etc.

Pre Request

You need a user in AWS, having necessary permissions to create an EC2 instance.
(Please check our blogs/videos, how to add permission for an AWS user)

Steps to Provision

  1. Download the terraform binary file from https://www.terraform.io/downloads.html
  2. Extract the terraform zip file
  3. The result is a terraform binary file
  4. cp terraform /usr/local/bin/terraform
  5. Validate terraform by using the command terraform -v

Minimal configuration for starting EC2 instance

mkdir terraform-workshop
cd terraform-workshop
vi ec2.tf


provider "aws" {
access_key = "YOUR_ACCESS_KEY"
secret_key = "YOUR_SECRET_KEY"
region = "us-east-1"
}

resource "aws_instance" "example_ec2" {
ami = "ami-2757f631"
instance_type = "t2.micro"
}

Save the file. 
You will get your AWS access_key and secret_key as a pre-request.

terraform init
terraform apply

Login to your AWS console and check the EC2 instance under N. Virginia region.

terraform destroy

Will make sure to remove all the AWS resources which we created just above.