provider/aws: import Elastic Beanstalk Application and Environment (#7444)
This commit is contained in:
parent
480542d2ab
commit
c744bb6fa8
|
@ -0,0 +1,28 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAWSElasticBeanstalkApplication_importBasic(t *testing.T) {
|
||||
resourceName := "aws_elastic_beanstalk_application.tftest"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckBeanstalkAppDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccBeanstalkAppConfig,
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAWSElasticBeanstalkEnvironment_importBasic(t *testing.T) {
|
||||
resourceName := "aws_elastic_beanstalk_application.tftest"
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccCheckBeanstalkAppDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccBeanstalkEnvConfig,
|
||||
},
|
||||
|
||||
resource.TestStep{
|
||||
ResourceName: resourceName,
|
||||
ImportState: true,
|
||||
ImportStateVerify: true,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
|
@ -19,6 +19,9 @@ func resourceAwsElasticBeanstalkApplication() *schema.Resource {
|
|||
Read: resourceAwsElasticBeanstalkApplicationRead,
|
||||
Update: resourceAwsElasticBeanstalkApplicationUpdate,
|
||||
Delete: resourceAwsElasticBeanstalkApplicationDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
|
@ -94,6 +97,7 @@ func resourceAwsElasticBeanstalkApplicationRead(d *schema.ResourceData, meta int
|
|||
return err
|
||||
}
|
||||
|
||||
d.Set("name", a.ApplicationName)
|
||||
d.Set("description", a.Description)
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@ func resourceAwsElasticBeanstalkEnvironment() *schema.Resource {
|
|||
Read: resourceAwsElasticBeanstalkEnvironmentRead,
|
||||
Update: resourceAwsElasticBeanstalkEnvironmentUpdate,
|
||||
Delete: resourceAwsElasticBeanstalkEnvironmentDelete,
|
||||
Importer: &schema.ResourceImporter{
|
||||
State: schema.ImportStatePassthrough,
|
||||
},
|
||||
|
||||
SchemaVersion: 1,
|
||||
MigrateState: resourceAwsElasticBeanstalkEnvironmentMigrateState,
|
||||
|
@ -339,15 +342,12 @@ func resourceAwsElasticBeanstalkEnvironmentUpdate(d *schema.ResourceData, meta i
|
|||
func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).elasticbeanstalkconn
|
||||
|
||||
app := d.Get("application").(string)
|
||||
envId := d.Id()
|
||||
tier := d.Get("tier").(string)
|
||||
|
||||
log.Printf("[DEBUG] Elastic Beanstalk environment read %s: id %s", d.Get("name").(string), d.Id())
|
||||
|
||||
resp, err := conn.DescribeEnvironments(&elasticbeanstalk.DescribeEnvironmentsInput{
|
||||
ApplicationName: aws.String(app),
|
||||
EnvironmentIds: []*string{aws.String(envId)},
|
||||
EnvironmentIds: []*string{aws.String(envId)},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
|
@ -380,6 +380,14 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int
|
|||
return err
|
||||
}
|
||||
|
||||
if err := d.Set("name", env.EnvironmentName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := d.Set("application", env.ApplicationName); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := d.Set("description", env.Description); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -388,8 +396,12 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int
|
|||
return err
|
||||
}
|
||||
|
||||
if tier == "WebServer" && env.CNAME != nil {
|
||||
beanstalkCnamePrefixRegexp := regexp.MustCompile(`(^[^.]+).\w{2}-\w{4,9}-\d.elasticbeanstalk.com$`)
|
||||
if err := d.Set("tier", *env.Tier.Name); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if env.CNAME != nil {
|
||||
beanstalkCnamePrefixRegexp := regexp.MustCompile(`(^[^.]+)(.\w{2}-\w{4,9}-\d)?.elasticbeanstalk.com$`)
|
||||
var cnamePrefix string
|
||||
cnamePrefixMatch := beanstalkCnamePrefixRegexp.FindStringSubmatch(*env.CNAME)
|
||||
|
||||
|
@ -402,6 +414,10 @@ func resourceAwsElasticBeanstalkEnvironmentRead(d *schema.ResourceData, meta int
|
|||
if err := d.Set("cname_prefix", cnamePrefix); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if err := d.Set("cname_prefix", ""); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := d.Set("autoscaling_groups", flattenBeanstalkAsg(resources.EnvironmentResources.AutoScalingGroups)); err != nil {
|
||||
|
|
Loading…
Reference in New Issue