Skip to content

Commit

Permalink
Merge pull request #163 from digitalocean/asb/data-source-example-desc
Browse files Browse the repository at this point in the history
docs: Add additional detail to the data source example.
  • Loading branch information
andrewsomething authored Sep 19, 2024
2 parents 63d0729 + 2c4686b commit 622f2ea
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
9 changes: 7 additions & 2 deletions .web-docs/components/data-source/digitalocean-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion datasource/image/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions datasource/image/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},

{
Expand Down Expand Up @@ -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",
},
}

Expand Down
9 changes: 7 additions & 2 deletions docs/datasources/digitalocean-image.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down

0 comments on commit 622f2ea

Please sign in to comment.