provider/aws: Increase AMI destroy timeout (#12943)
* provider/aws: Increase AMI destroy timeout Acceptance tests were timing out on AMI destroy, should alleviate the problem. * Further increase timeout, cleanup test * use function instead of printf
This commit is contained in:
parent
579e15c97c
commit
be2af3f577
|
@ -18,9 +18,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AWSAMIRetryTimeout = 10 * time.Minute
|
AWSAMIRetryTimeout = 10 * time.Minute
|
||||||
AWSAMIRetryDelay = 5 * time.Second
|
AWSAMIDeleteRetryTimeout = 20 * time.Minute
|
||||||
AWSAMIRetryMinTimeout = 3 * time.Second
|
AWSAMIRetryDelay = 5 * time.Second
|
||||||
|
AWSAMIRetryMinTimeout = 3 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func resourceAwsAmi() *schema.Resource {
|
func resourceAwsAmi() *schema.Resource {
|
||||||
|
@ -329,7 +330,7 @@ func resourceAwsAmiWaitForDestroy(id string, client *ec2.EC2) error {
|
||||||
Pending: []string{"available", "pending", "failed"},
|
Pending: []string{"available", "pending", "failed"},
|
||||||
Target: []string{"destroyed"},
|
Target: []string{"destroyed"},
|
||||||
Refresh: AMIStateRefreshFunc(client, id),
|
Refresh: AMIStateRefreshFunc(client, id),
|
||||||
Timeout: AWSAMIRetryTimeout,
|
Timeout: AWSAMIDeleteRetryTimeout,
|
||||||
Delay: AWSAMIRetryDelay,
|
Delay: AWSAMIRetryDelay,
|
||||||
MinTimeout: AWSAMIRetryTimeout,
|
MinTimeout: AWSAMIRetryTimeout,
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"github.com/aws/aws-sdk-go/aws"
|
"github.com/aws/aws-sdk-go/aws"
|
||||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||||
"github.com/aws/aws-sdk-go/service/ec2"
|
"github.com/aws/aws-sdk-go/service/ec2"
|
||||||
|
"github.com/hashicorp/terraform/helper/acctest"
|
||||||
"github.com/hashicorp/terraform/helper/resource"
|
"github.com/hashicorp/terraform/helper/resource"
|
||||||
"github.com/hashicorp/terraform/terraform"
|
"github.com/hashicorp/terraform/terraform"
|
||||||
)
|
)
|
||||||
|
@ -16,13 +17,14 @@ import (
|
||||||
func TestAccAWSAMIFromInstance(t *testing.T) {
|
func TestAccAWSAMIFromInstance(t *testing.T) {
|
||||||
var amiId string
|
var amiId string
|
||||||
snapshots := []string{}
|
snapshots := []string{}
|
||||||
|
rInt := acctest.RandInt()
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSAMIFromInstanceConfig,
|
Config: testAccAWSAMIFromInstanceConfig(rInt),
|
||||||
Check: func(state *terraform.State) error {
|
Check: func(state *terraform.State) error {
|
||||||
rs, ok := state.RootModule().Resources["aws_ami_from_instance.test"]
|
rs, ok := state.RootModule().Resources["aws_ami_from_instance.test"]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -51,13 +53,13 @@ func TestAccAWSAMIFromInstance(t *testing.T) {
|
||||||
|
|
||||||
image := describe.Images[0]
|
image := describe.Images[0]
|
||||||
if expected := "available"; *image.State != expected {
|
if expected := "available"; *image.State != expected {
|
||||||
return fmt.Errorf("invalid image state; expected %v, got %v", expected, image.State)
|
return fmt.Errorf("invalid image state; expected %v, got %v", expected, *image.State)
|
||||||
}
|
}
|
||||||
if expected := "machine"; *image.ImageType != expected {
|
if expected := "machine"; *image.ImageType != expected {
|
||||||
return fmt.Errorf("wrong image type; expected %v, got %v", expected, image.ImageType)
|
return fmt.Errorf("wrong image type; expected %v, got %v", expected, *image.ImageType)
|
||||||
}
|
}
|
||||||
if expected := "terraform-acc-ami-from-instance"; *image.Name != expected {
|
if expected := fmt.Sprintf("terraform-acc-ami-from-instance-%d", rInt); *image.Name != expected {
|
||||||
return fmt.Errorf("wrong name; expected %v, got %v", expected, image.Name)
|
return fmt.Errorf("wrong name; expected %v, got %v", expected, *image.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, bdm := range image.BlockDeviceMappings {
|
for _, bdm := range image.BlockDeviceMappings {
|
||||||
|
@ -137,24 +139,25 @@ func TestAccAWSAMIFromInstance(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var testAccAWSAMIFromInstanceConfig = `
|
func testAccAWSAMIFromInstanceConfig(rInt int) string {
|
||||||
provider "aws" {
|
return fmt.Sprintf(`
|
||||||
region = "us-east-1"
|
provider "aws" {
|
||||||
}
|
region = "us-east-1"
|
||||||
|
}
|
||||||
|
|
||||||
resource "aws_instance" "test" {
|
resource "aws_instance" "test" {
|
||||||
// This AMI has one block device mapping, so we expect to have
|
// This AMI has one block device mapping, so we expect to have
|
||||||
// one snapshot in our created AMI.
|
// one snapshot in our created AMI.
|
||||||
ami = "ami-408c7f28"
|
ami = "ami-408c7f28"
|
||||||
instance_type = "t1.micro"
|
instance_type = "t1.micro"
|
||||||
tags {
|
tags {
|
||||||
Name = "testAccAWSAMIFromInstanceConfig_TestAMI"
|
Name = "testAccAWSAMIFromInstanceConfig_TestAMI"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resource "aws_ami_from_instance" "test" {
|
resource "aws_ami_from_instance" "test" {
|
||||||
name = "terraform-acc-ami-from-instance"
|
name = "terraform-acc-ami-from-instance-%d"
|
||||||
description = "Testing Terraform aws_ami_from_instance resource"
|
description = "Testing Terraform aws_ami_from_instance resource"
|
||||||
source_instance_id = "${aws_instance.test.id}"
|
source_instance_id = "${aws_instance.test.id}"
|
||||||
|
}`, rInt)
|
||||||
}
|
}
|
||||||
`
|
|
||||||
|
|
Loading…
Reference in New Issue