-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.go
35 lines (32 loc) · 1006 Bytes
/
data.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
// All networking services-related tagging functions
package main
import (
"log"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/rds"
)
// tagrds tags an RDS resource
func tagrds(arnres arn.ARN, key, value string) error {
// resource types as per these docs:
// https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_AddTagsToResource.html
// for example:
// arn:aws:rds:eu-west-1:123456789012:db:mydb
region := arnres.Region
dbname := strings.Split(arnres.Resource, ":")[1]
log.Printf("Tagging RDS database '%s' in region '%s' with %s:%s",
dbname, region, key, value)
svc := rds.New(session.Must(session.NewSession()), aws.NewConfig().WithRegion(region))
_, err := svc.AddTagsToResource(&rds.AddTagsToResourceInput{
ResourceName: aws.String(arnres.String()),
Tags: []*rds.Tag{
{
Key: aws.String(key),
Value: aws.String(value),
},
},
})
return err
}