forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source_aws_arn.go
59 lines (52 loc) · 1.14 KB
/
data_source_aws_arn.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
package aws
import (
"fmt"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsArn() *schema.Resource {
return &schema.Resource{
Read: dataSourceAwsArnRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validateArn,
},
"partition": {
Type: schema.TypeString,
Computed: true,
},
"service": {
Type: schema.TypeString,
Computed: true,
},
"region": {
Type: schema.TypeString,
Computed: true,
},
"account": {
Type: schema.TypeString,
Computed: true,
},
"resource": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceAwsArnRead(d *schema.ResourceData, meta interface{}) error {
v := d.Get("arn").(string)
arn, err := arn.Parse(v)
if err != nil {
return fmt.Errorf("Error parsing '%s': %s", v, err.Error())
}
d.SetId(arn.String())
d.Set("partition", arn.Partition)
d.Set("service", arn.Service)
d.Set("region", arn.Region)
d.Set("account", arn.AccountID)
d.Set("resource", arn.Resource)
return nil
}