2016-03-07 21:42:30 +01:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
|
|
|
"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
|
2016-03-21 17:39:51 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/acctest"
|
2016-03-07 21:42:30 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAWSBeanstalkConfigurationTemplate_basic(t *testing.T) {
|
|
|
|
var config elasticbeanstalk.ConfigurationSettingsDescription
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckBeanstalkConfigurationTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccBeanstalkConfigurationTemplateConfig,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckBeanstalkConfigurationTemplateExists("aws_elastic_beanstalk_configuration_template.tf_template", &config),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:39:51 +01:00
|
|
|
func TestAccAWSBeanstalkConfigurationTemplate_VPC(t *testing.T) {
|
|
|
|
var config elasticbeanstalk.ConfigurationSettingsDescription
|
|
|
|
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckBeanstalkConfigurationTemplateDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccBeanstalkConfigurationTemplateConfig_VPC(acctest.RandString(5)),
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckBeanstalkConfigurationTemplateExists("aws_elastic_beanstalk_configuration_template.tf_template", &config),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2016-03-07 21:42:30 +01:00
|
|
|
func testAccCheckBeanstalkConfigurationTemplateDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_elastic_beanstalk_configuration_template" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to find the Configuration Template
|
|
|
|
opts := elasticbeanstalk.DescribeConfigurationSettingsInput{
|
|
|
|
TemplateName: aws.String(rs.Primary.ID),
|
|
|
|
ApplicationName: aws.String(rs.Primary.Attributes["application"]),
|
|
|
|
}
|
|
|
|
resp, err := conn.DescribeConfigurationSettings(&opts)
|
|
|
|
if err == nil {
|
|
|
|
if len(resp.ConfigurationSettings) > 0 {
|
|
|
|
return fmt.Errorf("Elastic Beanstalk Application still exists.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify the error is what we want
|
|
|
|
ec2err, ok := err.(awserr.Error)
|
|
|
|
if !ok {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
switch {
|
|
|
|
case ec2err.Code() == "InvalidBeanstalkConfigurationTemplateID.NotFound":
|
|
|
|
return nil
|
|
|
|
// This error can be returned when the beanstalk application no longer exists.
|
|
|
|
case ec2err.Code() == "InvalidParameterValue":
|
|
|
|
return nil
|
|
|
|
default:
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckBeanstalkConfigurationTemplateExists(n string, config *elasticbeanstalk.ConfigurationSettingsDescription) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn
|
|
|
|
rs, ok := s.RootModule().Resources[n]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", n)
|
|
|
|
}
|
|
|
|
|
|
|
|
if rs.Primary.ID == "" {
|
|
|
|
return fmt.Errorf("Elastic Beanstalk config ID is not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
opts := elasticbeanstalk.DescribeConfigurationSettingsInput{
|
|
|
|
TemplateName: aws.String(rs.Primary.ID),
|
|
|
|
ApplicationName: aws.String(rs.Primary.Attributes["application"]),
|
|
|
|
}
|
|
|
|
resp, err := conn.DescribeConfigurationSettings(&opts)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(resp.ConfigurationSettings) == 0 {
|
|
|
|
return fmt.Errorf("Elastic Beanstalk Configurations not found.")
|
|
|
|
}
|
|
|
|
|
|
|
|
*config = *resp.ConfigurationSettings[0]
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testAccBeanstalkConfigurationTemplateConfig = `
|
|
|
|
resource "aws_elastic_beanstalk_application" "tftest" {
|
|
|
|
name = "tf-test-name"
|
|
|
|
description = "tf-test-desc"
|
|
|
|
}
|
|
|
|
|
|
|
|
#resource "aws_elastic_beanstalk_environment" "tfenvtest" {
|
|
|
|
# name = "tf-test-name"
|
|
|
|
# application = "${aws_elastic_beanstalk_application.tftest.name}"
|
|
|
|
# solution_stack_name = "64bit Amazon Linux 2015.03 v2.0.3 running Go 1.4"
|
|
|
|
#}
|
|
|
|
|
|
|
|
resource "aws_elastic_beanstalk_configuration_template" "tf_template" {
|
|
|
|
name = "tf-test-template-config"
|
|
|
|
application = "${aws_elastic_beanstalk_application.tftest.name}"
|
|
|
|
solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.8 running Go 1.4"
|
|
|
|
}
|
|
|
|
`
|
2016-03-21 17:39:51 +01:00
|
|
|
|
|
|
|
func testAccBeanstalkConfigurationTemplateConfig_VPC(name string) string {
|
|
|
|
return fmt.Sprintf(`
|
|
|
|
resource "aws_vpc" "tf_b_test" {
|
|
|
|
cidr_block = "10.0.0.0/16"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "beanstalk_crash"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_subnet" "main" {
|
|
|
|
vpc_id = "${aws_vpc.tf_b_test.id}"
|
|
|
|
cidr_block = "10.0.0.0/24"
|
|
|
|
|
|
|
|
tags {
|
|
|
|
Name = "subnet-count-test"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elastic_beanstalk_application" "tftest" {
|
|
|
|
name = "tf-test-%s"
|
|
|
|
description = "tf-test-desc"
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "aws_elastic_beanstalk_configuration_template" "tf_template" {
|
|
|
|
name = "tf-test-%s"
|
|
|
|
application = "${aws_elastic_beanstalk_application.tftest.name}"
|
|
|
|
|
|
|
|
solution_stack_name = "64bit Amazon Linux 2015.03 v2.0.3 running Go 1.4"
|
|
|
|
|
|
|
|
setting {
|
|
|
|
namespace = "aws:ec2:vpc"
|
|
|
|
name = "VPCId"
|
|
|
|
value = "${aws_vpc.tf_b_test.id}"
|
|
|
|
}
|
|
|
|
|
|
|
|
setting {
|
|
|
|
namespace = "aws:ec2:vpc"
|
|
|
|
name = "Subnets"
|
|
|
|
value = "${aws_subnet.main.id}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, name, name)
|
|
|
|
}
|