Skip to content

Commit

Permalink
Update generation of schema & bridge metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
ringods committed Nov 15, 2024
1 parent 23bf6b9 commit 4d20e85
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 8 deletions.
210 changes: 210 additions & 0 deletions provider/cmd/pulumi-resource-sentry/bridge-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
{
"auto-aliasing": {
"resources": {
"sentry_dashboard": {
"current": "sentry:index/sentryDashboard:SentryDashboard",
"fields": {
"widget": {
"maxItemsOne": false,
"elem": {
"fields": {
"layout": {
"maxItemsOne": true
},
"query": {
"maxItemsOne": false,
"elem": {
"fields": {
"aggregates": {
"maxItemsOne": false
},
"columns": {
"maxItemsOne": false
},
"field_aliases": {
"maxItemsOne": false
},
"fields": {
"maxItemsOne": false
}
}
}
}
}
}
}
}
},
"sentry_issue_alert": {
"current": "sentry:index/sentryIssueAlert:SentryIssueAlert",
"fields": {
"actions": {
"maxItemsOne": false
},
"conditions": {
"maxItemsOne": false
},
"filters": {
"maxItemsOne": false
},
"projects": {
"maxItemsOne": false
}
}
},
"sentry_key": {
"current": "sentry:index/sentryKey:SentryKey"
},
"sentry_metric_alert": {
"current": "sentry:index/sentryMetricAlert:SentryMetricAlert",
"fields": {
"event_types": {
"maxItemsOne": false
},
"trigger": {
"maxItemsOne": false,
"elem": {
"fields": {
"action": {
"maxItemsOne": false
}
}
}
}
}
},
"sentry_organization": {
"current": "sentry:index/sentryOrganization:SentryOrganization"
},
"sentry_organization_code_mapping": {
"current": "sentry:index/sentryOrganizationCodeMapping:SentryOrganizationCodeMapping"
},
"sentry_organization_member": {
"current": "sentry:index/sentryOrganizationMember:SentryOrganizationMember",
"fields": {
"teams": {
"maxItemsOne": false
}
}
},
"sentry_organization_repository_github": {
"current": "sentry:index/sentryOrganizationRepositoryGithub:SentryOrganizationRepositoryGithub"
},
"sentry_plugin": {
"current": "sentry:index/sentryPlugin:SentryPlugin"
},
"sentry_project": {
"current": "sentry:index/sentryProject:SentryProject",
"fields": {
"features": {
"maxItemsOne": false
},
"teams": {
"maxItemsOne": false
}
}
},
"sentry_rule": {
"current": "sentry:index/sentryRule:SentryRule",
"fields": {
"actions": {
"maxItemsOne": false
},
"conditions": {
"maxItemsOne": false
},
"filters": {
"maxItemsOne": false
},
"projects": {
"maxItemsOne": false
}
}
},
"sentry_team": {
"current": "sentry:index/sentryTeam:SentryTeam"
}
},
"datasources": {
"sentry_dashboard": {
"current": "sentry:index/getSentryDashboard:getSentryDashboard",
"fields": {
"widget": {
"maxItemsOne": false,
"elem": {
"fields": {
"layout": {
"maxItemsOne": false
},
"query": {
"maxItemsOne": false,
"elem": {
"fields": {
"aggregates": {
"maxItemsOne": false
},
"columns": {
"maxItemsOne": false
},
"field_aliases": {
"maxItemsOne": false
},
"fields": {
"maxItemsOne": false
}
}
}
}
}
}
}
}
},
"sentry_issue_alert": {
"current": "sentry:index/getSentryIssueAlert:getSentryIssueAlert",
"fields": {
"actions": {
"maxItemsOne": false
},
"conditions": {
"maxItemsOne": false
},
"filters": {
"maxItemsOne": false
}
}
},
"sentry_key": {
"current": "sentry:index/getSentryKey:getSentryKey"
},
"sentry_metric_alert": {
"current": "sentry:index/getSentryMetricAlert:getSentryMetricAlert",
"fields": {
"event_types": {
"maxItemsOne": false
},
"trigger": {
"maxItemsOne": false,
"elem": {
"fields": {
"action": {
"maxItemsOne": false
}
}
}
}
}
},
"sentry_organization": {
"current": "sentry:index/getSentryOrganization:getSentryOrganization"
},
"sentry_organization_integration": {
"current": "sentry:index/getSentryOrganizationIntegration:getSentryOrganizationIntegration"
},
"sentry_team": {
"current": "sentry:index/getSentryTeam:getSentryTeam"
}
}
},
"auto-settings": {}
}
18 changes: 11 additions & 7 deletions provider/cmd/pulumi-resource-sentry/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build ignore
//go:build ignore

package main

import (
"encoding/json"
"fmt"
"io/ioutil"
"errors"
"io/fs"
"log"
"os"

Expand All @@ -32,7 +32,7 @@ func main() {
log.Fatal("version not found")
}

schemaContents, err := ioutil.ReadFile("./schema.json")
schemaContents, err := os.ReadFile("./schema.json")
if err != nil {
log.Fatal(err)
}
Expand All @@ -49,9 +49,13 @@ func main() {
log.Fatalf("cannot reserialize schema: %v", err)
}

err = ioutil.WriteFile("./schema.go", []byte(fmt.Sprintf(`package main
var pulumiSchema = %#v
`, versionedContents)), 0600)
// Clean up schema.go as it may be present & gitignored and tolerate an error if the file isn't present.
err = os.Remove("./schema.go")
if err != nil && !errors.Is(err, fs.ErrNotExist) {
log.Fatal(err)
}

err = os.WriteFile("./schema-embed.json", versionedContents, 0600)
if err != nil {
log.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions provider/cmd/pulumi-resource-sentry/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@
package main

import (
_ "embed"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"

sentry "github.com/pulumiverse/pulumi-sentry/provider"
"github.com/pulumiverse/pulumi-sentry/provider/pkg/version"
)

//go:embed schema-embed.json
var pulumiSchema []byte

func main() {
// Modify the path to point to the new provider
tfbridge.Main("sentry", version.Version, sentry.Provider(), pulumiSchema)
Expand Down
1 change: 1 addition & 0 deletions provider/cmd/pulumi-resource-sentry/schema-embed.json

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion provider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"fmt"
"path/filepath"

// Enable embedding of package metadata
_ "embed"

"github.com/jianyuan/terraform-provider-sentry/sentry"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
Expand Down Expand Up @@ -50,6 +53,9 @@ func boolRef(b bool) *bool {
return &b
}

//go:embed cmd/pulumi-resource-sentry/bridge-metadata.json
var metadata []byte

// Provider returns additional overlaid schema and metadata associated with the provider..
func Provider() tfbridge.ProviderInfo {
// Instantiate the Terraform provider
Expand Down Expand Up @@ -86,7 +92,8 @@ func Provider() tfbridge.ProviderInfo {
Homepage: "https://github.com/pulumiverse",
Repository: "https://github.com/pulumiverse/pulumi-sentry",
// The GitHub Org for the provider - defaults to `terraform-providers`
GitHubOrg: "jianyuan",
GitHubOrg: "jianyuan",
MetadataInfo: tfbridge.NewProviderMetadata(metadata),
Config: map[string]*tfbridge.SchemaInfo{
// Add any required configuration here, or remove the example below if
// no additional points are required.
Expand Down Expand Up @@ -212,6 +219,7 @@ func Provider() tfbridge.ProviderInfo {
}

prov.SetAutonaming(255, "-")
prov.MustApplyAutoAliases()

return prov
}

0 comments on commit 4d20e85

Please sign in to comment.