2015-04-23 20:35:51 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2015-05-23 00:02:05 +02:00
|
|
|
"fmt"
|
2015-04-23 20:35:51 +02:00
|
|
|
"testing"
|
|
|
|
|
2015-06-03 20:36:57 +02:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2015-04-23 20:35:51 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
2015-05-23 00:02:05 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2015-04-23 20:35:51 +02:00
|
|
|
)
|
|
|
|
|
2015-06-08 01:18:14 +02:00
|
|
|
func TestAccAWSEBSVolume_basic(t *testing.T) {
|
2015-05-23 00:02:05 +02:00
|
|
|
var v ec2.Volume
|
2015-04-23 20:35:51 +02:00
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAwsEbsVolumeConfig,
|
2015-05-23 00:02:05 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckVolumeExists("aws_ebs_volume.test", &v),
|
|
|
|
),
|
2015-04-23 20:35:51 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-12-07 21:49:44 +01:00
|
|
|
func TestAccAWSEBSVolume_NoIops(t *testing.T) {
|
2015-12-07 18:16:29 +01:00
|
|
|
var v ec2.Volume
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
2015-12-07 21:49:44 +01:00
|
|
|
Config: testAccAwsEbsVolumeConfigWithNoIops,
|
2015-12-07 18:16:29 +01:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckVolumeExists("aws_ebs_volume.iops_test", &v),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-29 09:05:21 +02:00
|
|
|
func TestAccAWSEBSVolume_withTags(t *testing.T) {
|
|
|
|
var v ec2.Volume
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAwsEbsVolumeConfigWithTags,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckVolumeExists("aws_ebs_volume.tags_test", &v),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2015-05-23 00:02:05 +02:00
|
|
|
func testAccCheckVolumeExists(n string, v *ec2.Volume) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("No ID is set")
|
|
|
|
}
|
|
|
|
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
|
|
|
|
|
|
|
request := &ec2.DescribeVolumesInput{
|
2015-08-17 20:27:16 +02:00
|
|
|
VolumeIds: []*string{aws.String(rs.Primary.ID)},
|
2015-05-23 00:02:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
response, err := conn.DescribeVolumes(request)
|
|
|
|
if err == nil {
|
|
|
|
if response.Volumes != nil && len(response.Volumes) > 0 {
|
|
|
|
*v = *response.Volumes[0]
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Errorf("Error finding EC2 volume %s", rs.Primary.ID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 20:35:51 +02:00
|
|
|
const testAccAwsEbsVolumeConfig = `
|
|
|
|
resource "aws_ebs_volume" "test" {
|
2015-05-06 16:22:34 +02:00
|
|
|
availability_zone = "us-west-2a"
|
2015-04-23 20:35:51 +02:00
|
|
|
size = 1
|
|
|
|
}
|
|
|
|
`
|
2015-05-29 09:05:21 +02:00
|
|
|
|
|
|
|
const testAccAwsEbsVolumeConfigWithTags = `
|
|
|
|
resource "aws_ebs_volume" "tags_test" {
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
size = 1
|
|
|
|
tags {
|
|
|
|
Name = "TerraformTest"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2015-12-07 18:16:29 +01:00
|
|
|
|
2015-12-07 21:49:44 +01:00
|
|
|
const testAccAwsEbsVolumeConfigWithNoIops = `
|
2015-12-07 18:16:29 +01:00
|
|
|
resource "aws_ebs_volume" "iops_test" {
|
|
|
|
availability_zone = "us-west-2a"
|
|
|
|
size = 10
|
|
|
|
type = "gp2"
|
|
|
|
iops = 0
|
|
|
|
tags {
|
|
|
|
Name = "TerraformTest"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|