|
| 1 | +package sentry |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/hashicorp/go-multierror" |
| 7 | + "github.com/hashicorp/terraform-plugin-log/tflog" |
| 8 | + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" |
| 9 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" |
| 10 | + "github.com/jianyuan/go-sentry/v2/sentry" |
| 11 | +) |
| 12 | + |
| 13 | +func dataSourceSentryProject() *schema.Resource { |
| 14 | + return &schema.Resource{ |
| 15 | + Description: "Sentry Project data source.", |
| 16 | + |
| 17 | + ReadContext: dataSourceSentryProjectRead, |
| 18 | + |
| 19 | + Schema: map[string]*schema.Schema{ |
| 20 | + "organization": { |
| 21 | + Description: "The slug of the organization the project belongs to.", |
| 22 | + Type: schema.TypeString, |
| 23 | + Required: true, |
| 24 | + }, |
| 25 | + "slug": { |
| 26 | + Description: "The unique URL slug for this project.", |
| 27 | + Type: schema.TypeString, |
| 28 | + Required: true, |
| 29 | + }, |
| 30 | + "internal_id": { |
| 31 | + Description: "The internal ID for this project.", |
| 32 | + Type: schema.TypeString, |
| 33 | + Computed: true, |
| 34 | + }, |
| 35 | + "is_public": { |
| 36 | + Type: schema.TypeBool, |
| 37 | + Computed: true, |
| 38 | + }, |
| 39 | + }, |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func dataSourceSentryProjectRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { |
| 44 | + client := meta.(*sentry.Client) |
| 45 | + |
| 46 | + org := d.Get("organization").(string) |
| 47 | + projectSlug := d.Get("slug").(string) |
| 48 | + |
| 49 | + tflog.Debug(ctx, "Reading project", map[string]interface{}{ |
| 50 | + "org": org, |
| 51 | + "project": projectSlug, |
| 52 | + }) |
| 53 | + project, _, err := client.Projects.Get(ctx, org, projectSlug) |
| 54 | + if err != nil { |
| 55 | + return diag.FromErr(err) |
| 56 | + } |
| 57 | + |
| 58 | + d.SetId(project.Slug) |
| 59 | + retErr := multierror.Append( |
| 60 | + d.Set("organization", project.Organization.Slug), |
| 61 | + d.Set("slug", project.Slug), |
| 62 | + d.Set("internal_id", project.ID), |
| 63 | + d.Set("is_public", project.IsPublic), |
| 64 | + ) |
| 65 | + return diag.FromErr(retErr.ErrorOrNil()) |
| 66 | +} |
0 commit comments