Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidInstanceID: Not found error #1108

Open
iamdheee opened this issue Apr 21, 2022 · 3 comments
Open

InvalidInstanceID: Not found error #1108

iamdheee opened this issue Apr 21, 2022 · 3 comments
Labels
awaiting response Waiting for a response or more data from issue reporter question

Comments

@iamdheee
Copy link

could someone help fix this, please?

ec2.go:284:
Error Trace: ec2.go:284
terraform_aws_example_test.go:46
Error: Received unexpected error:
InvalidInstanceID.NotFound: The instance ID 'i-00b2e1ecef37b5674' does not exist
status code: 400, request id: 1692c5cc-aa41-49bc-8478-fb1e6197aedb

@denis256
Copy link
Member

Hi,
can be provided more details when this issue occurs, example test code that generates this error.
terraform_aws_example_test.go:46 terratest repository points to EnvVars declaration from TestTerraformAwsExample which executed locally successfully pass

https://github.com/gruntwork-io/terratest/blob/master/test/terraform_aws_example_test.go#L46

@denis256 denis256 added question awaiting response Waiting for a response or more data from issue reporter labels Apr 22, 2022
@iamdheee
Copy link
Author

iamdheee commented Apr 25, 2022

main.tf:

terraform {
required_version = ">=1.0.11"
}

resource "aws_instance" "example" {
ami = data.aws_ami.ubuntu.id
instance_type = var.instance_type
tags = {
Name = var.instance_name
}

}

data "aws_ami" "ubuntu" {
most_recent = true
owners = ["099720109477"] # Canonical

filter {
name = "virtualization-type"
values = ["hvm"]
}

filter {
name = "architecture"
values = ["x86_64"]
}

filter {
name = "image-type"
values = ["machine"]
}

filter {
name = "name"
values = ["ubuntu/images/hvm-ssd/ubuntu-xenial-16.04-amd64-server-*"]
}
}


package test

import (
"fmt"
"testing"

"github.com/gruntwork-io/terratest/modules/aws"
"github.com/gruntwork-io/terratest/modules/random"
"github.com/gruntwork-io/terratest/modules/terraform"
    "github.com/stretchr/testify/assert"

)

func TestTerraformAWSPublicIp(t *testing.T) {
t.Parallel()

expectedName := fmt.Sprintf("terratest-aws-example-%s", random.UniqueId())

awsRegion := aws.GetRandomStableRegion(t, []string{"us-east-2"}, nil)

instanceType := aws.GetRecommendedInstanceType(t, awsRegion, []string{"t2.micro"})

terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
	TerraformDir: "",

	Vars: map[string]interface{}{
		"instance_name": expectedName,
		"instance_type": instanceType,
	},

	EnvVars: map[string]string{
		"AWS_DEFAULT_REGION": awsRegion,
	},
})

defer terraform.Destroy(t, terraformOptions)

terraform.InitAndApply(t, terraformOptions)

instanceID := terraform.Output(t, terraformOptions, "instance_id")

aws.AddTagsToResource(t, awsRegion, instanceID, map[string]string{"testing": "testing-tag-value"})

// Look up the tags for the given Instance ID
instanceTags := aws.GetTagsForEc2Instance(t, awsRegion, instanceID)

// website::tag::3::Check if the EC2 instance with a given tag and name is set.
testingTag, containsTestingTag := instanceTags["testing"]
assert.True(t, containsTestingTag)
assert.Equal(t, "testing-tag-value", testingTag)

// Verify that our expected name tag is one of the tags
nameTag, containsNameTag := instanceTags["Name"]
assert.True(t, containsNameTag)
assert.Equal(t, expectedName, nameTag)

}

@denis256 above s' the code that's throwing the following error for me:
ec2.go:284:
Error Trace: ec2.go:284
terraform_aws_example_test.go:46
Error: Received unexpected error:
InvalidInstanceID.NotFound: The instance ID 'i-05fa469159206b1b5' does not exist
status code: 400, request id: bb255e1e-c7b0-4f9a-ad90-ea63a9a014d4

@iamdheee
Copy link
Author

im still unable to get thru my tests without errors.. Could you please help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Waiting for a response or more data from issue reporter question
Projects
None yet
Development

No branches or pull requests

2 participants