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

Docs update and custom image options update #538

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
17 changes: 11 additions & 6 deletions digitalocean/resource_digitalocean_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,20 @@ func resourceDigitalOceanCustomImageUpdate(ctx context.Context, d *schema.Resour
return diag.Errorf("Error converting id %s to string: %s", imageID, err)
}

if d.HasChange("name") {
name := d.Get("name").(string)
_, _, err := client.Images.Update(ctx, id, &godo.ImageUpdateRequest{
Name: name,
})
if d.HasChanges("name", "description", "distribution") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀 Hadn't noticed they've introduced HasChanges. Much nicer than the old if d.HasChange("foo") || d.HasChange("bar") syntaxt.

imageName := d.Get("name").(string)
imageUpdateRequest := &godo.ImageUpdateRequest{
Name: imageName,
Distribution: d.Get("distribution").(string),
Description: d.Get("description").(string),
}

_, _, err := client.Images.Update(ctx, id, imageUpdateRequest)
if err != nil {
return diag.Errorf("Error updating image %s, name %s: %s", imageID, name, err)
return diag.Errorf("Error updating image %s, name %s: %s", imageID, imageName, err)
}
}

return resourceDigitalOceanCustomImageRead(ctx, d, meta)
}

Expand Down
22 changes: 16 additions & 6 deletions digitalocean/resource_digitalocean_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import (
func TestAccDigitalOceanCustomImageFull(t *testing.T) {
rString := randomTestName()
name := fmt.Sprintf("digitalocean_custom_image.%s", rString)
updatedString := randomTestName()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: testAccProviderFactories,
CheckDestroy: testAccCheckDigitalOceanCustomImageDestroy,
Steps: []resource.TestStep{
{
Config: testAccCheckDigitalOceanCustomImageConfig(rString),
Config: testAccCheckDigitalOceanCustomImageConfig(rString, rString, "Unknown"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "name", fmt.Sprintf("%s-name", rString)),
resource.TestCheckResourceAttr(name, "description", fmt.Sprintf("%s-description", rString)),
Expand All @@ -37,22 +38,31 @@ func TestAccDigitalOceanCustomImageFull(t *testing.T) {
resource.TestCheckResourceAttrSet(name, "size_gigabytes"),
),
},
{
Config: testAccCheckDigitalOceanCustomImageConfig(rString, updatedString, "CoreOS"),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(name, "name", fmt.Sprintf("%s-name", updatedString)),
resource.TestCheckResourceAttr(name, "description", fmt.Sprintf("%s-description", updatedString)),
resource.TestCheckResourceAttr(name, "distribution", "CoreOS"),
),
},
},
})
}

func testAccCheckDigitalOceanCustomImageConfig(name string) string {
func testAccCheckDigitalOceanCustomImageConfig(rName string, name string, distro string) string {
return fmt.Sprintf(`
resource "digitalocean_custom_image" "%s" {
name = "%s-name"
url = "https://stable.release.flatcar-linux.net/amd64-usr/2605.7.0/flatcar_production_digitalocean_image.bin.bz2"
regions = ["nyc3"]
description = "%s-description"
url = "https://stable.release.flatcar-linux.net/amd64-usr/2605.7.0/flatcar_production_digitalocean_image.bin.bz2"
regions = ["nyc3"]
description = "%s-description"
distribution = "%s"
tags = [
"flatcar"
]
}
`, name, name, name)
`, rName, name, name, distro)
}

func testAccCheckDigitalOceanCustomImageDestroy(s *terraform.State) error {
Expand Down
5 changes: 4 additions & 1 deletion docs/resources/custom_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ The following arguments are supported:

* `name` - (Required) A name for the Custom Image.
* `url` - (Required) A URL from which the custom Linux virtual machine image may be retrieved.
* `regions` - (Required) A list of regions. (Currently only one is supported)
* `regions` - (Required) A list of regions. (Currently only one is supported).
* `description` - An optional description for the image.
* `distribution` - An optional distribution name for the image. Valid values are documented [here](https://developers.digitalocean.com/documentation/v2/#create-a-custom-image)
* `tags` - A list of optional tags for the image.

## Attributes Reference

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/digitalocean/terraform-provider-digitalocean

require (
github.com/aws/aws-sdk-go v1.25.4
github.com/digitalocean/godo v1.52.0
github.com/digitalocean/godo v1.54.0
github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/terraform-plugin-sdk/v2 v2.0.3
github.com/mitchellh/go-homedir v1.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.52.0 h1:1QSUC0w5T1wS1d/1uvPtG8GLeD0p/4zhx1Q+Fxtna+k=
github.com/digitalocean/godo v1.52.0/go.mod h1:p7dOjjtSBqCTUksqtA5Fd3uaKs9kyTq2xcz76ulEJRU=
github.com/digitalocean/godo v1.54.0 h1:KP0Nv87pgViR8k/7De3VrmflCL5pJqXbNnkcw0bwG10=
github.com/digitalocean/godo v1.54.0/go.mod h1:p7dOjjtSBqCTUksqtA5Fd3uaKs9kyTq2xcz76ulEJRU=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down