forked from hashicorp/terraform-provider-aws
/
data_source_aws_ssm_parameter.go
77 lines (66 loc) · 1.64 KB
/
data_source_aws_ssm_parameter.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
package aws
import (
"fmt"
"log"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/service/ssm"
"github.com/hashicorp/terraform/helper/schema"
)
func dataSourceAwsSsmParameter() *schema.Resource {
return &schema.Resource{
Read: dataAwsSsmParameterRead,
Schema: map[string]*schema.Schema{
"arn": {
Type: schema.TypeString,
Computed: true,
},
"name": {
Type: schema.TypeString,
Required: true,
},
"type": {
Type: schema.TypeString,
Computed: true,
},
"value": {
Type: schema.TypeString,
Computed: true,
Sensitive: true,
},
"with_decryption": {
Type: schema.TypeBool,
Optional: true,
Default: true,
},
},
}
}
func dataAwsSsmParameterRead(d *schema.ResourceData, meta interface{}) error {
ssmconn := meta.(*AWSClient).ssmconn
name := d.Get("name").(string)
paramInput := &ssm.GetParameterInput{
Name: aws.String(name),
WithDecryption: aws.Bool(d.Get("with_decryption").(bool)),
}
log.Printf("[DEBUG] Reading SSM Parameter: %s", paramInput)
resp, err := ssmconn.GetParameter(paramInput)
if err != nil {
return fmt.Errorf("Error describing SSM parameter: %s", err)
}
param := resp.Parameter
d.SetId(*param.Name)
arn := arn.ARN{
Partition: meta.(*AWSClient).partition,
Region: meta.(*AWSClient).region,
Service: "ssm",
AccountID: meta.(*AWSClient).accountid,
Resource: fmt.Sprintf("parameter/%s", strings.TrimPrefix(d.Id(), "/")),
}
d.Set("arn", arn.String())
d.Set("name", param.Name)
d.Set("type", param.Type)
d.Set("value", param.Value)
return nil
}