-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
provider/aws: Add cloudwatch_log_group
- Loading branch information
1 parent
7850bb3
commit ff3138f
Showing
4 changed files
with
127 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
builtin/providers/aws/resource_aws_cloudwatch_log_group.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
25 changes: 25 additions & 0 deletions
25
website/source/docs/providers/aws/r/cloudwatch_log_group.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters