forked from hashicorp/terraform-provider-aws
/
data_source_aws_elastic_beanstalk_application.go
87 lines (75 loc) · 2.02 KB
/
data_source_aws_elastic_beanstalk_application.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package aws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/elasticbeanstalk"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsElasticBeanstalkApplication() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsElasticBeanstalkApplicationRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"description": {
Type: schema.TypeString,
Computed: true,
},
"appversion_lifecycle": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"service_role": {
Type: schema.TypeString,
Computed: true,
},
"max_age_in_days": {
Type: schema.TypeInt,
Computed: true,
},
"max_count": {
Type: schema.TypeInt,
Computed: true,
},
"delete_source_from_s3": {
Type: schema.TypeBool,
Computed: true,
},
},
},
},
},
}
}
func dataSourceAwsElasticBeanstalkApplicationRead(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).elasticbeanstalkconn
// Get the name and description
name := d.Get("name").(string)
resp, err := conn.DescribeApplications(&elasticbeanstalk.DescribeApplicationsInput{
ApplicationNames: []*string{aws.String(name)},
})
if err != nil {
return fmt.Errorf("Error describing Applications (%s): %s", name, err)
}
if len(resp.Applications) > 1 || len(resp.Applications) < 1 {
return fmt.Errorf("Error %d Applications matched, expected 1", len(resp.Applications))
}
app := resp.Applications[0]
d.SetId(name)
d.Set("arn", app.ApplicationArn)
d.Set("name", app.ApplicationName)
d.Set("description", app.Description)
if app.ResourceLifecycleConfig != nil {
d.Set("appversion_lifecycle", flattenResourceLifecycleConfig(app.ResourceLifecycleConfig))
}
return nil
}