diff --git a/builtin/providers/aws/config.go b/builtin/providers/aws/config.go index 93f7db919043..143cb3ebced3 100644 --- a/builtin/providers/aws/config.go +++ b/builtin/providers/aws/config.go @@ -11,6 +11,7 @@ import ( "github.com/aws/aws-sdk-go/aws/credentials" "github.com/aws/aws-sdk-go/service/autoscaling" "github.com/aws/aws-sdk-go/service/cloudwatch" + "github.com/aws/aws-sdk-go/service/cloudwatchlogs" "github.com/aws/aws-sdk-go/service/dynamodb" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ecs" @@ -38,22 +39,23 @@ type Config struct { } type AWSClient struct { - cloudwatchconn *cloudwatch.CloudWatch - dynamodbconn *dynamodb.DynamoDB - ec2conn *ec2.EC2 - ecsconn *ecs.ECS - elbconn *elb.ELB - autoscalingconn *autoscaling.AutoScaling - s3conn *s3.S3 - sqsconn *sqs.SQS - snsconn *sns.SNS - r53conn *route53.Route53 - region string - rdsconn *rds.RDS - iamconn *iam.IAM - kinesisconn *kinesis.Kinesis - elasticacheconn *elasticache.ElastiCache - lambdaconn *lambda.Lambda + cloudwatchconn *cloudwatch.CloudWatch + cloudwatchlogsconn *cloudwatchlogs.CloudWatchLogs + dynamodbconn *dynamodb.DynamoDB + ec2conn *ec2.EC2 + ecsconn *ecs.ECS + elbconn *elb.ELB + autoscalingconn *autoscaling.AutoScaling + s3conn *s3.S3 + sqsconn *sqs.SQS + snsconn *sns.SNS + r53conn *route53.Route53 + region string + rdsconn *rds.RDS + iamconn *iam.IAM + kinesisconn *kinesis.Kinesis + elasticacheconn *elasticache.ElastiCache + lambdaconn *lambda.Lambda } // Client configures and returns a fully initailized AWSClient @@ -148,6 +150,9 @@ func (c *Config) Client() (interface{}, error) { log.Println("[INFO] Initializing CloudWatch SDK connection") client.cloudwatchconn = cloudwatch.New(awsConfig) + + log.Println("[INFO] Initializing CloudWatch Logs connection") + client.cloudwatchlogsconn = cloudwatchlogs.New(awsConfig) } if len(errs) > 0 { diff --git a/builtin/providers/aws/resource_aws_cloudwatch_log_group.go b/builtin/providers/aws/resource_aws_cloudwatch_log_group.go new file mode 100644 index 000000000000..8bb48f529753 --- /dev/null +++ b/builtin/providers/aws/resource_aws_cloudwatch_log_group.go @@ -0,0 +1,77 @@ +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/cloudwatchlogs" +) + +func resourceAwsCloudWatchLogGroup() *schema.Resource { + return &schema.Resource{ + Create: resourceAwsCloudWatchLogGroupCreate, + Read: resourceAwsCloudWatchLogGroupRead, + Delete: resourceAwsCloudWatchLogGroupDelete, + + Schema: map[string]*schema.Schema{ + "name": &schema.Schema{ + Type: schema.TypeString, + Required: true, + ForceNew: true, + }, + }, + } +} + +func resourceAwsCloudWatchLogGroupCreate(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).cloudwatchlogsconn + + log.Printf("[DEBUG] Creating CloudWatch Log Group: %s", d.Get("name").(string)) + _, err := conn.CreateLogGroup(&cloudwatchlogs.CreateLogGroupInput{ + LogGroupName: aws.String(d.Get("name").(string)), + }) + if err != nil { + return fmt.Errorf("Creating CloudWatch Log Group failed: %s", err) + } + + d.SetId(d.Get("name").(string)) + + log.Println("[INFO] CloudWatch Log Group created") + + return nil +} + +func resourceAwsCloudWatchLogGroupRead(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).cloudwatchlogsconn + log.Printf("[DEBUG] Reading CloudWatch Log Group: %s", d.Get("name")) + resp, err := conn.DescribeLogGroups(&cloudwatchlogs.DescribeLogGroupsInput{ + LogGroupNamePrefix: aws.String(d.Get("name").(string)), + }) + if err != nil { + return err + } + + // TODO Get a single group instead of filtering by prefix + + d.Set("name", resp.LogGroups[0].LogGroupName) + + return nil +} + +func resourceAwsCloudWatchLogGroupDelete(d *schema.ResourceData, meta interface{}) error { + conn := meta.(*AWSClient).cloudwatchlogsconn + log.Printf("[INFO] Deleting CloudWatch Log Group: %s", d.Id()) + _, err := conn.DeleteLogGroup(&cloudwatchlogs.DeleteLogGroupInput{ + LogGroupName: aws.String(d.Get("name").(string)), + }) + if err != nil { + return fmt.Errorf("Error deleting CloudWatch Log Group: %s", err) + } + log.Println("[INFO] CloudWatch Log Group deleted") + + d.SetId("") + return nil +} diff --git a/website/source/docs/providers/aws/r/cloudwatch_log_group.html.markdown b/website/source/docs/providers/aws/r/cloudwatch_log_group.html.markdown new file mode 100644 index 000000000000..5374a5a66bae --- /dev/null +++ b/website/source/docs/providers/aws/r/cloudwatch_log_group.html.markdown @@ -0,0 +1,25 @@ +--- +layout: "aws" +page_title: "AWS: aws_cloudwatch_log_group" +sidebar_current: "docs-aws-resource-cloudwatch-log-group" +description: |- + Provides a CloudWatch Log Group resource. +--- + +# aws\_cloudwatch\_log\_group + +Provides a CloudWatch Log Group resource. + +## Example Usage + +``` +resource "aws_cloudwatch_log_group" "yada" { + name = "Yada" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Group name. diff --git a/website/source/layouts/aws.erb b/website/source/layouts/aws.erb index 801945dec969..bdf6fb116ffa 100644 --- a/website/source/layouts/aws.erb +++ b/website/source/layouts/aws.erb @@ -29,6 +29,10 @@ aws_cloudwatch_metric_alarm + > + aws_cloudwatch_log_group + + > aws_customer_gateway