forked from hashicorp/terraform-provider-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging_options.go
90 lines (72 loc) · 2.63 KB
/
logging_options.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
package iot
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/iot"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
"github.com/hashicorp/terraform-provider-aws/internal/conns"
tfiam "github.com/hashicorp/terraform-provider-aws/internal/service/iam"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
)
func ResourceLoggingOptions() *schema.Resource {
return &schema.Resource{
CreateWithoutTimeout: resourceLoggingOptionsPut,
ReadWithoutTimeout: resourceLoggingOptionsRead,
UpdateWithoutTimeout: resourceLoggingOptionsPut,
DeleteWithoutTimeout: schema.NoopContext,
Schema: map[string]*schema.Schema{
"default_log_level": {
Type: schema.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice(iot.LogLevel_Values(), false),
},
"disable_all_logs": {
Type: schema.TypeBool,
Optional: true,
},
"role_arn": {
Type: schema.TypeString,
Required: true,
ValidateFunc: verify.ValidARN,
},
},
}
}
func resourceLoggingOptionsPut(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).IoTConn
input := &iot.SetV2LoggingOptionsInput{}
if v, ok := d.GetOk("default_log_level"); ok {
input.DefaultLogLevel = aws.String(v.(string))
}
if v, ok := d.GetOk("disable_all_logs"); ok {
input.DisableAllLogs = aws.Bool(v.(bool))
}
if v, ok := d.GetOk("role_arn"); ok {
input.RoleArn = aws.String(v.(string))
}
_, err := tfresource.RetryWhenAWSErrMessageContainsContext(ctx, tfiam.PropagationTimeout,
func() (interface{}, error) {
return conn.SetV2LoggingOptionsWithContext(ctx, input)
},
iot.ErrCodeInvalidRequestException, "If the role was just created or updated, please try again in a few seconds.",
)
if err != nil {
return diag.Errorf("setting IoT logging options: %s", err)
}
d.SetId(meta.(*conns.AWSClient).Region)
return resourceLoggingOptionsRead(ctx, d, meta)
}
func resourceLoggingOptionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
conn := meta.(*conns.AWSClient).IoTConn
output, err := conn.GetV2LoggingOptionsWithContext(ctx, &iot.GetV2LoggingOptionsInput{})
if err != nil {
return diag.Errorf("reading IoT logging options: %s", err)
}
d.Set("default_log_level", output.DefaultLogLevel)
d.Set("disable_all_logs", output.DisableAllLogs)
d.Set("role_arn", output.RoleArn)
return nil
}