First stab at fixing hashicorp/terraform#9930
Add the following resources: * `aws_cloudwatch_log_destination` * `aws_cloudwatch_log_destination_policy`
This commit is contained in:
parent
03af9fa42d
commit
7a55fe4bcc
|
@ -232,6 +232,8 @@ func Provider() terraform.ResourceProvider {
|
|||
"aws_cloudtrail": resourceAwsCloudTrail(),
|
||||
"aws_cloudwatch_event_rule": resourceAwsCloudWatchEventRule(),
|
||||
"aws_cloudwatch_event_target": resourceAwsCloudWatchEventTarget(),
|
||||
"aws_cloudwatch_log_destination": resourceAwsCloudWatchLogDestination(),
|
||||
"aws_cloudwatch_log_destination_policy": resourceAwsCloudWatchLogDestinationPolicy(),
|
||||
"aws_cloudwatch_log_group": resourceAwsCloudWatchLogGroup(),
|
||||
"aws_cloudwatch_log_metric_filter": resourceAwsCloudWatchLogMetricFilter(),
|
||||
"aws_cloudwatch_log_stream": resourceAwsCloudWatchLogStream(),
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
)
|
||||
|
||||
func resourceAwsCloudWatchLogDestination() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceAwsCloudWatchLogDestinationPut,
|
||||
Update: resourceAwsCloudWatchLogDestinationPut,
|
||||
|
||||
Read: resourceAwsCloudWatchLogDestinationRead,
|
||||
Delete: resourceAwsCloudWatchLogDestinationDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"role_arn": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"target_arn": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
|
||||
"arn": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceAwsCloudWatchLogDestinationPut(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).cloudwatchlogsconn
|
||||
|
||||
name := d.Get("name").(string)
|
||||
role_arn := d.Get("role_arn").(string)
|
||||
target_arn := d.Get("target_arn").(string)
|
||||
|
||||
params := &cloudwatchlogs.PutDestinationInput{
|
||||
DestinationName: aws.String(name),
|
||||
RoleArn: aws.String(role_arn),
|
||||
TargetArn: aws.String(target_arn),
|
||||
}
|
||||
|
||||
resp, err := conn.PutDestination(params)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating Destination with name %s: %#v", name, err)
|
||||
}
|
||||
|
||||
d.SetId(*resp.Destination.Arn)
|
||||
d.Set("arn", *resp.Destination.Arn)
|
||||
return resourceAwsCloudWatchLogDestinationRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsCloudWatchLogDestinationRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).cloudwatchlogsconn
|
||||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
params := &cloudwatchlogs.DescribeDestinationsInput{
|
||||
DestinationNamePrefix: aws.String(name),
|
||||
}
|
||||
|
||||
resp, err := conn.DescribeDestinations(params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading Destinations with name prefix %s: %#v", name, err)
|
||||
}
|
||||
|
||||
for _, destination := range resp.Destinations {
|
||||
if *destination.DestinationName == name {
|
||||
d.SetId(*destination.Arn)
|
||||
d.Set("arn", *destination.Arn)
|
||||
d.Set("role_arn", *destination.RoleArn)
|
||||
d.Set("target_arn", *destination.TargetArn)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceAwsCloudWatchLogDestinationDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).cloudwatchlogsconn
|
||||
|
||||
name := d.Get("name").(string)
|
||||
|
||||
params := &cloudwatchlogs.DeleteDestinationInput{
|
||||
DestinationName: aws.String(name),
|
||||
}
|
||||
_, err := conn.DeleteDestination(params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error deleting Destination with name %s", name)
|
||||
}
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
package aws
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
)
|
||||
|
||||
func resourceAwsCloudWatchLogDestinationPolicy() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Create: resourceAwsCloudWatchLogDestinationPolicyPut,
|
||||
Update: resourceAwsCloudWatchLogDestinationPolicyPut,
|
||||
|
||||
Read: resourceAwsCloudWatchLogDestinationPolicyRead,
|
||||
Delete: resourceAwsCloudWatchLogDestinationPolicyDelete,
|
||||
|
||||
Schema: map[string]*schema.Schema{
|
||||
"destination_name": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"access_policy": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func resourceAwsCloudWatchLogDestinationPolicyPut(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).cloudwatchlogsconn
|
||||
|
||||
destination_name := d.Get("destination_name").(string)
|
||||
access_policy := d.Get("access_policy").(string)
|
||||
|
||||
params := &cloudwatchlogs.PutDestinationPolicyInput{
|
||||
DestinationName: aws.String(destination_name),
|
||||
AccessPolicy: aws.String(access_policy),
|
||||
}
|
||||
|
||||
_, err := conn.PutDestinationPolicy(params)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error creating DestinationPolicy with destination_name %s: %#v", destination_name, err)
|
||||
}
|
||||
|
||||
d.SetId(destination_name)
|
||||
return resourceAwsCloudWatchLogDestinationPolicyRead(d, meta)
|
||||
}
|
||||
|
||||
func resourceAwsCloudWatchLogDestinationPolicyRead(d *schema.ResourceData, meta interface{}) error {
|
||||
conn := meta.(*AWSClient).cloudwatchlogsconn
|
||||
|
||||
destination_name := d.Get("destination_name").(string)
|
||||
|
||||
params := &cloudwatchlogs.DescribeDestinationsInput{
|
||||
DestinationNamePrefix: aws.String(destination_name),
|
||||
}
|
||||
|
||||
resp, err := conn.DescribeDestinations(params)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error reading Destinations with name prefix %s: %#v", destination_name, err)
|
||||
}
|
||||
|
||||
for _, destination := range resp.Destinations {
|
||||
if *destination.DestinationName == destination_name {
|
||||
if destination.AccessPolicy != nil {
|
||||
d.Set("access_policy", *destination.AccessPolicy)
|
||||
}
|
||||
d.SetId(destination_name)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
||||
func resourceAwsCloudWatchLogDestinationPolicyDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue