hashicorp / terraform-plugin-codegen-spec

Terraform Provider Code Generation Specification and Go Bindings
Mozilla Public License 2.0
7 stars 4 forks source link

Consider modifying validation to account for duplicate names used in attributes and blocks #34

Open bendbennett opened 1 year ago

bendbennett commented 1 year ago

Within the terraform-plugin-codegen-framework, models are generated from the specification. Currently, it is possible for the specification to contain names that are duplicated across attributes and blocks. For instance, the following intermediate representation is currently permitted

{
{
  "datasources": [
    {
      "name": "datasource",
      "schema": {
        "attributes": [
          {
            "name": "one",
          }
        ],
        "blocks": [
          {
            "name": "one",

This results in the generation of a valid schema with the following form:

datasourceDataSourceSchema = schema.Schema{
    Attributes: map[string]schema.Attribute{
        "one": /*...*/
    },
    Blocks: map[string]schema.Block{
        "one": /*...*/
    },
}

However, it also results in the generation of an invalid model with the following form:

type DatasourceModel struct {
    One types.Bool `tfsdk:"one"`
    One types.List `tfsdk:"one"`
}