-
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add sentry project data source (#301)
- Loading branch information
1 parent
acc60af
commit d62399e
Showing
5 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "sentry_project Data Source - terraform-provider-sentry" | ||
subcategory: "" | ||
description: |- | ||
Sentry Project data source. | ||
--- | ||
|
||
# sentry_project (Data Source) | ||
|
||
Sentry Project data source. | ||
|
||
## Example Usage | ||
|
||
```terraform | ||
# Retrieve a project | ||
data "sentry_project" "default" { | ||
organization = "my-organization" | ||
slug = "my-project" | ||
} | ||
``` | ||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `organization` (String) The slug of the organization the project belongs to. | ||
- `slug` (String) The unique URL slug for this project. | ||
|
||
### Read-Only | ||
|
||
- `id` (String) The ID of this resource. | ||
- `internal_id` (String) The internal ID for this project. | ||
- `is_public` (Boolean) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Retrieve a project | ||
data "sentry_project" "default" { | ||
organization = "my-organization" | ||
|
||
slug = "my-project" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package sentry | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/terraform-plugin-log/tflog" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/jianyuan/go-sentry/v2/sentry" | ||
) | ||
|
||
func dataSourceSentryProject() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Sentry Project data source.", | ||
|
||
ReadContext: dataSourceSentryProjectRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"organization": { | ||
Description: "The slug of the organization the project belongs to.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"slug": { | ||
Description: "The unique URL slug for this project.", | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"internal_id": { | ||
Description: "The internal ID for this project.", | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"is_public": { | ||
Type: schema.TypeBool, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceSentryProjectRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
client := meta.(*sentry.Client) | ||
|
||
org := d.Get("organization").(string) | ||
projectSlug := d.Get("slug").(string) | ||
|
||
tflog.Debug(ctx, "Reading project", map[string]interface{}{ | ||
"org": org, | ||
"project": projectSlug, | ||
}) | ||
project, _, err := client.Projects.Get(ctx, org, projectSlug) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(project.Slug) | ||
retErr := multierror.Append( | ||
d.Set("organization", project.Organization.Slug), | ||
d.Set("slug", project.Slug), | ||
d.Set("internal_id", project.ID), | ||
d.Set("is_public", project.IsPublic), | ||
) | ||
return diag.FromErr(retErr.ErrorOrNil()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package sentry | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccSentryProjectDataSource_basic(t *testing.T) { | ||
teamName := acctest.RandomWithPrefix("tf-team") | ||
projectName := acctest.RandomWithPrefix("tf-project") | ||
dn := "data.sentry_project.test" | ||
rn := "sentry_project.test" | ||
|
||
var projectID string | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { acctest.PreCheck(t) }, | ||
Check failure on line 19 in sentry/data_source_sentry_project_test.go GitHub Actions / Matrix Test (1.4.*)
Check failure on line 19 in sentry/data_source_sentry_project_test.go GitHub Actions / Matrix Test (1.5.*)
|
||
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccSentryProjectConfig_basic(teamName, projectName), | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckSentryProjectExists(rn, &projectID), | ||
resource.TestCheckResourceAttrPair(dn, "organization", rn, "organization"), | ||
resource.TestCheckResourceAttrPair(dn, "slug", rn, "slug"), | ||
resource.TestCheckResourceAttrPair(dn, "internal_id", rn, "internal_id"), | ||
resource.TestCheckResourceAttrPair(dn, "is_public", rn, "is_public"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccSentryProjectConfig_basic(teamName, projectName string) string { | ||
return testAccSentryProjectConfig_team(teamName, projectName) + ` | ||
data "sentry_project" "test" { | ||
organization = sentry_project.test.organization | ||
slug = sentry_project.test.slug | ||
} | ||
` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters