Пример #1
0
func CreateSnapshotTags(svc *ec2.EC2, resourceID, volumeName, volumeID string) error {
	var nKey, nVal string

	var tags []*ec2.Tag

	nKey = "Name"

	if volumeName == "" {
		nVal = fmt.Sprintf("%s: %s, %s", *tagPrefix, volumeID, time.Now().Format("2006-01-02"))
	} else {
		nVal = fmt.Sprintf("%s: %s, %s", *tagPrefix, volumeName, time.Now().Format("2006-01-02"))
	}
	tags = append(tags, &ec2.Tag{Key: &nKey, Value: &nVal})

	if *purgeAfterDays > 0 {
		var paKey, paVal string
		var pKey, pVal string
		paKey = PurgeAfterKey
		paVal = time.Now().Add(time.Duration(*purgeAfterDays*24) * time.Hour).Format(PurgeAfterFormat)
		tags = append(tags, &ec2.Tag{Key: &paKey, Value: &paVal})

		pKey = PurgeAllowKey
		pVal = "true"
		tags = append(tags, &ec2.Tag{Key: &pKey, Value: &pVal})
	}

	cti := ec2.CreateTagsInput{Tags: tags}
	cti.Resources = append(cti.Resources, &resourceID)

	_, err := svc.CreateTags(&cti)
	if err != nil {
		return err
	}

	return nil
}