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

Modify imports that are included during code generation #41

Merged
merged 2 commits into from
Sep 11, 2023

Conversation

bendbennett
Copy link
Contributor

@bendbennett bendbennett commented Sep 11, 2023

Requirement for context import

With a spec that looks as follows:

{
  "datasources": [
    {
      "name": "example",
      "schema": {
        "attributes": [
          {
            "name": "bool_attribute",
            "bool": {
              "computed_optional_required": "computed"
            }
          }
        ]
      }
    }
  ],
  "provider": {
    "name": "provider"
  }
}

The generated code is:

// Code generated by terraform-plugin-framework-generator DO NOT EDIT.

package datasource_example

import (
	"context"
	"github.com/hashicorp/terraform-plugin-framework/types"

	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
)

func ExampleDataSourceSchema(ctx context.Context) schema.Schema {
	return schema.Schema{
		Attributes: map[string]schema.Attribute{
			"bool_attribute": schema.BoolAttribute{
				Computed: true,
			},
		},
	}
}

type ExampleModel struct {
	BoolAttribute types.Bool `tfsdk:"bool_attribute"`
}

The context import is required.

Requirement for github.com/hashicorp/terraform-plugin-framework/types/basetypes import

With a spec that looks as follows:

{
  "datasources": [
    {
      "name": "example",
      "schema": {
        "attributes": [
          {
            "name": "list_nested_attribute",
            "list_nested": {
              "computed_optional_required": "optional",
              "nested_object": {
                "attributes": [
                  {
                    "name": "bool_attribute",
                    "bool": {
                      "computed_optional_required": "optional"
                    }
                  }
                ]
              }
            }
          }
        ]
      }
    }
  ],
  "provider": {
    "name": "provider"
  }
}

The generated code includes:

/* ... */

var _ basetypes.ObjectTypable = ListNestedAttributeType{}

/* ... */

var _ basetypes.ObjectValuable = ListNestedAttributeValue{}

The github.com/hashicorp/terraform-plugin-framework/types/basetypes import is required.

@bendbennett bendbennett requested a review from a team as a code owner September 11, 2023 10:52
@bendbennett bendbennett changed the title Import for context is required for simple schemas containing only primitive attributes Modify imports that are included during code generation Sep 11, 2023
Copy link
Contributor

@bflad bflad left a comment

Choose a reason for hiding this comment

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

🚀

@bendbennett bendbennett merged commit 7daebab into main Sep 11, 2023
3 checks passed
@bendbennett bendbennett deleted the include-context-import branch September 11, 2023 14:16
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