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

Default to generating directory and package per data source, provider and resource #39

Merged
merged 6 commits into from
Sep 7, 2023

Conversation

bendbennett
Copy link
Contributor

@bendbennett bendbennett commented Sep 5, 2023

References: #20

The changes in this PR implement the following behaviour:

  • If the --package flag is omitted when executing the generate command, a directory and package will be generated for each data source, provider and resource that is defined within the intermediate representation / spec.
  • If the --package flag is included when executing the generate command, all generated code will be placed in the same directory and package.

Default Behaviour (--package flag omitted)

For example, if we have an intermediate representation / spec that defines the following data source, provider, and resource:

{
  "datasources": [
    {
      "name": "example",
      "schema": {}
    }
  ],
  "provider": {
    "name": "example",
    "schema": {}
  },
  "resources": [
    {
      "name": "example",
      "schema": {}
    }
  ]
}  

Executing the following generate command:

	go run ./cmd/terraform-plugin-codegen-framework generate all \
		--input ./internal/cmd/testdata/custom_and_external/ir.json \
		--output ./internal/cmd/testdata/custom_and_external/all_output/default_pkg_name

Generates the following output:

├── default_pkg_name
│   ├── datasource_example
│   │   └── example_data_source_gen.go
│   ├── provider_example
│   │   └── example_provider_gen.go
│   └── resource_example
│       └── example_resource_gen.go

The package within each of the three files is then:

package datasource_example
package provider_example
package resource_example

Package Specified (--package flag defined)

Conversely, if the same intermediate representation / spec illustrated above is passed to the generate command, and the --package flag is specified, for instance:

	go run ./cmd/terraform-plugin-codegen-framework generate all \
		--input ./internal/cmd/testdata/custom_and_external/ir.json \
		--package specified \
		--output ./internal/cmd/testdata/custom_and_external/all_output/specified_pkg_name

The following output is generated:

└── specified_pkg_name
    ├── example_data_source_gen.go
    ├── example_provider_gen.go
    └── example_resource_gen.go

The package in all three files is then:

package specified

@bendbennett bendbennett requested a review from a team as a code owner September 5, 2023 08:23
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 🚀

I imagine "naming collisions" will get a documentation section all to itself 😆

@@ -11,7 +11,6 @@ import (
"github.com/google/go-cmp/cmp"
)

// TODO: currently doesn't compare nested directory files
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! 😎

@bendbennett bendbennett merged commit 63bc509 into main Sep 7, 2023
3 checks passed
@bendbennett bendbennett deleted the bendbennett/issues-20 branch September 7, 2023 07:52
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants