-
Notifications
You must be signed in to change notification settings - Fork 134
/
data_source_tc_ssm_rotation_detail.go
110 lines (93 loc) · 3.01 KB
/
data_source_tc_ssm_rotation_detail.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package ssm
import (
"context"
tccommon "github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/common"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
ssm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ssm/v20190923"
"github.com/tencentcloudstack/terraform-provider-tencentcloud/tencentcloud/internal/helper"
)
func DataSourceTencentCloudSsmRotationDetail() *schema.Resource {
return &schema.Resource{
Read: dataSourceTencentCloudSsmRotationDetailRead,
Schema: map[string]*schema.Schema{
"secret_name": {
Required: true,
Type: schema.TypeString,
Description: "Secret name.",
},
"enable_rotation": {
Computed: true,
Type: schema.TypeBool,
Description: "Whether to allow rotation.",
},
"frequency": {
Computed: true,
Type: schema.TypeInt,
Description: "The rotation frequency, in days, defaults to 1 day.",
},
"latest_rotate_time": {
Computed: true,
Type: schema.TypeString,
Description: "Time of last rotation.",
},
"next_rotate_begin_time": {
Computed: true,
Type: schema.TypeString,
Description: "The time to start the next rotation.",
},
"result_output_file": {
Type: schema.TypeString,
Optional: true,
Description: "Used to save results.",
},
},
}
}
func dataSourceTencentCloudSsmRotationDetailRead(d *schema.ResourceData, meta interface{}) error {
defer tccommon.LogElapsed("data_source.tencentcloud_ssm_rotation_detail.read")()
defer tccommon.InconsistentCheck(d, meta)()
var (
logId = tccommon.GetLogId(tccommon.ContextNil)
ctx = context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
service = SsmService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
rotationDetail *ssm.DescribeRotationDetailResponseParams
secretName string
)
paramMap := make(map[string]interface{})
if v, ok := d.GetOk("secret_name"); ok {
paramMap["SecretName"] = helper.String(v.(string))
secretName = v.(string)
}
err := resource.Retry(tccommon.ReadRetryTimeout, func() *resource.RetryError {
result, e := service.DescribeSsmRotationDetailByFilter(ctx, paramMap)
if e != nil {
return tccommon.RetryError(e)
}
rotationDetail = result
return nil
})
if err != nil {
return err
}
if rotationDetail.EnableRotation != nil {
_ = d.Set("enable_rotation", rotationDetail.EnableRotation)
}
if rotationDetail.Frequency != nil {
_ = d.Set("frequency", rotationDetail.Frequency)
}
if rotationDetail.LatestRotateTime != nil {
_ = d.Set("latest_rotate_time", rotationDetail.LatestRotateTime)
}
if rotationDetail.NextRotateBeginTime != nil {
_ = d.Set("next_rotate_begin_time", rotationDetail.NextRotateBeginTime)
}
d.SetId(secretName)
output, ok := d.GetOk("result_output_file")
if ok && output.(string) != "" {
if e := tccommon.WriteToFile(output.(string), d); e != nil {
return e
}
}
return nil
}