generated from hashicorp/terraform-provider-scaffolding
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Embed templates for plural data sources.
- Loading branch information
Showing
3 changed files
with
82 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
internal/provider/generators/plural-data-source/schema.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Code generated by generators/plural-data-source/main.go; DO NOT EDIT. | ||
|
||
package {{ .PackageName }} | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-framework/types" | ||
. "github.com/hashicorp/terraform-provider-awscc/internal/generic" | ||
"github.com/hashicorp/terraform-provider-awscc/internal/registry" | ||
) | ||
|
||
func init() { | ||
registry.AddDataSourceTypeFactory("{{ .TerraformTypeName }}", {{ .FactoryFunctionName }}) | ||
} | ||
|
||
// {{ .FactoryFunctionName }} returns the Terraform {{ .TerraformTypeName }} data source type. | ||
// This Terraform data source type corresponds to the CloudFormation {{ .CloudFormationTypeName }} resource type. | ||
func {{ .FactoryFunctionName }}(ctx context.Context) (tfsdk.DataSourceType, error) { | ||
attributes := map[string]tfsdk.Attribute { | ||
"id": { | ||
Description: "Uniquely identifies the data source.", | ||
Type: types.StringType, | ||
Computed: true, | ||
}, | ||
"ids": { | ||
Description: "Set of Resource Identifiers.", | ||
Type: types.SetType{ElemType:types.StringType}, | ||
Computed: true, | ||
}, | ||
} | ||
|
||
schema := tfsdk.Schema{ | ||
Description: "{{ .SchemaDescription }}", | ||
Version: {{ .SchemaVersion }}, | ||
Attributes: attributes, | ||
} | ||
|
||
var opts DataSourceTypeOptions | ||
|
||
opts = opts.WithCloudFormationTypeName("{{ .CloudFormationTypeName }}").WithTerraformTypeName("{{ .TerraformTypeName }}") | ||
opts = opts.WithTerraformSchema(schema) | ||
|
||
pluralDataSourceType, err := NewPluralDataSourceType(ctx, opts...) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return pluralDataSourceType, nil | ||
} |
24 changes: 24 additions & 0 deletions
24
internal/provider/generators/plural-data-source/tests.tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Code generated by generators/plural-data-source/main.go; DO NOT EDIT. | ||
|
||
package {{ .PackageName }}_test | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-awscc/internal/acctest" | ||
) | ||
|
||
func {{ .AcceptanceTestFunctionPrefix }}DataSource_basic(t *testing.T) { | ||
td := acctest.NewTestData(t, "{{ .CloudFormationTypeName }}", "{{ .TerraformTypeName }}", "test") | ||
|
||
td.DataSourceTest(t, []resource.TestStep{ | ||
{ | ||
Config: td.EmptyDataSourceConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrSet(fmt.Sprintf("data.%s", td.ResourceName), "ids.#"), | ||
), | ||
}, | ||
}) | ||
} |