diff --git a/.web-docs/components/data-source/digitalocean-image/README.md b/.web-docs/components/data-source/digitalocean-image/README.md index 23939ed..bb0f2ff 100644 --- a/.web-docs/components/data-source/digitalocean-image/README.md +++ b/.web-docs/components/data-source/digitalocean-image/README.md @@ -56,9 +56,14 @@ for use as a builder source. ## Example Usage +In this example, we combine `name_regex` and `latest` to find the most recent +user generated image matching the name `golden-image-.*`. The ID of the found +image is then passed to the builder where it is used as the base for creating +a new image. + ```hcl data "digitalocean-image" "example" { - name_regex = "golden-image-2022.*" + name_regex = "golden-image-.*" region = "nyc3" type = "user" latest = true @@ -69,7 +74,7 @@ locals { } source "digitalocean" "example" { - snapshot_name = "updated-golden-image" + snapshot_name = "golden-image-{{isotime}}" image = local.image_id region = "nyc3" size = "s-1vcpu-1gb" diff --git a/datasource/image/data.go b/datasource/image/data.go index ead2bc2..a84f37e 100644 --- a/datasource/image/data.go +++ b/datasource/image/data.go @@ -256,7 +256,7 @@ func filterImages(c *Config, images []godo.Image) (godo.Image, error) { return godo.Image{}, fmt.Errorf("More than one matching image found: %v", result) } if len(result) == 0 { - return godo.Image{}, errors.New("No image matching found") + return godo.Image{}, errors.New("No matching image found") } return result[0], nil diff --git a/datasource/image/data_test.go b/datasource/image/data_test.go index d8802d6..8e746ac 100644 --- a/datasource/image/data_test.go +++ b/datasource/image/data_test.go @@ -58,7 +58,7 @@ func TestFilterImages(t *testing.T) { {ID: 1, Name: "test-image-01", Created: "2022-08-08T21:31:54Z", Regions: []string{"nyc3"}}, {ID: 2, Name: "test-image-02", Created: "2022-08-10T21:31:54Z", Regions: []string{"nyc2"}}, }, - expectedError: "No image matching found", + expectedError: "No matching image found", }, { @@ -104,7 +104,7 @@ func TestFilterImages(t *testing.T) { {ID: 1, Name: "test-image01", Created: "2022-08-08T21:31:54Z", Regions: []string{"nyc3"}}, {ID: 2, Name: "test-image02", Created: "2022-08-10T21:31:54Z", Regions: []string{"nyc2"}}, }, - expectedError: "No image matching found", + expectedError: "No matching image found", }, } diff --git a/docs/datasources/digitalocean-image.mdx b/docs/datasources/digitalocean-image.mdx index cc9d7fe..189af60 100644 --- a/docs/datasources/digitalocean-image.mdx +++ b/docs/datasources/digitalocean-image.mdx @@ -26,9 +26,14 @@ for use as a builder source. ## Example Usage +In this example, we combine `name_regex` and `latest` to find the most recent +user generated image matching the name `golden-image-.*`. The ID of the found +image is then passed to the builder where it is used as the base for creating +a new image. + ```hcl data "digitalocean-image" "example" { - name_regex = "golden-image-2022.*" + name_regex = "golden-image-.*" region = "nyc3" type = "user" latest = true @@ -39,7 +44,7 @@ locals { } source "digitalocean" "example" { - snapshot_name = "updated-golden-image" + snapshot_name = "golden-image-{{isotime}}" image = local.image_id region = "nyc3" size = "s-1vcpu-1gb"