Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider: separate schemas into dedicated files #1321

Merged
merged 3 commits into from
Nov 26, 2021

Conversation

jacobbednarz
Copy link
Member

@jacobbednarz jacobbednarz commented Nov 26, 2021

Updates the provider to separate the resource and schema. This unblocks
some possibilities with schema automation, schema reuse between
data sources and resources, and trims down some very large files.

To perform this, I largely relied on comby and a couple of hand
modified files for the outliers.

COMBY_M="$(cat <<"MATCH"
func :[methodname]() *schema.Resource {
	return &schema.Resource{
		:[rest]

		Schema: map[string]*schema.Schema{
			:[attrs]
		},
	}
}
MATCH
)"

COMBY_R="$(cat <<"REWRITE"
func :[methodname]() *schema.Resource {
	return &schema.Resource{
		Schema: :[methodname]Schema(),
		:[rest]	
	}
}

func :[methodname]Schema() map[string]*schema.Schema {
	return map[string]*schema.Schema{
			:[attrs]
	}
}
REWRITE
)"

comby "$COMBY_M" "$COMBY_R" .go -matcher .go

As this PR is largely just whitespace, I recommend viewing with ?w=1
enabled.

I've updated the documentation here too to mention why the file name conventions are
the way they are and what they actually mean. See https://github.com/cloudflare/terraform-provider-cloudflare/pull/1321/files#diff-977f7a75a20da1290fb7ee0adb2dafa4d442433510400bcb01e2fd4ef95f5af5 for full details.

Updates the provider to separate the resource and schema. This unblocks
some possibilities with schema automation, schema reuse between
data sources and resources, and trims down some very large files.
@jacobbednarz
Copy link
Member Author

acceptance tests are all still passing (like master).

@jacobbednarz jacobbednarz merged commit f335d8c into master Nov 26, 2021
@jacobbednarz jacobbednarz deleted the create-schema-files branch November 26, 2021 08:40
github-actions bot pushed a commit that referenced this pull request Nov 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant