Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #33 Add snapshot_tags #151

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .web-docs/components/builder/digitalocean/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ each category, the available configuration keys are alphabetized.

- `tags` ([]string) - Tags to apply to the droplet when it is created

- `snapshot_tags` ([]string) - Tags to apply to the snapshot after it is created

- `vpc_uuid` (string) - UUID of the VPC which the droplet will be created in. Before using this,
private_networking should be enabled.

Expand Down
7 changes: 5 additions & 2 deletions builder/digitalocean/builder_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ const (
"region": "nyc2",
"size": "s-1vcpu-1gb",
"image": "%v",
"ssh_username": "root"
"ssh_username": "root",
"tags": ["tag1","tag2"]
}]
}
`
Expand All @@ -179,7 +180,8 @@ const (
"size": "s-1vcpu-1gb",
"image": "%v",
"ssh_username": "root",
"snapshot_regions": ["nyc1", "nyc2", "nyc3"]
"snapshot_regions": ["nyc1", "nyc2", "nyc3"],
"tags": ["tag1","tag2"]
}]
}
`
Expand All @@ -193,6 +195,7 @@ const (
"image": "%v",
"ssh_username": "root",
"snapshot_regions": ["nyc2", "nyc3"],
"tags": ["tag1","tag2"],
"wait_snapshot_transfer": false
}]
}
Expand Down
2 changes: 2 additions & 0 deletions builder/digitalocean/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type Config struct {
UserDataFile string `mapstructure:"user_data_file" required:"false"`
// Tags to apply to the droplet when it is created
Tags []string `mapstructure:"tags" required:"false"`
// Tags to apply to the snapshot after it is created
SnapshotTags []string `mapstructure:"snapshot_tags" required:"false"`
// UUID of the VPC which the droplet will be created in. Before using this,
// private_networking should be enabled.
VPCUUID string `mapstructure:"vpc_uuid" required:"false"`
Expand Down
2 changes: 2 additions & 0 deletions builder/digitalocean/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions builder/digitalocean/step_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"log"
"strconv"
"time"

"github.com/digitalocean/godo"
Expand Down Expand Up @@ -79,6 +80,19 @@ func (s *stepSnapshot) Run(ctx context.Context, state multistep.StateBag) multis
return multistep.ActionHalt
}

if len(c.SnapshotTags) > 0 {
for _, tag := range c.SnapshotTags {
_, err = client.Tags.TagResources(context.TODO(), tag, &godo.TagResourcesRequest{Resources: []godo.Resource{{ID: strconv.Itoa(imageId), Type: "image"}}})
if err != nil {
err := fmt.Errorf("Error Tagging Image: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
}
ui.Say(fmt.Sprintf("Added snapshot tag: %s...", tag))
}
}

if len(c.SnapshotRegions) > 0 {
regionSet := make(map[string]bool)
regions := make([]string, 0, len(c.SnapshotRegions))
Expand Down
2 changes: 2 additions & 0 deletions docs-partials/builder/digitalocean/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@

- `tags` ([]string) - Tags to apply to the droplet when it is created

- `snapshot_tags` ([]string) - Tags to apply to the snapshot after it is created

- `vpc_uuid` (string) - UUID of the VPC which the droplet will be created in. Before using this,
private_networking should be enabled.

Expand Down
Loading