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

[data_source_datadog_synthetics_test] Allow datasource to take a test URL as well as id #1993

Merged
merged 6 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 5 additions & 2 deletions datadog/data_source_datadog_synthetics_test_.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"

"regexp"
)

func dataSourceDatadogSyntheticsTest() *schema.Resource {
Expand All @@ -16,7 +18,7 @@ func dataSourceDatadogSyntheticsTest() *schema.Resource {

Schema: map[string]*schema.Schema{
"test_id": {
Description: "The synthetic test id to search for",
Description: "The synthetic test id or URL to search for",
Type: schema.TypeString,
Required: true,
},
Expand Down Expand Up @@ -52,7 +54,8 @@ func dataSourceDatadogSyntheticsTestRead(ctx context.Context, d *schema.Resource
return utils.TranslateClientErrorDiag(err, httpresp, "error getting synthetic tests")
}

searchedId := d.Get("test_id").(string)
urlRegex := regexp.MustCompile(`https:\/\/(.*)\.datadoghq\.com\/synthetics\/details\/`)
Cgg marked this conversation as resolved.
Show resolved Hide resolved
searchedId := urlRegex.ReplaceAllString(d.Get("test_id").(string), "")

for _, test := range tests.Tests {
if test.GetPublicId() == searchedId {
Expand Down
4 changes: 1 addition & 3 deletions docs/data-sources/synthetics_test.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ Use this data source to retrieve a Datadog Synthetic Test.

### Required

- `test_id` (String) The synthetic test id to search for
- `test_id` (String) The synthetic test id or URL to search for

### Read-Only

- `id` (String) The ID of this resource.
- `name` (String) The name of the synthetic test.
- `tags` (List of String) A list of tags assigned to the synthetic test.
- `url` (String) The start URL of the synthetic test.