Failed to connect to repository : Error performing git command: git ls-remote -h https://[email protected]/ssabuthagir/devops.git

Hi  Guys, We are going to give a solution for below error while adding git repository in Jenkins

Failed to connect to repository : Error performing git command: git ls-remote -h https://[email protected]/ssabuthagir/devops.git HEAD

Mostly  we will find this error while adding git repository  in Jenkins.

Basically to integrate any tool with Jenkins, we have to install respective plugins. But, for git it is already installed when we initiate “Install Suggested plugin” option when we login first time in Jenkins dashboard after Installation & Configuration of Jenkins.

Now will come to solution for this error.

Solutions 1: 

Basically git should be installed in same server where the Jenkins installed & configured.

Because while adding our git repo Jenkins will issue git command to check whether that repo is accessible or not by using below command

git ls-remote -h <git_repo_url>

this command will not work when we use this on server which is not installed with git. Because in Jenkins we need to provide git path even if it is installed or still getting error.

Solutions 1: 

Below is the location where need to mention the path in Jenkins

Goto -> <Jenkins_URL> -> Dashboard -> Tools -> Git Installation

Under “Git Installation” git will mentioned in a text box there we need to provide the git absolute path

Then Apply & Save

Failed to connect repoFailed to connect repo

 

Failed to connect repoThanks for reading this post. Expecting your support in future too.

 

A managed resource “aws_subnet” “pubsubnet” has not been declared in the root module.

Hi Techies,

We are going to see how to resolve ‘A managed resource “aws_subnet” “pubsubnet” has not been declared in the root module.’  error while using terraform to create 2 EC2 instance with VPC in AWS

code:

resource "aws_instance" "pub_instance" {
ami = "ami-033fabdd332044f06"
instance_type = "t2.micro"
availability_zone = "us-east-2a"
associate_public_ip_address = "true"
vpc_security_group_ids = [aws_security_group.PUBSG.id]
subnet_id = aws_subnet.pubsubnet.id
key_name = "Terraform_Srv"

tags = {
Name = "WEBSERVER"
}

}

resource "aws_instance" "pvt_instance" {
ami = "ami-033fabdd332044f06"
instance_type = "t2.micro"
availability_zone = "us-east-2b"
associate_public_ip_address = "true"
vpc_security_group_ids = [aws_security_group.PVTSG.id]
subnet_id = aws_subnet.pvtsubnet.id
key_name = "Terraform_Srv"

tags = {
Name = "APPSERVER"
}

Error:

[root@ip-172-31-7-226 terraform]# terraform apply
╷
│ Error: Reference to undeclared resource
│
│ on main.tf line 163, in resource "aws_instance" "pub_instance":
│ 163: subnet_id = aws_subnet.pubsubnet.id
│
│ A managed resource "aws_subnet" "pubsubnet" has not been declared in the root module.
╵
╷
│ Error: Reference to undeclared resource
│
│ on main.tf line 178, in resource "aws_instance" "pvt_instance":
│ 178: subnet_id = aws_subnet.pvtsubnet.id
│
│ A managed resource "aws_subnet" "pvtsubnet" has not been declared in the root module.

After checking the full code of script, found that I have declared the names like PUBSUB & PVTSUB for public and private subnet wiseversa.

But I wrongly mentioned like pubsubnet & pvtsubnet in the EC2 instance creation. So, after renaming it to correctly like below it is fixed.

subnet_id = aws_subnet.pubsubnet.id
subnet_id = aws_subnet.pubsubnet.id

modified like below based on the declared name inn previous code

subnet_id = aws_subnet.PUBSUB.id
subnet_id = aws_subnet.PVTSUB.id

Result:

After changing the error was fixed and find the below result

aws_instance.pvt_instance: Creating...
aws_instance.pub_instance: Creating...
aws_route_table.PVTRT: Modifying... [id=rtb-05ab30d4598210e59]
aws_route_table.PVTRT: Modifications complete after 0s [id=rtb-05ab30d4598210e59]
aws_instance.pub_instance: Still creating... [10s elapsed]
aws_instance.pvt_instance: Still creating... [10s elapsed]
aws_instance.pvt_instance: Still creating... [20s elapsed]
aws_instance.pub_instance: Still creating... [20s elapsed]
aws_instance.pub_instance: Still creating... [30s elapsed]
aws_instance.pvt_instance: Still creating... [30s elapsed]
aws_instance.pvt_instance: Creation complete after 31s [id=i-096c28fbbaeff8a42]
aws_instance.pub_instance: Creation complete after 31s [id=i-0f745c3aeca6327aa]

Apply complete! Resources: 2 added, 1 changed, 0 destroyed.
[root@ip-172-31-7-226 terraform]#

Error: creating EC2 Instance: operation error EC2: Run Instances, https response error StatusCode: 400, error InvalidSubnetID.NotFound: The subnet ID ‘aws_subnet.pubsubnet.id’ does not exist

Hi Techies!

Good day!

We are going to see how to troubleshoot issues in terraform(Alternate Ansible) script which will create VPC in AWS.

In my script the file name is main.tf and we need to execute “terraform init, terraform validate, terraform apply” commands one by one.

terraform init:   It will initialize the directory, which will contains the terraform configuration file(in our scenario main.tf)

terraform validate: It will to check the syntax and consistency of your Terraform configuration files without accessing remote services

terraform plan: It will help to create an execution plan and preview the changes to your infrastructure.

terraform apply: It will execute the proposed actions in a Terraform plan.

In our scenario I’m getting error while applying it (terraform apply)

Error:

Error: creating EC2 Instance: operation error EC2: RunInstances, https response error StatusCode: 400, RequestID: 5eea2384-64e8-4a57-ba1a-2ac955c799f9, api error InvalidSubnetID.NotFound: The subnet ID 'aws_subnet.pubsubnet.id' does not exist
│
│ with aws_instance.pub_instance,
│ on main.tf line 157, in resource "aws_instance" "pub_instance":
│ 157: resource "aws_instance" "pub_instance" {
│
╵
╷
│ Error: creating EC2 Instance: operation error EC2: RunInstances, https response error StatusCode: 400, RequestID: 64d5c412-e7db-49ad-a7aa-49b4f9345d89, api error InvalidSubnetID.NotFound: The subnet ID 'aws_subnet.pvtsubnet.id' does not exist
│
│ with aws_instance.pvt_instance,
│ on main.tf line 172, in resource "aws_instance" "pvt_instance":
│ 172: resource "aws_instance" "pvt_instance" {

Code in my script:

 resource "aws_instance" "pub_instance" {
ami                                     = "ami-033fabdd332044f06"
instance_type                           = "t2.micro"
availability_zone                       = "us-east-2a"
associate_public_ip_address             = "true"
vpc_security_group_ids                  = [aws_security_group.PUBSG.id]
subnet_id                               = "aws_subnet.PUBSUB.id"
key_name                                = "Terraform_Srv"

  tags = {
  Name = "WEBSERVER"
 }

}

resource "aws_instance" "pvt_instance" {
ami                                     = "ami-033fabdd332044f06"
instance_type                           = "t2.micro"
availability_zone                       = "us-east-2b"
associate_public_ip_address             = "true"
vpc_security_group_ids                  = [aws_security_group.PVTSG.id]
subnet_id                               = "aws_subnet.PVTSUB.id"
key_name                                = "Terraform_Srv"

  tags = {
  Name = "APPSERVER"
 }

}

Solution:

In may script I have used double quotes (“”) to mention subnet id. In my case I have removed double quotes and it fixed the issue.

resource "aws_instance" "pub_instance" {
ami                                    = "ami-033fabdd332044f06"
instance_type                          = "t2.micro"
availability_zone                      = "us-east-2a"
associate_public_ip_address            = "true"
vpc_security_group_ids                 = [aws_security_group.PUBSG.id]
subnet_id                              = aws_subnet.PUBSUB.id
key_name                               = "Terraform_Srv"

tags = {
Name = "WEBSERVER"
}

}

resource "aws_instance" "pvt_instance" {
ami                                    = "ami-033fabdd332044f06"
instance_type                          = "t2.micro"
availability_zone                      = "us-east-2b"
associate_public_ip_address            = "true"
vpc_security_group_ids                 = [aws_security_group.PVTSG.id]
subnet_id                              = aws_subnet.PVTSUB.id
key_name                               = "Terraform_Srv"

tags = {
Name = "APPSERVER"
}

}

Now while executing “terraform apply” it created ec2-instance along with VPC successfully.

Result:

#terraform apply

aws_instance.pvt_instance: Creating...
aws_instance.pub_instance: Creating...
aws_route_table.PVTRT: Modifying... [id=rtb-05ab30d4598210e59]
aws_route_table.PVTRT: Modifications complete after 0s [id=rtb-05ab30d4598210e59]
aws_instance.pub_instance: Still creating... [10s elapsed]
aws_instance.pvt_instance: Still creating... [10s elapsed]
aws_instance.pvt_instance: Still creating... [20s elapsed]
aws_instance.pub_instance: Still creating... [20s elapsed]
aws_instance.pub_instance: Still creating... [30s elapsed]
aws_instance.pvt_instance: Still creating... [30s elapsed]
aws_instance.pvt_instance: Creation complete after 31s [id=i-096c28fbbaeff8a42]
aws_instance.pub_instance: Creation complete after 31s [id=i-0f745c3aeca6327aa]
Apply complete! Resources: 2 added, 1 changed, 0 destroyed.
[root@ip-172-31-7-226 terraform]#