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 singular data sources.
- Loading branch information
Showing
3 changed files
with
108 additions
and
106 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/singular-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/singular-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 := {{ .RootPropertiesSchema }} | ||
|
||
attributes["id"] = tfsdk.Attribute{ | ||
Description: "Uniquely identifies the resource.", | ||
Type: types.StringType, | ||
Required: true, | ||
} | ||
|
||
schema := tfsdk.Schema{ | ||
Description: "{{ .SchemaDescription }}", | ||
Version: {{ .SchemaVersion }}, | ||
Attributes: attributes, | ||
} | ||
|
||
var opts DataSourceTypeOptions | ||
|
||
opts = opts.WithCloudFormationTypeName("{{ .CloudFormationTypeName }}").WithTerraformTypeName("{{ .TerraformTypeName }}") | ||
opts = opts.WithTerraformSchema(schema) | ||
opts = opts.WithAttributeNameMap(map[string]string{ | ||
{{- range $key, $value := .AttributeNameMap }} | ||
"{{ $key }}": "{{ $value }}", | ||
{{- end }} | ||
}) | ||
|
||
singularDataSourceType, err := NewSingularDataSourceType(ctx, opts...) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return singularDataSourceType, nil | ||
} |
50 changes: 50 additions & 0 deletions
50
internal/provider/generators/singular-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,50 @@ | ||
// Code generated by generators/singular-data-source/main.go; DO NOT EDIT. | ||
|
||
package {{ .PackageName }}_test | ||
|
||
import ( | ||
{{ if not .HasRequiredAttribute }}"fmt"{{- end }} | ||
"regexp" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-provider-awscc/internal/acctest" | ||
) | ||
|
||
{{ if .HasRequiredAttribute }} | ||
func {{ .AcceptanceTestFunctionPrefix }}DataSource_basic(t *testing.T) { | ||
td := acctest.NewTestData(t, "{{ .CloudFormationTypeName }}", "{{ .TerraformTypeName }}", "test") | ||
|
||
td.DataSourceTest(t, []resource.TestStep{ | ||
{ | ||
Config: td.EmptyDataSourceConfig(), | ||
ExpectError: regexp.MustCompile("Missing required argument"), | ||
}, | ||
}) | ||
} | ||
{{- else }} | ||
func {{ .AcceptanceTestFunctionPrefix }}DataSource_basic(t *testing.T) { | ||
td := acctest.NewTestData(t, "{{ .CloudFormationTypeName }}", "{{ .TerraformTypeName }}", "test") | ||
|
||
td.DataSourceTest(t, []resource.TestStep{ | ||
{ | ||
Config: td.DataSourceWithEmptyResourceConfig(), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttrPair(fmt.Sprintf("data.%s", td.ResourceName), "id", td.ResourceName, "id"), | ||
resource.TestCheckResourceAttrPair(fmt.Sprintf("data.%s", td.ResourceName), "arn", td.ResourceName, "arn"), | ||
), | ||
}, | ||
}) | ||
} | ||
{{- end }} | ||
|
||
func {{ .AcceptanceTestFunctionPrefix }}DataSource_NonExistent(t *testing.T) { | ||
td := acctest.NewTestData(t, "{{ .CloudFormationTypeName }}", "{{ .TerraformTypeName }}", "test") | ||
|
||
td.DataSourceTest(t, []resource.TestStep{ | ||
{ | ||
Config: td.DataSourceWithNonExistentIDConfig(), | ||
ExpectError: regexp.MustCompile("Not Found"), | ||
}, | ||
}) | ||
} |