Skip to content

Commit

Permalink
Update provider generation guide
Browse files Browse the repository at this point in the history
Fixes crossplane#226

Signed-off-by: Hasan Turken <[email protected]>
  • Loading branch information
turkenh committed Feb 21, 2022
1 parent 6761645 commit 03e41b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions docs/generating-a-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ be quite similar for any other Terraform provider.
```
6. Before generating all resources that the provider has, let's go step by step
and only start with generating `github_repository` and `github_branch`
resources.
and only start with generating CRDs for [github_repository] and
[github_branch] Terraform resources.
To limit the resources to be generated, we need to provide an include list
option with `tjconfig.WithIncludeList` in file `config/provider.go`:
```go
pc := tjconfig.NewProvider(resourceMap, resourcePrefix, modulePath,
pc := tjconfig.NewProviderWithSchema([]byte(providerSchema), resourcePrefix, modulePath,
tjconfig.WithDefaultResourceFn(defaultResourceFn),
tjconfig.WithIncludeList([]string{
"github_repository$",
Expand Down Expand Up @@ -339,5 +339,7 @@ Now let's test our generated resources.
[Terraform GitHub provider]: https://registry.terraform.io/providers/integrations/github/latest/docs
[provider-jet-template]: https://github.com/crossplane-contrib/provider-jet-template
[Terraform documentation for provider configuration]: https://registry.terraform.io/providers/integrations/github/latest/docs#argument-reference
[github_repository]: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/repository
[github_branch]: https://registry.terraform.io/providers/integrations/github/latest/docs/resources/branch
[this line in controller Dockerfile]: https://github.com/crossplane-contrib/provider-jet-template/blob/d9a793dd8a304f09bb2e9694c47c1bade1b6b057/cluster/images/provider-jet-template-controller/Dockerfile#L18-L25
[terraform-plugin-sdk]: https://github.com/hashicorp/terraform-plugin-sdk
4 changes: 2 additions & 2 deletions pkg/config/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ func WithDefaultResourceFn(f DefaultResourceFn) ProviderOption {
// NewProviderWithSchema builds and returns a new Provider from provider
// tfjson schema, that is generated using Terraform CLI with:
// `terraform providers schema --json`
func NewProviderWithSchema(schema string, prefix string, modulePath string, opts ...ProviderOption) *Provider {
func NewProviderWithSchema(schema []byte, prefix string, modulePath string, opts ...ProviderOption) *Provider {
ps := tfjson.ProviderSchemas{}
if err := ps.UnmarshalJSON([]byte(schema)); err != nil {
if err := ps.UnmarshalJSON(schema); err != nil {
panic(err)
}
if len(ps.Schemas) != 1 {
Expand Down

0 comments on commit 03e41b7

Please sign in to comment.