Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Radek Simko committed Sep 4, 2015
1 parent 7d14213 commit c6f049b
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtin/providers/aws/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/elasticache"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/glacier"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/kinesis"
"github.com/aws/aws-sdk-go/service/lambda"
Expand Down Expand Up @@ -54,6 +55,7 @@ type AWSClient struct {
region string
rdsconn *rds.RDS
iamconn *iam.IAM
glacierconn *glacier.Glacier
kinesisconn *kinesis.Kinesis
elasticacheconn *elasticache.ElastiCache
lambdaconn *lambda.Lambda
Expand Down Expand Up @@ -156,6 +158,9 @@ func (c *Config) Client() (interface{}, error) {

log.Println("[INFO] Initializing CloudWatch SDK connection")
client.cloudwatchconn = cloudwatch.New(awsConfig)

log.Println("[INFO] Initializing Glacier connection")
client.glacierconn = glacier.New(awsConfig)
}

if len(errs) > 0 {
Expand Down
1 change: 1 addition & 0 deletions builtin/providers/aws/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func Provider() terraform.ResourceProvider {
"aws_elasticache_subnet_group": resourceAwsElasticacheSubnetGroup(),
"aws_elb": resourceAwsElb(),
"aws_flow_log": resourceAwsFlowLog(),
"aws_glacier_vault": resourceAwsGlacierVault(),
"aws_iam_access_key": resourceAwsIamAccessKey(),
"aws_iam_group_policy": resourceAwsIamGroupPolicy(),
"aws_iam_group": resourceAwsIamGroup(),
Expand Down
143 changes: 143 additions & 0 deletions builtin/providers/aws/resource_aws_glacier_vault.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package aws

import (
"encoding/json"
"fmt"
"log"

"github.com/hashicorp/terraform/helper/schema"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/glacier"
)

func resourceAwsGlacierVault() *schema.Resource {
return &schema.Resource{
Create: resourceAwsGlacierVaultCreate,
Read: resourceAwsGlacierVaultRead,
Update: resourceAwsGlacierVaultUpdate,
Delete: resourceAwsGlacierVaultDelete,

Schema: map[string]*schema.Schema{
"name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
},

"access_policy": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},

"notification": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"events": &schema.Schema{
Type: schema.TypeSet,
Optional: true,
},
"sns_topic": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
},
},

"location": &schema.Schema{
Type: schema.TypeString,
Computed: true,
},

"tags": tagsSchema(),
},
}
}

func resourceAwsGlacierVaultCreate(d *schema.ResourceData, meta interface{}) error {
glacierconn := meta.(*AWSClient).glacierconn

input := &glacier.CreateVaultInput{
VaultName: aws.String(d.Get("name").(string)),
}
out, err := glacierconn.CreateVault(input)

i := glacier.SetVaultNotificationsInput{}
glacierconn.SetVaultNotifications(i)

d.Set("location", *out.Location)

return resourceAwsGlacierVaultRead(d, meta)
}

func resourceAwsGlacierVaultUpdate(d *schema.ResourceData, meta interface{}) error {
glacierconn := meta.(*AWSClient).glacierconn

glacierconn.AddTagsToVault(input)

return resourceAwsGlacierVaultRead(d, meta)
}

func resourceAwsGlacierVaultRead(d *schema.ResourceData, meta interface{}) error {
glacierconn := meta.(*AWSClient).glacierconn

return nil
}

func resourceAwsGlacierVaultDelete(d *schema.ResourceData, meta interface{}) error {
glacierconn := meta.(*AWSClient).glacierconn

return nil
}

// setTags is a helper to set the tags for a resource. It expects the
// tags field to be named "tags"
func setGlacierVaultTags(conn *glacier.Glacier, d *schema.ResourceData) error {
if d.HasChange("tags") {
oraw, nraw := d.GetChange("tags")
o := oraw.(map[string]interface{})
n := nraw.(map[string]interface{})
create, remove := diffGlacierVaultTags(o, n)

// Set tags
if len(remove) > 0 {
log.Printf("[DEBUG] Removing tags: %#v from %s", remove, d.Id())
_, err := conn.RemoveTagsFromVault(&glacier.RemoveTagsFromVaultInput{
VaultName: aws.String(d.Get("name").(string)),
TagKeys: remove,
})
if err != nil {
return err
}
}
if len(create) > 0 {
log.Printf("[DEBUG] Creating tags: %s for %s", create, d.Id())
_, err := conn.AddTagsToVault(&glacier.AddTagsToVaultInput{
VaultName: aws.String(d.Get("name").(string)),
Tags: create,
})
if err != nil {
return err
}
}
}

return nil
}

// diffTags takes our tags locally and the ones remotely and returns
// the set of tags that must be created, and the set of tags that must
// be destroyed.
func diffGlacierVaultTags(oldTags, newTags map[string]*string) (map[string]*string, map[string]*string) {
// First, we're creating everything we have
create := make(map[string]interface{})
remove := make(map[string]interface{})

// TODO

return create, remove
}

0 comments on commit c6f049b

Please sign in to comment.