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: Add additional detail to the data source example. #163

Merged
merged 1 commit into from
Sep 19, 2024
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
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
Loading