/
resource_aws_route53_query_log.go
91 lines (73 loc) · 2.53 KB
/
resource_aws_route53_query_log.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
package aws
import (
"fmt"
"log"
"github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/route53"
)
func resourceAwsRoute53QueryLog() *schema.Resource {
return &schema.Resource{
Create: resourceAwsRoute53QueryLogCreate,
Read: resourceAwsRoute53QueryLogRead,
Delete: resourceAwsRoute53QueryLogDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},
Schema: map[string]*schema.Schema{
"cloudwatch_log_group_arn": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validateArn,
},
"zone_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
}
}
func resourceAwsRoute53QueryLogCreate(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).r53conn
input := &route53.CreateQueryLoggingConfigInput{
CloudWatchLogsLogGroupArn: aws.String(d.Get("cloudwatch_log_group_arn").(string)),
HostedZoneId: aws.String(d.Get("zone_id").(string)),
}
log.Printf("[DEBUG] Creating Route53 query logging configuration: %#v", input)
out, err := r53.CreateQueryLoggingConfig(input)
if err != nil {
return fmt.Errorf("Error creating Route53 query logging configuration: %s", err)
}
log.Printf("[DEBUG] Route53 query logging configuration created: %#v", out)
d.SetId(*out.QueryLoggingConfig.Id)
return resourceAwsRoute53QueryLogRead(d, meta)
}
func resourceAwsRoute53QueryLogRead(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).r53conn
input := &route53.GetQueryLoggingConfigInput{
Id: aws.String(d.Id()),
}
log.Printf("[DEBUG] Reading Route53 query logging configuration: %#v", input)
out, err := r53.GetQueryLoggingConfig(input)
if err != nil {
return fmt.Errorf("Error reading Route53 query logging configuration: %s", err)
}
log.Printf("[DEBUG] Route53 query logging configuration received: %#v", out)
d.Set("cloudwatch_log_group_arn", out.QueryLoggingConfig.CloudWatchLogsLogGroupArn)
d.Set("zone_id", out.QueryLoggingConfig.HostedZoneId)
return nil
}
func resourceAwsRoute53QueryLogDelete(d *schema.ResourceData, meta interface{}) error {
r53 := meta.(*AWSClient).r53conn
input := &route53.DeleteQueryLoggingConfigInput{
Id: aws.String(d.Id()),
}
log.Printf("[DEBUG] Deleting Route53 query logging configuration: %#v", input)
_, err := r53.DeleteQueryLoggingConfig(input)
if err != nil {
return fmt.Errorf("Error deleting Route53 query logging configuration: %s", err)
}
return nil
}