terraform-provider-sentry icon indicating copy to clipboard operation
terraform-provider-sentry copied to clipboard

Validate project platforms on plan

Open acm19 opened this issue 2 years ago • 2 comments

Currently platform is not validated for sentry_project resource. The plan will succeed and the apply will fail if an invalid platform is introduced. Only a list of attributes are valid that should be validated at terraform plan time.

acm19 avatar Sep 15 '22 12:09 acm19

AFAIK there doesn't seem to be a reliable way to get the platforms through an API or documentation. This hacky bit of JS can be used on the console of the new project page to scrape valid platforms.

Array.from(document.querySelectorAll("div[data-test-id^='platform-']")).map((element) => {
  return element.getAttribute('data-test-id').replace(/platform-/, '');
});

I'm not sure how often these change, but imo hardcoding validation might cause issues in the future.

danielpoonwj avatar Sep 26 '22 09:09 danielpoonwj

They seemed to store the complete list here:

  1. https://github.com/getsentry/sentry/blob/master/src/sentry/utils/platform_categories.py
  2. https://github.com/getsentry/sentry/blob/master/static/app/data/platformCategories.tsx

It seems that we can do a POST to https://sentry.io/api/0/teams/terraform-provider-sentry/operations/projects/ with the name hardcoded to blank to avoid creating a project, but it is hacky.

Request:
POST https://sentry.io/api/0/teams/terraform-provider-sentry/operations/projects/
{"name":"","platform":"invalid-platform","default_rules":false}

Response:
{"name":["This field may not be blank."],"platform":["Invalid platform"]}

Let me enquire about this with the Sentry team and revert.

jianyuan avatar Sep 26 '22 22:09 jianyuan

Hardcoding it is not really bad as long as they don't provide it. Regions are hardcoded in the AWS client for example: https://github.com/hashicorp/aws-sdk-go-base/blob/main/internal/endpoints/endpoints.go and https://github.com/aws/aws-sdk-go/blob/main/models/endpoints/endpoints.json. It'd be possible to automatically generate it from Sentry code. In any case it's always possible to bump the provider if your platform is not provided. I could take a look and contribute it you'd be happy with that when I have some time.

acm19 avatar Dec 06 '22 20:12 acm19