From 9ae8e85640f4a3f5faeb94ff7f96236b46758ba2 Mon Sep 17 00:00:00 2001 From: clint shryock Date: Mon, 21 Mar 2016 11:39:51 -0500 Subject: [PATCH] provider/aws: Fix crasher in Elastic Beanstalk Configuration with option settings --- ...lastic_beanstalk_configuration_template.go | 30 ++------- ...c_beanstalk_configuration_template_test.go | 64 +++++++++++++++++++ ...stalk_configuration_template.html.markdown | 12 +++- 3 files changed, 79 insertions(+), 27 deletions(-) diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template.go index eff6535e94..1f3f91e84b 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template.go @@ -4,7 +4,6 @@ import ( "fmt" "log" - "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" "github.com/aws/aws-sdk-go/aws" @@ -38,26 +37,12 @@ func resourceAwsElasticBeanstalkConfigurationTemplate() *schema.Resource { Optional: true, ForceNew: true, }, - "option_settings": &schema.Schema{ + "setting": &schema.Schema{ Type: schema.TypeSet, Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "namespace": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - }, - "option_name": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - }, - "value": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - }, - }, - }, - Set: optionSettingHash, + Computed: true, + Elem: resourceAwsElasticBeanstalkOptionSetting(), + Set: optionSettingValueHash, }, "solution_stack_name": &schema.Schema{ Type: schema.TypeString, @@ -225,13 +210,6 @@ func resourceAwsElasticBeanstalkConfigurationTemplateDelete(d *schema.ResourceDa return err } -func optionSettingHash(v interface{}) int { - rd := v.(*schema.ResourceData) - namespace := rd.Get("namespace").(string) - optionName := rd.Get("option_name").(string) - return hashcode.String(fmt.Sprintf("%s.%s", namespace, optionName)) -} - func gatherOptionSettings(d *schema.ResourceData) []*elasticbeanstalk.ConfigurationOptionSetting { optionSettingsSet, ok := d.Get("option_settings").(*schema.Set) if !ok || optionSettingsSet == nil { diff --git a/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go b/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go index 0d0ec4c0af..4aedf82b15 100644 --- a/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go +++ b/builtin/providers/aws/resource_aws_elastic_beanstalk_configuration_template_test.go @@ -7,6 +7,7 @@ import ( "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/service/elasticbeanstalk" + "github.com/hashicorp/terraform/helper/acctest" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -29,6 +30,24 @@ func TestAccAWSBeanstalkConfigurationTemplate_basic(t *testing.T) { }) } +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), + ), + }, + }, + }) +} + func testAccCheckBeanstalkConfigurationTemplateDestroy(s *terraform.State) error { conn := testAccProvider.Meta().(*AWSClient).elasticbeanstalkconn @@ -119,3 +138,48 @@ resource "aws_elastic_beanstalk_configuration_template" "tf_template" { solution_stack_name = "64bit Amazon Linux 2015.09 v2.0.8 running Go 1.4" } ` + +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) +} diff --git a/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown b/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown index 02d0be496c..a493f58ff4 100644 --- a/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown +++ b/website/source/docs/providers/aws/r/elastic_beanstalk_configuration_template.html.markdown @@ -36,13 +36,23 @@ The following arguments are supported: * `application` – (Required) name of the application to associate with this configuration template * `description` - (Optional) Short description of the Template * `environment_id` – (Optional) The ID of the environment used with this configuration template -* `option_settings` – (Optional) Option settings to configure the new Environment. These +* `setting` – (Optional) Option settings to configure the new Environment. These override specific values that are set as defaults. The format is detailed below in [Option Settings](#option-settings) * `solution_stack_name` – (Optional) A solution stack to base your Template off of. Example stacks can be found in the [Amazon API documentation][1] + +## Option Settings + +The `setting` field supports the following format: + +* `namespace` - (Optional) unique namespace identifying the option's + associated AWS resource +* `name` - (Optional) name of the configuration option +* `value` - (Optional) value for the configuration option + ## Attributes Reference The following attributes are exported: