forked from hashicorp/terraform-provider-aws
/
data_source_aws_iam_group.go
63 lines (52 loc) · 1.19 KB
/
data_source_aws_iam_group.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
package aws
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsIAMGroup() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsIAMGroupRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"path": {
Type: schema.TypeString,
Computed: true,
},
"group_id": {
Type: schema.TypeString,
Computed: true,
},
"group_name": {
Type: schema.TypeString,
Required: true,
},
},
}
}
func dataSourceAwsIAMGroupRead(d *schema.ResourceData, meta interface{}) error {
iamconn := meta.(*AWSClient).iamconn
groupName := d.Get("group_name").(string)
req := &iam.GetGroupInput{
GroupName: aws.String(groupName),
}
log.Printf("[DEBUG] Reading IAM Group: %s", req)
resp, err := iamconn.GetGroup(req)
if err != nil {
return fmt.Errorf("Error getting group: %s", err)
}
if resp == nil {
return fmt.Errorf("no IAM group found")
}
group := resp.Group
d.SetId(*group.GroupId)
d.Set("arn", group.Arn)
d.Set("path", group.Path)
d.Set("group_id", group.GroupId)
return nil
}