terraform-provider-sentry
terraform-provider-sentry copied to clipboard
Validate project platforms on plan
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.
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.
They seemed to store the complete list here:
- https://github.com/getsentry/sentry/blob/master/src/sentry/utils/platform_categories.py
- 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.
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.