├── .gitignore ├── .github ├── CODEOWNERS ├── workflows │ ├── compliance.yml │ ├── lock.yml │ └── issue-comment-triage.yml ├── pull_request_template.md └── dependabot.yml ├── CHANGELOG.md ├── internal ├── tf6muxprovider │ ├── provider1 │ │ ├── doc.go │ │ ├── function_string.go │ │ ├── resource_user_test.go │ │ └── provider.go │ ├── provider2 │ │ ├── doc.go │ │ ├── function_string.go │ │ ├── resource_user_test.go │ │ └── provider.go │ ├── main.go │ └── provider.go ├── tf6to5provider │ ├── provider │ │ ├── doc.go │ │ ├── function_string.go │ │ ├── resource_user_test.go │ │ └── provider.go │ ├── main.go │ ├── provider.go │ └── provider_test.go ├── tf5muxprovider │ ├── provider1 │ │ ├── doc.go │ │ ├── provider_test.go │ │ ├── resource_user_test.go │ │ └── provider.go │ ├── provider2 │ │ ├── doc.go │ │ ├── provider_test.go │ │ ├── resource_user_test.go │ │ └── provider.go │ ├── main.go │ ├── provider.go │ └── provider_test.go ├── tf5to6provider │ ├── provider │ │ ├── doc.go │ │ ├── provider_test.go │ │ ├── resource_user_test.go │ │ └── provider.go │ ├── main.go │ ├── provider.go │ └── provider_test.go ├── cornertesting │ ├── doc.go │ ├── string_required_on_create.go │ └── expect_output_type_state_check.go ├── sdkv2testingprovider │ ├── doc.go │ ├── data_source_regions_test.go │ ├── data_source_bigint_test.go │ ├── data_source_regions_cty_test.go │ ├── resource_user_test.go │ ├── resource_bigint_test.go │ ├── data_source_bigint.go │ ├── provider.go │ ├── data_source_regions.go │ ├── provider_test.go │ ├── resource_user_cty_test.go │ ├── data_source_regions_cty.go │ └── resource_bigint.go ├── sdkv2provider │ ├── data_source_regions_test.go │ ├── data_source_bigint_test.go │ ├── data_source_regions_cty_test.go │ ├── resource_user_test.go │ ├── resource_bigint_test.go │ ├── data_source_bigint.go │ ├── resource_write_only_import_test.go │ ├── data_source_regions.go │ ├── resource_user_identity_test.go │ ├── resource_user_cty_test.go │ ├── data_source_regions_cty.go │ ├── provider_test.go │ ├── resource_write_only_upgrade_test.go │ ├── resource_bigint.go │ ├── resource_user_identity_upgrade_test.go │ ├── resource_write_only_upgrade.go │ ├── resource_write_only_import.go │ └── provider.go ├── protocolprovider │ ├── function_bool.go │ ├── function_router.go │ ├── data_time_test.go │ ├── data_router.go │ ├── function_bool_test.go │ ├── deferred_action_test.go │ ├── data_time.go │ └── data_deferred_action.go ├── protocolv6provider │ ├── function_bool.go │ ├── function_router.go │ ├── data_time_test.go │ ├── data_router.go │ ├── function_bool_test.go │ ├── deferred_action_test.go │ ├── data_time.go │ └── data_deferred_action.go ├── framework5provider │ ├── bool_function.go │ ├── int32_function.go │ ├── int64_function.go │ ├── string_function.go │ ├── float32_function.go │ ├── float64_function.go │ ├── ephemeral_resource_spy_client.go │ ├── number_function.go │ ├── dynamic_function.go │ ├── variadic_function.go │ ├── set_function.go │ ├── map_function.go │ ├── list_function.go │ ├── dynamic_variadic_function.go │ ├── writeonly_move_resource_test.go │ ├── writeonly_import_resource_test.go │ ├── writeonly_upgrade_resource_test.go │ ├── timeouts_resource_test.go │ ├── object_function.go │ ├── object_with_dynamic_function.go │ ├── timeouts_resource.go │ ├── list_resource_test.go │ ├── timetypes_resource.go │ ├── dynamic_computed_type_change_resource_test.go │ ├── writeonly_import_resource.go │ ├── bool_function_test.go │ ├── writeonly_move_resource.go │ ├── int32_function_test.go │ └── int64_function_test.go └── framework6provider │ ├── bool_function.go │ ├── int32_function.go │ ├── int64_function.go │ ├── string_function.go │ ├── float32_function.go │ ├── float64_function.go │ ├── ephemeral_resource_spy_client.go │ ├── number_function.go │ ├── dynamic_function.go │ ├── variadic_function.go │ ├── set_function.go │ ├── map_function.go │ ├── list_function.go │ ├── dynamic_variadic_function.go │ ├── writeonly_move_resource_test.go │ ├── writeonly_import_resource_test.go │ ├── writeonly_upgrade_resource_test.go │ ├── timeouts_resource_test.go │ ├── object_function.go │ ├── object_with_dynamic_function.go │ ├── timeouts_resource.go │ ├── timetypes_resource.go │ ├── dynamic_computed_type_change_resource_test.go │ ├── writeonly_import_resource.go │ ├── bool_function_test.go │ └── writeonly_move_resource.go ├── META.d └── _summary.yaml ├── tools ├── copywrite.go └── go.mod ├── README.md ├── scripts └── gofmtcheck.sh ├── GNUmakefile ├── .copywrite.hcl ├── .golangci.yml └── main.go /.gitignore: -------------------------------------------------------------------------------- 1 | go.work* -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @hashicorp/terraform-core-plugins 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.1.0 (Unreleased) 2 | 3 | BACKWARDS INCOMPATIBILITIES / NOTES: 4 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider1/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // This provider is mainly a duplicate of internal/frameworkprovider 5 | package provider1 6 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider2/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // This provider is mainly a duplicate of internal/frameworkprovider 5 | package provider2 6 | -------------------------------------------------------------------------------- /internal/tf6to5provider/provider/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // This provider is mainly a duplicate of internal/frameworkprovider 5 | package provider 6 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider1/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // This provider is mainly a duplicate of the user portion of internal/sdkv2provider 5 | package provider1 6 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider2/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // This provider is mainly a duplicate of the user portion of internal/sdkv2provider 5 | package provider2 6 | -------------------------------------------------------------------------------- /internal/tf5to6provider/provider/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // This provider is mainly a duplicate of the user portion of internal/sdkv2provider 5 | package provider 6 | -------------------------------------------------------------------------------- /internal/cornertesting/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // The cornertesting package implements state checks that assist in corner provider testing. 5 | package cornertesting 6 | -------------------------------------------------------------------------------- /META.d/_summary.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | schema: 1.1 3 | 4 | partition: tf-ecosystem 5 | 6 | summary: 7 | owner: team-tf-core-plugins 8 | description: | 9 | A Terraform provider of corner cases, used for testing Terraform and its SDK. 10 | visibility: public 11 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | // Package sdkv2testingprovider is a duplicate of sdkv2, however it uses 5 | // terraform-plugin-sdk/v2/helper/resource for testing instead of 6 | // terraform-plugin-testing. 7 | package sdkv2testingprovider 8 | -------------------------------------------------------------------------------- /tools/copywrite.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //go:build generate 5 | 6 | package tools 7 | 8 | import ( 9 | // copywrite header generation 10 | _ "github.com/hashicorp/copywrite" 11 | ) 12 | 13 | //go:generate go run github.com/hashicorp/copywrite headers -d .. --config ../.copywrite.hcl 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-provider-corner 2 | A Terraform provider of corner cases, used for testing Terraform and its SDK. 3 | 4 | ## License Headers 5 | 6 | All source code files (excluding autogenerated files like `go.mod`, prose, and files excluded in [.copywrite.hcl](.copywrite.hcl)) must have a license header at the top. 7 | 8 | This can be autogenerated by running `make generate` or running `go generate ./...` in the [/tools](/tools) directory. 9 | -------------------------------------------------------------------------------- /.github/workflows/compliance.yml: -------------------------------------------------------------------------------- 1 | name: compliance 2 | 3 | on: 4 | pull_request: 5 | 6 | permissions: 7 | contents: read 8 | 9 | jobs: 10 | # Reference: ENGSRV-059 11 | copywrite: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 15 | - uses: hashicorp/setup-copywrite@32638da2d4e81d56a0764aa1547882fc4d209636 # v1.1.3 16 | - run: copywrite headers --plan 17 | - run: copywrite license --plan 18 | -------------------------------------------------------------------------------- /scripts/gofmtcheck.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Copyright (c) HashiCorp, Inc. 3 | # SPDX-License-Identifier: MPL-2.0 4 | 5 | set -e 6 | 7 | echo "==> Checking that code complies with gofmt requirements..." 8 | gofmt_files=$(gofmt -s -l `find . -name '*.go'`) 9 | if [[ -n ${gofmt_files} ]]; then 10 | echo 'gofmt needs running on the following files:' 11 | echo "${gofmt_files}" 12 | echo "You can use the command: \`make fmt\` to reformat code." 13 | exit 1 14 | fi 15 | 16 | exit 0 17 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf5muxprovider 5 | 6 | import ( 7 | "log" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server" 10 | ) 11 | 12 | //nolint:unused // Test provider server, executed by test framework 13 | func main() { 14 | provider, err := New() 15 | 16 | if err != nil { 17 | log.Fatalf("unable to create provider: %s", err) 18 | } 19 | 20 | err = tf5server.Serve("registry.terraform.io/hashicorp/corner", provider) 21 | 22 | if err != nil { 23 | log.Fatalf("unable to serve provider: %s", err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /internal/tf5to6provider/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf5to6provider 5 | 6 | import ( 7 | "log" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server" 10 | ) 11 | 12 | //nolint:unused // Test provider server, executed by test framework 13 | func main() { 14 | provider, err := New() 15 | 16 | if err != nil { 17 | log.Fatalf("unable to create provider: %s", err) 18 | } 19 | 20 | err = tf6server.Serve("registry.terraform.io/hashicorp/corner", provider) 21 | 22 | if err != nil { 23 | log.Fatalf("unable to serve provider: %s", err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf6muxprovider 5 | 6 | import ( 7 | "log" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6/tf6server" 10 | ) 11 | 12 | //nolint:unused // Test provider server, executed by test framework 13 | func main() { 14 | provider, err := New() 15 | 16 | if err != nil { 17 | log.Fatalf("unable to create provider: %s", err) 18 | } 19 | 20 | err = tf6server.Serve("registry.terraform.io/hashicorp/corner", provider) 21 | 22 | if err != nil { 23 | log.Fatalf("unable to serve provider: %s", err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /internal/tf6to5provider/main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf6to5provider 5 | 6 | import ( 7 | "log" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server" 10 | ) 11 | 12 | //nolint:unused // Test provider server, executed by test framework 13 | func main() { 14 | provider, err := New() 15 | 16 | if err != nil { 17 | log.Fatalf("unable to create provider: %s", err) 18 | } 19 | 20 | err = tf5server.Serve("registry.terraform.io/hashicorp/corner", provider) 21 | 22 | if err != nil { 23 | log.Fatalf("unable to serve provider: %s", err) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | GOFMT_FILES?=$$(find . -name '*.go') 2 | 3 | default: testacc 4 | 5 | # Run acceptance tests 6 | testacc: 7 | TF_ACC=1 go test ./... -v $(TESTARGS) -timeout 120m -count 1 8 | 9 | fmt: 10 | gofmt -w $(GOFMT_FILES) 11 | 12 | vet: 13 | @echo "go vet ." 14 | @go vet $$(go list ./...) ; if [ $$? -eq 1 ]; then \ 15 | echo ""; \ 16 | echo "Vet found suspicious constructs. Please check the reported constructs"; \ 17 | echo "and fix them if necessary before submitting the code for review."; \ 18 | exit 1; \ 19 | fi 20 | 21 | # Generate copywrite headers 22 | generate: 23 | cd tools; go generate ./... 24 | 25 | .PHONY: testacc vet fmt 26 | -------------------------------------------------------------------------------- /internal/tf5to6provider/provider/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 10 | ) 11 | 12 | var testAccProviders map[string]*schema.Provider 13 | var testAccProvider *schema.Provider 14 | 15 | func init() { 16 | testAccProvider = New() 17 | testAccProviders = map[string]*schema.Provider{ 18 | "tf5to6provider": testAccProvider, 19 | } 20 | } 21 | 22 | func TestProvider(t *testing.T) { 23 | if err := New().InternalValidate(); err != nil { 24 | t.Fatalf("err: %s", err) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider1/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider1 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 10 | ) 11 | 12 | var testAccProviders map[string]*schema.Provider 13 | var testAccProvider *schema.Provider 14 | 15 | func init() { 16 | testAccProvider = New() 17 | testAccProviders = map[string]*schema.Provider{ 18 | "tf5muxprovider": testAccProvider, 19 | } 20 | } 21 | 22 | func TestProvider(t *testing.T) { 23 | if err := New().InternalValidate(); err != nil { 24 | t.Fatalf("err: %s", err) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider2/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 10 | ) 11 | 12 | var testAccProviders map[string]*schema.Provider 13 | var testAccProvider *schema.Provider 14 | 15 | func init() { 16 | testAccProvider = New() 17 | testAccProviders = map[string]*schema.Provider{ 18 | "tf5muxprovider": testAccProvider, 19 | } 20 | } 21 | 22 | func TestProvider(t *testing.T) { 23 | if err := New().InternalValidate(); err != nil { 24 | t.Fatalf("err: %s", err) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Related Issue 2 | 3 | Fixes # 4 | 5 | ## Description 6 | 7 | In plain English, describe your approach to addressing the issue linked above. For example, if you made a particular design decision, let us know why you chose this path instead of another solution. 8 | 9 | 10 | ## Rollback Plan 11 | 12 | - [ ] If a change needs to be reverted, we will roll out an update to the code within 7 days. 13 | 14 | ## Changes to Security Controls 15 | 16 | Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain. 17 | -------------------------------------------------------------------------------- /internal/tf5to6provider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf5to6provider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 10 | "github.com/hashicorp/terraform-plugin-mux/tf5to6server" 11 | "github.com/hashicorp/terraform-provider-corner/internal/tf5to6provider/provider" 12 | ) 13 | 14 | func New() (func() tfprotov6.ProviderServer, error) { 15 | ctx := context.Background() 16 | 17 | upgradeServer, err := tf5to6server.UpgradeServer(ctx, provider.New().GRPCProvider) 18 | 19 | if err != nil { 20 | return nil, err 21 | } 22 | 23 | return func() tfprotov6.ProviderServer { 24 | return upgradeServer 25 | }, nil 26 | } 27 | -------------------------------------------------------------------------------- /internal/sdkv2provider/data_source_regions_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 10 | ) 11 | 12 | func testAccDataSourceRegions(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configDataSourceBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttrSet("data.corner_regions.foo", "names.#")), 21 | }, 22 | }, 23 | } 24 | } 25 | 26 | const configDataSourceBasic = ` 27 | data "corner_regions" "foo" { 28 | } 29 | ` 30 | -------------------------------------------------------------------------------- /.copywrite.hcl: -------------------------------------------------------------------------------- 1 | schema_version = 1 2 | 3 | project { 4 | license = "MPL-2.0" 5 | copyright_year = 2020 6 | 7 | header_ignore = [ 8 | # internal catalog metadata (prose) 9 | "META.d/**/*.yaml", 10 | 11 | # changie tooling configuration and CHANGELOG entries (prose) 12 | ".changes/unreleased/*.yaml", 13 | ".changie.yaml", 14 | 15 | # GitHub issue template configuration 16 | ".github/ISSUE_TEMPLATE/*.yml", 17 | 18 | # GitHub Actions workflow-specific configurations 19 | ".github/labeler-*.yml", 20 | 21 | # golangci-lint tooling configuration 22 | ".golangci.yml", 23 | 24 | # GoReleaser tooling configuration 25 | ".goreleaser.yml", 26 | 27 | # Release Engineering tooling configuration 28 | ".release/*.hcl", 29 | ] 30 | } 31 | -------------------------------------------------------------------------------- /internal/sdkv2provider/data_source_bigint_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 10 | ) 11 | 12 | func testAccDataSourceBigint(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configDataSourceBigint, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttr("data.corner_bigint.foo", "int64", "7227701560655103598")), 21 | }, 22 | }, 23 | } 24 | } 25 | 26 | const configDataSourceBigint = ` 27 | data "corner_bigint" "foo" { 28 | } 29 | ` 30 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "gomod" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | groups: 8 | # Group all terraform-plugin-(go|sdk|framework|testing) dependencies together 9 | "terraform-plugin": 10 | patterns: 11 | - "github.com/hashicorp/terraform-plugin-*" 12 | - package-ecosystem: "gomod" 13 | directory: "/tools" 14 | schedule: 15 | interval: "daily" 16 | - package-ecosystem: "github-actions" 17 | directory: "/" 18 | groups: 19 | "github-actions": 20 | patterns: 21 | - "*" # Group all GitHub Actions dependencies together 22 | schedule: 23 | interval: "weekly" 24 | day: "monday" 25 | time: "09:00" 26 | timezone: "Etc/UTC" 27 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/data_source_regions_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 10 | ) 11 | 12 | func testAccDataSourceRegions(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configDataSourceBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttrSet("data.corner_regions.foo", "names.#")), 21 | }, 22 | }, 23 | } 24 | } 25 | 26 | const configDataSourceBasic = ` 27 | data "corner_regions" "foo" { 28 | } 29 | ` 30 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/data_source_bigint_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 10 | ) 11 | 12 | func testAccDataSourceBigint(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configDataSourceBigint, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttr("data.corner_bigint.foo", "int64", "7227701560655103598")), 21 | }, 22 | }, 23 | } 24 | } 25 | 26 | const configDataSourceBigint = ` 27 | data "corner_bigint" "foo" { 28 | } 29 | ` 30 | -------------------------------------------------------------------------------- /internal/tf6to5provider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf6to5provider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-mux/tf6to5server" 12 | "github.com/hashicorp/terraform-provider-corner/internal/tf6to5provider/provider" 13 | ) 14 | 15 | func New() (func() tfprotov5.ProviderServer, error) { 16 | ctx := context.Background() 17 | 18 | downgradeServer, err := tf6to5server.DowngradeServer(ctx, providerserver.NewProtocol6(provider.New())) 19 | 20 | if err != nil { 21 | return nil, err 22 | } 23 | 24 | return func() tfprotov5.ProviderServer { 25 | return downgradeServer 26 | }, nil 27 | } 28 | -------------------------------------------------------------------------------- /internal/sdkv2provider/data_source_regions_cty_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 10 | ) 11 | 12 | func testAccDataSourceRegionsCty(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configDataSourceRegionsCtyBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttrSet("data.corner_regions_cty.foo", "names.#")), 21 | }, 22 | }, 23 | } 24 | } 25 | 26 | const configDataSourceRegionsCtyBasic = ` 27 | data "corner_regions_cty" "foo" { 28 | filter = "foo" 29 | } 30 | ` 31 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/data_source_regions_cty_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 10 | ) 11 | 12 | func testAccDataSourceRegionsCty(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configDataSourceRegionsCtyBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttrSet("data.corner_regions_cty.foo", "names.#")), 21 | }, 22 | }, 23 | } 24 | } 25 | 26 | const configDataSourceRegionsCtyBasic = ` 27 | data "corner_regions_cty" "foo" { 28 | filter = "foo" 29 | } 30 | ` 31 | -------------------------------------------------------------------------------- /.github/workflows/lock.yml: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT - This GitHub Workflow is managed by automation 2 | # https://github.com/hashicorp/terraform-devex-repos 3 | name: 'Lock Threads' 4 | 5 | on: 6 | schedule: 7 | - cron: '0 19 * * *' 8 | 9 | jobs: 10 | lock: 11 | runs-on: ubuntu-latest 12 | steps: 13 | # NOTE: When TSCCR updates the GitHub action version, update the template workflow file to avoid drift: 14 | # https://github.com/hashicorp/terraform-devex-repos/blob/main/modules/repo/workflows/lock.tftpl 15 | - uses: dessant/lock-threads@7266a7ce5c1df01b1c6db85bf8cd86c737dadbe7 # v6.0.0 16 | with: 17 | process-only: 'issues, prs' 18 | github-token: ${{ github.token }} 19 | issue-inactive-days: '30' 20 | issue-lock-reason: resolved 21 | pr-inactive-days: '30' 22 | pr-lock-reason: resolved 23 | -------------------------------------------------------------------------------- /internal/tf5to6provider/provider/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | ) 12 | 13 | func TestAccResourceUser(t *testing.T) { 14 | resource.UnitTest(t, resource.TestCase{ 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configResourceBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestMatchResourceAttr("tf5to6provider_user.example", "name", regexp.MustCompile("^Exam")), 21 | ), 22 | }, 23 | }, 24 | }) 25 | } 26 | 27 | const configResourceBasic = ` 28 | resource "tf5to6provider_user" "example" { 29 | age = 200 30 | email = "example@example.com" 31 | name = "Example Name" 32 | } 33 | ` 34 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider1/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider1 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | ) 12 | 13 | func TestAccResourceUser1(t *testing.T) { 14 | resource.UnitTest(t, resource.TestCase{ 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configResourceBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestMatchResourceAttr("tf5muxprovider_user1.example", "name", regexp.MustCompile("^Exam")), 21 | ), 22 | }, 23 | }, 24 | }) 25 | } 26 | 27 | const configResourceBasic = ` 28 | resource "tf5muxprovider_user1" "example" { 29 | age = 200 30 | email = "example@example.com" 31 | name = "Example Name" 32 | } 33 | ` 34 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider2/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider2 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | ) 12 | 13 | func TestAccResourceUser2(t *testing.T) { 14 | resource.UnitTest(t, resource.TestCase{ 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configResourceBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestMatchResourceAttr("tf5muxprovider_user2.example", "name", regexp.MustCompile("^Exam")), 21 | ), 22 | }, 23 | }, 24 | }) 25 | } 26 | 27 | const configResourceBasic = ` 28 | resource "tf5muxprovider_user2" "example" { 29 | age = 200 30 | email = "example@example.com" 31 | name = "Example Name" 32 | } 33 | ` 34 | -------------------------------------------------------------------------------- /internal/protocolprovider/function_bool.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | "github.com/hashicorp/terraform-plugin-go/tftypes" 11 | ) 12 | 13 | type functionBool struct{} 14 | 15 | func (f functionBool) CallFunction(context.Context, *tfprotov5.CallFunctionRequest) (*tfprotov5.CallFunctionResponse, error) { 16 | value, err := tfprotov5.NewDynamicValue(tftypes.Bool, tftypes.NewValue(tftypes.Bool, true)) 17 | 18 | if err != nil { 19 | return nil, err 20 | } 21 | 22 | return &tfprotov5.CallFunctionResponse{ 23 | Result: &value, 24 | }, nil 25 | } 26 | 27 | func (f functionBool) GetFunctions(context.Context, *tfprotov5.GetFunctionsRequest) (*tfprotov5.GetFunctionsResponse, error) { 28 | panic("implement me") 29 | } 30 | -------------------------------------------------------------------------------- /internal/protocolv6provider/function_bool.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 10 | "github.com/hashicorp/terraform-plugin-go/tftypes" 11 | ) 12 | 13 | type functionBool struct{} 14 | 15 | func (f functionBool) CallFunction(context.Context, *tfprotov6.CallFunctionRequest) (*tfprotov6.CallFunctionResponse, error) { 16 | value, err := tfprotov6.NewDynamicValue(tftypes.Bool, tftypes.NewValue(tftypes.Bool, true)) 17 | 18 | if err != nil { 19 | return nil, err 20 | } 21 | 22 | return &tfprotov6.CallFunctionResponse{ 23 | Result: &value, 24 | }, nil 25 | } 26 | 27 | func (f functionBool) GetFunctions(context.Context, *tfprotov6.GetFunctionsRequest) (*tfprotov6.GetFunctionsResponse, error) { 28 | panic("implement me") 29 | } 30 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf5muxprovider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" 11 | "github.com/hashicorp/terraform-provider-corner/internal/tf5muxprovider/provider1" 12 | "github.com/hashicorp/terraform-provider-corner/internal/tf5muxprovider/provider2" 13 | ) 14 | 15 | func New() (func() tfprotov5.ProviderServer, error) { 16 | ctx := context.Background() 17 | providers := []func() tfprotov5.ProviderServer{ 18 | provider1.New().GRPCProvider, 19 | provider2.New().GRPCProvider, 20 | } 21 | 22 | muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...) 23 | 24 | if err != nil { 25 | return nil, err 26 | } 27 | 28 | return muxServer.ProviderServer, nil 29 | } 30 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | ) 12 | 13 | func testAccResourceUser(t *testing.T) resource.TestCase { 14 | return resource.TestCase{ 15 | PreCheck: func() { testAccPreCheck(t) }, 16 | Providers: testAccProviders, 17 | Steps: []resource.TestStep{ 18 | { 19 | Config: configResourceBasic, 20 | Check: resource.ComposeTestCheckFunc( 21 | resource.TestMatchResourceAttr( 22 | "corner_user.foo", "name", regexp.MustCompile("^For")), 23 | ), 24 | }, 25 | }, 26 | } 27 | } 28 | 29 | const configResourceBasic = ` 30 | resource "corner_user" "foo" { 31 | email = "ford@prefect.co" 32 | name = "Ford Prefect" 33 | age = 200 34 | } 35 | ` 36 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 11 | ) 12 | 13 | func testAccResourceUser(t *testing.T) resource.TestCase { 14 | return resource.TestCase{ 15 | PreCheck: func() { testAccPreCheck(t) }, 16 | Providers: testAccProviders, 17 | Steps: []resource.TestStep{ 18 | { 19 | Config: configResourceBasic, 20 | Check: resource.ComposeTestCheckFunc( 21 | resource.TestMatchResourceAttr( 22 | "corner_user.foo", "name", regexp.MustCompile("^For")), 23 | ), 24 | }, 25 | }, 26 | } 27 | } 28 | 29 | const configResourceBasic = ` 30 | resource "corner_user" "foo" { 31 | email = "ford@prefect.co" 32 | name = "Ford Prefect" 33 | age = 200 34 | } 35 | ` 36 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_bigint_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 10 | ) 11 | 12 | func testAccResourceBigint(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configResourceBigint, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttr("corner_bigint.foo", "number", "7227701560655103598"), 21 | resource.TestCheckResourceAttr("corner_bigint.foo", "int64", "7227701560655103598"), 22 | ), 23 | }, 24 | }, 25 | } 26 | } 27 | 28 | const configResourceBigint = ` 29 | resource "corner_bigint" "foo" { 30 | number = 7227701560655103598 31 | } 32 | ` 33 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/resource_bigint_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 10 | ) 11 | 12 | func testAccResourceBigint(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configResourceBigint, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttr("corner_bigint.foo", "number", "7227701560655103598"), 21 | resource.TestCheckResourceAttr("corner_bigint.foo", "int64", "7227701560655103598"), 22 | ), 23 | }, 24 | }, 25 | } 26 | } 27 | 28 | const configResourceBigint = ` 29 | resource "corner_bigint" "foo" { 30 | number = 7227701560655103598 31 | } 32 | ` 33 | -------------------------------------------------------------------------------- /internal/protocolprovider/function_router.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | ) 11 | 12 | type errUnsupportedFunction string 13 | 14 | func (e errUnsupportedFunction) Error() string { 15 | return "unsupported function: " + string(e) 16 | } 17 | 18 | type functionRouter map[string]tfprotov5.FunctionServer 19 | 20 | func (f functionRouter) CallFunction(ctx context.Context, req *tfprotov5.CallFunctionRequest) (*tfprotov5.CallFunctionResponse, error) { 21 | fu, ok := f[req.Name] 22 | 23 | if !ok { 24 | return nil, errUnsupportedFunction(req.Name) 25 | } 26 | 27 | return fu.CallFunction(ctx, req) 28 | } 29 | 30 | func (f functionRouter) GetFunctions(ctx context.Context, req *tfprotov5.GetFunctionsRequest) (*tfprotov5.GetFunctionsResponse, error) { 31 | panic("not implemented") 32 | } 33 | -------------------------------------------------------------------------------- /internal/protocolv6provider/function_router.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 10 | ) 11 | 12 | type errUnsupportedFunction string 13 | 14 | func (e errUnsupportedFunction) Error() string { 15 | return "unsupported function: " + string(e) 16 | } 17 | 18 | type functionRouter map[string]tfprotov6.FunctionServer 19 | 20 | func (f functionRouter) CallFunction(ctx context.Context, req *tfprotov6.CallFunctionRequest) (*tfprotov6.CallFunctionResponse, error) { 21 | fu, ok := f[req.Name] 22 | 23 | if !ok { 24 | return nil, errUnsupportedFunction(req.Name) 25 | } 26 | 27 | return fu.CallFunction(ctx, req) 28 | } 29 | 30 | func (f functionRouter) GetFunctions(ctx context.Context, req *tfprotov6.GetFunctionsRequest) (*tfprotov6.GetFunctionsResponse, error) { 31 | panic("not implemented") 32 | } 33 | -------------------------------------------------------------------------------- /internal/sdkv2provider/data_source_bigint.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | ) 12 | 13 | func dataSourceBigint() *schema.Resource { 14 | return &schema.Resource{ 15 | EnableLegacyTypeSystemPlanErrors: true, 16 | EnableLegacyTypeSystemApplyErrors: true, 17 | 18 | ReadContext: dataSourceBigintRead, 19 | 20 | Schema: map[string]*schema.Schema{ 21 | "int64": { 22 | Type: schema.TypeInt, 23 | Computed: true, 24 | }, 25 | }, 26 | } 27 | } 28 | 29 | func dataSourceBigintRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 30 | d.SetId("7227701560655103598") 31 | 32 | if err := d.Set("int64", 7227701560655103598); err != nil { 33 | return diag.FromErr(err) 34 | } 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf6muxprovider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" 12 | "github.com/hashicorp/terraform-provider-corner/internal/tf6muxprovider/provider1" 13 | "github.com/hashicorp/terraform-provider-corner/internal/tf6muxprovider/provider2" 14 | ) 15 | 16 | func New() (func() tfprotov6.ProviderServer, error) { 17 | ctx := context.Background() 18 | providers := []func() tfprotov6.ProviderServer{ 19 | providerserver.NewProtocol6(provider1.New()), 20 | providerserver.NewProtocol6(provider2.New()), 21 | } 22 | 23 | muxServer, err := tf6muxserver.NewMuxServer(ctx, providers...) 24 | 25 | if err != nil { 26 | return nil, err 27 | } 28 | 29 | return muxServer.ProviderServer, nil 30 | } 31 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/data_source_bigint.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | ) 12 | 13 | func dataSourceBigint() *schema.Resource { 14 | return &schema.Resource{ 15 | EnableLegacyTypeSystemPlanErrors: true, 16 | EnableLegacyTypeSystemApplyErrors: true, 17 | 18 | ReadContext: dataSourceBigintRead, 19 | 20 | Schema: map[string]*schema.Schema{ 21 | "int64": { 22 | Type: schema.TypeInt, 23 | Computed: true, 24 | }, 25 | }, 26 | } 27 | } 28 | 29 | func dataSourceBigintRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 30 | d.SetId("7227701560655103598") 31 | 32 | if err := d.Set("int64", 7227701560655103598); err != nil { 33 | return diag.FromErr(err) 34 | } 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /internal/tf5to6provider/provider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 12 | ) 13 | 14 | func New() *schema.Provider { 15 | p := &schema.Provider{ 16 | DataSourcesMap: map[string]*schema.Resource{}, 17 | ResourcesMap: map[string]*schema.Resource{ 18 | "tf5to6provider_user": resourceUser(), 19 | }, 20 | } 21 | 22 | p.ConfigureContextFunc = configure(p) 23 | 24 | return p 25 | } 26 | 27 | func configure(p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 28 | return func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 29 | client, err := backend.NewClient() 30 | if err != nil { 31 | return nil, diag.FromErr(err) 32 | } 33 | return client, nil 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider1/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider1 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 12 | ) 13 | 14 | func New() *schema.Provider { 15 | p := &schema.Provider{ 16 | DataSourcesMap: map[string]*schema.Resource{}, 17 | ResourcesMap: map[string]*schema.Resource{ 18 | "tf5muxprovider_user1": resourceUser(), 19 | }, 20 | } 21 | 22 | p.ConfigureContextFunc = configure(p) 23 | 24 | return p 25 | } 26 | 27 | func configure(p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 28 | return func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 29 | client, err := backend.NewClient() 30 | if err != nil { 31 | return nil, diag.FromErr(err) 32 | } 33 | return client, nil 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider2/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider2 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 12 | ) 13 | 14 | func New() *schema.Provider { 15 | p := &schema.Provider{ 16 | DataSourcesMap: map[string]*schema.Resource{}, 17 | ResourcesMap: map[string]*schema.Resource{ 18 | "tf5muxprovider_user2": resourceUser(), 19 | }, 20 | } 21 | 22 | p.ConfigureContextFunc = configure(p) 23 | 24 | return p 25 | } 26 | 27 | func configure(p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 28 | return func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 29 | client, err := backend.NewClient() 30 | if err != nil { 31 | return nil, diag.FromErr(err) 32 | } 33 | return client, nil 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /.github/workflows/issue-comment-triage.yml: -------------------------------------------------------------------------------- 1 | # DO NOT EDIT - This GitHub Workflow is managed by automation 2 | # https://github.com/hashicorp/terraform-devex-repos 3 | name: Issue Comment Triage 4 | 5 | on: 6 | issue_comment: 7 | types: [created] 8 | 9 | jobs: 10 | issue_comment_triage: 11 | runs-on: ubuntu-latest 12 | env: 13 | # issue_comment events are triggered by comments on issues and pull requests. Checking the 14 | # value of github.event.issue.pull_request tells us whether the issue is an issue or is 15 | # actually a pull request, allowing us to dynamically set the gh subcommand: 16 | # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#issue_comment-on-issues-only-or-pull-requests-only 17 | COMMAND: ${{ github.event.issue.pull_request && 'pr' || 'issue' }} 18 | GH_TOKEN: ${{ github.token }} 19 | steps: 20 | - name: 'Remove waiting-response on comment' 21 | run: gh ${{ env.COMMAND }} edit ${{ github.event.issue.html_url }} --remove-label waiting-response 22 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_write_only_import_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 10 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 11 | ) 12 | 13 | func TestWriteOnlyImportResource(t *testing.T) { 14 | t.Parallel() 15 | 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Write-only attributes are only available in 1.11.0+ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_11_0), 20 | }, 21 | Providers: testAccProviders, 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: `resource "corner_writeonly_import" "test" { 25 | string_attr = "hello world!" 26 | writeonly_string = "fakepassword" 27 | }`, 28 | }, 29 | { 30 | ResourceName: "corner_writeonly_import.test", 31 | ImportState: true, 32 | ImportStateVerify: true, 33 | }, 34 | }, 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /internal/protocolprovider/data_time_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | ) 13 | 14 | func TestAccDataSourceTime(t *testing.T) { 15 | resource.UnitTest(t, resource.TestCase{ 16 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 17 | //nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 18 | "corner": func() (tfprotov5.ProviderServer, error) { 19 | return Server(false), nil 20 | }, 21 | }, 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: testAccDataSourceTimeConfig, 25 | Check: resource.ComposeTestCheckFunc( 26 | resource.TestMatchResourceAttr("data.corner_time.foo", "current", regexp.MustCompile(`[0-9]+`)), 27 | ), 28 | }, 29 | }, 30 | }) 31 | } 32 | 33 | var testAccDataSourceTimeConfig = `data "corner_time" "foo" { 34 | 35 | }` 36 | -------------------------------------------------------------------------------- /internal/protocolv6provider/data_time_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | ) 13 | 14 | func TestAccV6DataSourceTime(t *testing.T) { 15 | resource.UnitTest(t, resource.TestCase{ 16 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 17 | //nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 18 | "corner": func() (tfprotov6.ProviderServer, error) { 19 | return Server(false), nil 20 | }, 21 | }, 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: testAccDataSourceTimeConfig, 25 | Check: resource.ComposeTestCheckFunc( 26 | resource.TestMatchResourceAttr("data.corner_v6_time.foo", "current", regexp.MustCompile(`[0-9]+`)), 27 | ), 28 | }, 29 | }, 30 | }) 31 | } 32 | 33 | var testAccDataSourceTimeConfig = `data "corner_v6_time" "foo" { 34 | 35 | }` 36 | -------------------------------------------------------------------------------- /internal/protocolprovider/data_router.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | ) 11 | 12 | type errUnsupportedDataSource string 13 | 14 | func (e errUnsupportedDataSource) Error() string { 15 | return "unsupported data source: " + string(e) 16 | } 17 | 18 | type dataSourceRouter map[string]tfprotov5.DataSourceServer 19 | 20 | func (d dataSourceRouter) ValidateDataSourceConfig(ctx context.Context, req *tfprotov5.ValidateDataSourceConfigRequest) (*tfprotov5.ValidateDataSourceConfigResponse, error) { 21 | ds, ok := d[req.TypeName] 22 | if !ok { 23 | return nil, errUnsupportedDataSource(req.TypeName) 24 | } 25 | return ds.ValidateDataSourceConfig(ctx, req) 26 | } 27 | 28 | func (d dataSourceRouter) ReadDataSource(ctx context.Context, req *tfprotov5.ReadDataSourceRequest) (*tfprotov5.ReadDataSourceResponse, error) { 29 | ds, ok := d[req.TypeName] 30 | if !ok { 31 | return nil, errUnsupportedDataSource(req.TypeName) 32 | } 33 | return ds.ReadDataSource(ctx, req) 34 | } 35 | -------------------------------------------------------------------------------- /internal/protocolv6provider/data_router.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 10 | ) 11 | 12 | type errUnsupportedDataSource string 13 | 14 | func (e errUnsupportedDataSource) Error() string { 15 | return "unsupported data source: " + string(e) 16 | } 17 | 18 | type dataSourceRouter map[string]tfprotov6.DataSourceServer 19 | 20 | func (d dataSourceRouter) ValidateDataResourceConfig(ctx context.Context, req *tfprotov6.ValidateDataResourceConfigRequest) (*tfprotov6.ValidateDataResourceConfigResponse, error) { 21 | ds, ok := d[req.TypeName] 22 | if !ok { 23 | return nil, errUnsupportedDataSource(req.TypeName) 24 | } 25 | return ds.ValidateDataResourceConfig(ctx, req) 26 | } 27 | 28 | func (d dataSourceRouter) ReadDataSource(ctx context.Context, req *tfprotov6.ReadDataSourceRequest) (*tfprotov6.ReadDataSourceResponse, error) { 29 | ds, ok := d[req.TypeName] 30 | if !ok { 31 | return nil, errUnsupportedDataSource(req.TypeName) 32 | } 33 | return ds.ReadDataSource(ctx, req) 34 | } 35 | -------------------------------------------------------------------------------- /internal/framework5provider/bool_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = BoolFunction{} 13 | 14 | func NewBoolFunction() function.Function { 15 | return &BoolFunction{} 16 | } 17 | 18 | type BoolFunction struct{} 19 | 20 | func (f BoolFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "bool" 22 | } 23 | 24 | func (f BoolFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.BoolParameter{ 28 | Name: "bool_param", 29 | }, 30 | }, 31 | Return: function.BoolReturn{}, 32 | } 33 | } 34 | 35 | func (f BoolFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg bool 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework6provider/bool_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = BoolFunction{} 13 | 14 | func NewBoolFunction() function.Function { 15 | return &BoolFunction{} 16 | } 17 | 18 | type BoolFunction struct{} 19 | 20 | func (f BoolFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "bool" 22 | } 23 | 24 | func (f BoolFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.BoolParameter{ 28 | Name: "bool_param", 29 | }, 30 | }, 31 | Return: function.BoolReturn{}, 32 | } 33 | } 34 | 35 | func (f BoolFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg bool 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework5provider/int32_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Int32Function{} 13 | 14 | func NewInt32Function() function.Function { 15 | return &Int32Function{} 16 | } 17 | 18 | type Int32Function struct{} 19 | 20 | func (f Int32Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "int32" 22 | } 23 | 24 | func (f Int32Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Int32Parameter{ 28 | Name: "int32_param", 29 | }, 30 | }, 31 | Return: function.Int32Return{}, 32 | } 33 | } 34 | 35 | func (f Int32Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg int32 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework5provider/int64_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Int64Function{} 13 | 14 | func NewInt64Function() function.Function { 15 | return &Int64Function{} 16 | } 17 | 18 | type Int64Function struct{} 19 | 20 | func (f Int64Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "int64" 22 | } 23 | 24 | func (f Int64Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Int64Parameter{ 28 | Name: "int64_param", 29 | }, 30 | }, 31 | Return: function.Int64Return{}, 32 | } 33 | } 34 | 35 | func (f Int64Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg int64 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework6provider/int32_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Int32Function{} 13 | 14 | func NewInt32Function() function.Function { 15 | return &Int32Function{} 16 | } 17 | 18 | type Int32Function struct{} 19 | 20 | func (f Int32Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "int32" 22 | } 23 | 24 | func (f Int32Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Int32Parameter{ 28 | Name: "int32_param", 29 | }, 30 | }, 31 | Return: function.Int32Return{}, 32 | } 33 | } 34 | 35 | func (f Int32Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg int32 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework6provider/int64_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Int64Function{} 13 | 14 | func NewInt64Function() function.Function { 15 | return &Int64Function{} 16 | } 17 | 18 | type Int64Function struct{} 19 | 20 | func (f Int64Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "int64" 22 | } 23 | 24 | func (f Int64Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Int64Parameter{ 28 | Name: "int64_param", 29 | }, 30 | }, 31 | Return: function.Int64Return{}, 32 | } 33 | } 34 | 35 | func (f Int64Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg int64 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework5provider/string_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = StringFunction{} 13 | 14 | func NewStringFunction() function.Function { 15 | return &StringFunction{} 16 | } 17 | 18 | type StringFunction struct{} 19 | 20 | func (f StringFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "string" 22 | } 23 | 24 | func (f StringFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.StringParameter{ 28 | Name: "string_param", 29 | }, 30 | }, 31 | Return: function.StringReturn{}, 32 | } 33 | } 34 | 35 | func (f StringFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg string 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework6provider/string_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = StringFunction{} 13 | 14 | func NewStringFunction() function.Function { 15 | return &StringFunction{} 16 | } 17 | 18 | type StringFunction struct{} 19 | 20 | func (f StringFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "string" 22 | } 23 | 24 | func (f StringFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.StringParameter{ 28 | Name: "string_param", 29 | }, 30 | }, 31 | Return: function.StringReturn{}, 32 | } 33 | } 34 | 35 | func (f StringFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg string 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/tf6to5provider/provider/function_string.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = StringFunction{} 13 | 14 | func NewStringFunction() function.Function { 15 | return &StringFunction{} 16 | } 17 | 18 | type StringFunction struct{} 19 | 20 | func (f StringFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "string" 22 | } 23 | 24 | func (f StringFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.StringParameter{ 28 | Name: "string_param", 29 | }, 30 | }, 31 | Return: function.StringReturn{}, 32 | } 33 | } 34 | 35 | func (f StringFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg string 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider1/function_string.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider1 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = StringFunction{} 13 | 14 | func NewStringFunction() function.Function { 15 | return &StringFunction{} 16 | } 17 | 18 | type StringFunction struct{} 19 | 20 | func (f StringFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "string1" 22 | } 23 | 24 | func (f StringFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.StringParameter{ 28 | Name: "string1_param", 29 | }, 30 | }, 31 | Return: function.StringReturn{}, 32 | } 33 | } 34 | 35 | func (f StringFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg string 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider2/function_string.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider2 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = StringFunction{} 13 | 14 | func NewStringFunction() function.Function { 15 | return &StringFunction{} 16 | } 17 | 18 | type StringFunction struct{} 19 | 20 | func (f StringFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "string2" 22 | } 23 | 24 | func (f StringFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.StringParameter{ 28 | Name: "string2_param", 29 | }, 30 | }, 31 | Return: function.StringReturn{}, 32 | } 33 | } 34 | 35 | func (f StringFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg string 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework5provider/float32_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Float32Function{} 13 | 14 | func NewFloat32Function() function.Function { 15 | return &Float32Function{} 16 | } 17 | 18 | type Float32Function struct{} 19 | 20 | func (f Float32Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "float32" 22 | } 23 | 24 | func (f Float32Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Float32Parameter{ 28 | Name: "float32_param", 29 | }, 30 | }, 31 | Return: function.Float32Return{}, 32 | } 33 | } 34 | 35 | func (f Float32Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg float32 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework5provider/float64_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Float64Function{} 13 | 14 | func NewFloat64Function() function.Function { 15 | return &Float64Function{} 16 | } 17 | 18 | type Float64Function struct{} 19 | 20 | func (f Float64Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "float64" 22 | } 23 | 24 | func (f Float64Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Float64Parameter{ 28 | Name: "float64_param", 29 | }, 30 | }, 31 | Return: function.Float64Return{}, 32 | } 33 | } 34 | 35 | func (f Float64Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg float64 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework6provider/float32_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Float32Function{} 13 | 14 | func NewFloat32Function() function.Function { 15 | return &Float32Function{} 16 | } 17 | 18 | type Float32Function struct{} 19 | 20 | func (f Float32Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "float32" 22 | } 23 | 24 | func (f Float32Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Float32Parameter{ 28 | Name: "float32_param", 29 | }, 30 | }, 31 | Return: function.Float32Return{}, 32 | } 33 | } 34 | 35 | func (f Float32Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg float32 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework6provider/float64_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | ) 11 | 12 | var _ function.Function = Float64Function{} 13 | 14 | func NewFloat64Function() function.Function { 15 | return &Float64Function{} 16 | } 17 | 18 | type Float64Function struct{} 19 | 20 | func (f Float64Function) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 21 | resp.Name = "float64" 22 | } 23 | 24 | func (f Float64Function) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 25 | resp.Definition = function.Definition{ 26 | Parameters: []function.Parameter{ 27 | function.Float64Parameter{ 28 | Name: "float64_param", 29 | }, 30 | }, 31 | Return: function.Float64Return{}, 32 | } 33 | } 34 | 35 | func (f Float64Function) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 36 | var arg float64 37 | 38 | resp.Error = req.Arguments.Get(ctx, &arg) 39 | 40 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 41 | } 42 | -------------------------------------------------------------------------------- /internal/framework5provider/ephemeral_resource_spy_client.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | // EphemeralResourceSpyClient is used in tests to verify that an ephemeral resource lifecycle handler has been executed. 7 | type EphemeralResourceSpyClient struct { 8 | renewInvocations int 9 | closeInvocations int 10 | } 11 | 12 | // Renew will increment the number of invocations for this instance, which can be retrieved with the `RenewInvocations` method 13 | func (e *EphemeralResourceSpyClient) Renew() { 14 | e.renewInvocations++ 15 | } 16 | 17 | // RenewInvocations returns the number of times the `Renew` method has been called on this instance. 18 | func (e *EphemeralResourceSpyClient) RenewInvocations() int { 19 | return e.renewInvocations 20 | } 21 | 22 | // Close will increment the number of invocations for this instance, which can be retrieved with the `CloseInvocations` method 23 | func (e *EphemeralResourceSpyClient) Close() { 24 | e.closeInvocations++ 25 | } 26 | 27 | // CloseInvocations returns the number of times the `Close` method has been called on this instance. 28 | func (e *EphemeralResourceSpyClient) CloseInvocations() int { 29 | return e.closeInvocations 30 | } 31 | -------------------------------------------------------------------------------- /internal/framework5provider/number_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | "math/big" 9 | 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | ) 12 | 13 | var _ function.Function = NumberFunction{} 14 | 15 | func NewNumberFunction() function.Function { 16 | return &NumberFunction{} 17 | } 18 | 19 | type NumberFunction struct{} 20 | 21 | func (f NumberFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "number" 23 | } 24 | 25 | func (f NumberFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.NumberParameter{ 29 | Name: "number_param", 30 | }, 31 | }, 32 | Return: function.NumberReturn{}, 33 | } 34 | } 35 | 36 | func (f NumberFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 37 | var arg *big.Float 38 | 39 | resp.Error = req.Arguments.Get(ctx, &arg) 40 | 41 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 42 | } 43 | -------------------------------------------------------------------------------- /internal/framework6provider/ephemeral_resource_spy_client.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | // EphemeralResourceSpyClient is used in tests to verify that an ephemeral resource lifecycle handler has been executed. 7 | type EphemeralResourceSpyClient struct { 8 | renewInvocations int 9 | closeInvocations int 10 | } 11 | 12 | // Renew will increment the number of invocations for this instance, which can be retrieved with the `RenewInvocations` method 13 | func (e *EphemeralResourceSpyClient) Renew() { 14 | e.renewInvocations++ 15 | } 16 | 17 | // RenewInvocations returns the number of times the `Renew` method has been called on this instance. 18 | func (e *EphemeralResourceSpyClient) RenewInvocations() int { 19 | return e.renewInvocations 20 | } 21 | 22 | // Close will increment the number of invocations for this instance, which can be retrieved with the `CloseInvocations` method 23 | func (e *EphemeralResourceSpyClient) Close() { 24 | e.closeInvocations++ 25 | } 26 | 27 | // CloseInvocations returns the number of times the `Close` method has been called on this instance. 28 | func (e *EphemeralResourceSpyClient) CloseInvocations() int { 29 | return e.closeInvocations 30 | } 31 | -------------------------------------------------------------------------------- /internal/framework6provider/number_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | "math/big" 9 | 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | ) 12 | 13 | var _ function.Function = NumberFunction{} 14 | 15 | func NewNumberFunction() function.Function { 16 | return &NumberFunction{} 17 | } 18 | 19 | type NumberFunction struct{} 20 | 21 | func (f NumberFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "number" 23 | } 24 | 25 | func (f NumberFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.NumberParameter{ 29 | Name: "number_param", 30 | }, 31 | }, 32 | Return: function.NumberReturn{}, 33 | } 34 | } 35 | 36 | func (f NumberFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 37 | var arg *big.Float 38 | 39 | resp.Error = req.Arguments.Get(ctx, &arg) 40 | 41 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 42 | } 43 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 12 | ) 13 | 14 | func New() *schema.Provider { 15 | p := &schema.Provider{ 16 | DataSourcesMap: map[string]*schema.Resource{ 17 | "corner_regions": dataSourceRegions(), 18 | "corner_bigint": dataSourceBigint(), 19 | "corner_regions_cty": dataSourceRegionsCty(), 20 | }, 21 | ResourcesMap: map[string]*schema.Resource{ 22 | "corner_user": resourceUser(), 23 | "corner_bigint": resourceBigint(), 24 | "corner_user_cty": resourceUserCty(), 25 | }, 26 | } 27 | 28 | p.ConfigureContextFunc = configure(p) 29 | 30 | return p 31 | } 32 | 33 | func configure(p *schema.Provider) func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 34 | return func(context.Context, *schema.ResourceData) (interface{}, diag.Diagnostics) { 35 | client, err := backend.NewClient() 36 | if err != nil { 37 | return nil, diag.FromErr(err) 38 | } 39 | return client, nil 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /internal/tf5to6provider/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf5to6provider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | ) 12 | 13 | func TestAccResourceUser(t *testing.T) { 14 | resource.UnitTest(t, resource.TestCase{ 15 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 16 | "tf5to6provider": func() (tfprotov6.ProviderServer, error) { 17 | provider, err := New() 18 | 19 | return provider(), err 20 | }, 21 | }, 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: configResourceUserBasic, 25 | Check: resource.ComposeTestCheckFunc( 26 | resource.TestCheckResourceAttr("tf5to6provider_user.example", "age", "123"), 27 | resource.TestCheckResourceAttr("tf5to6provider_user.example", "email", "example@example.com"), 28 | resource.TestCheckResourceAttr("tf5to6provider_user.example", "name", "Example Name"), 29 | ), 30 | }, 31 | }, 32 | }) 33 | } 34 | 35 | const configResourceUserBasic = ` 36 | resource "tf5to6provider_user" "example" { 37 | age = 123 38 | email = "example@example.com" 39 | name = "Example Name" 40 | } 41 | ` 42 | -------------------------------------------------------------------------------- /internal/framework5provider/dynamic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = StringFunction{} 14 | 15 | func NewDynamicFunction() function.Function { 16 | return &DynamicFunction{} 17 | } 18 | 19 | type DynamicFunction struct{} 20 | 21 | func (f DynamicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "dynamic" 23 | } 24 | 25 | func (f DynamicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.DynamicParameter{ 29 | Name: "dynamic_param", 30 | }, 31 | }, 32 | Return: function.DynamicReturn{}, 33 | } 34 | } 35 | 36 | func (f DynamicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 37 | var arg types.Dynamic 38 | 39 | resp.Error = req.Arguments.Get(ctx, &arg) 40 | 41 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 42 | } 43 | -------------------------------------------------------------------------------- /internal/framework6provider/dynamic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = StringFunction{} 14 | 15 | func NewDynamicFunction() function.Function { 16 | return &DynamicFunction{} 17 | } 18 | 19 | type DynamicFunction struct{} 20 | 21 | func (f DynamicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "dynamic" 23 | } 24 | 25 | func (f DynamicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.DynamicParameter{ 29 | Name: "dynamic_param", 30 | }, 31 | }, 32 | Return: function.DynamicReturn{}, 33 | } 34 | } 35 | 36 | func (f DynamicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 37 | var arg types.Dynamic 38 | 39 | resp.Error = req.Arguments.Get(ctx, &arg) 40 | 41 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 42 | } 43 | -------------------------------------------------------------------------------- /internal/framework5provider/variadic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = VariadicFunction{} 14 | 15 | func NewVariadicFunction() function.Function { 16 | return &VariadicFunction{} 17 | } 18 | 19 | type VariadicFunction struct{} 20 | 21 | func (f VariadicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "variadic" 23 | } 24 | 25 | func (f VariadicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Return: function.ListReturn{ 28 | ElementType: types.StringType, 29 | }, 30 | VariadicParameter: function.StringParameter{ 31 | Name: "variadic_param", 32 | }, 33 | } 34 | } 35 | 36 | func (f VariadicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 37 | var varg []string 38 | 39 | resp.Error = req.Arguments.Get(ctx, &varg) 40 | 41 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, varg)) 42 | } 43 | -------------------------------------------------------------------------------- /internal/framework6provider/variadic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = VariadicFunction{} 14 | 15 | func NewVariadicFunction() function.Function { 16 | return &VariadicFunction{} 17 | } 18 | 19 | type VariadicFunction struct{} 20 | 21 | func (f VariadicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "variadic" 23 | } 24 | 25 | func (f VariadicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Return: function.ListReturn{ 28 | ElementType: types.StringType, 29 | }, 30 | VariadicParameter: function.StringParameter{ 31 | Name: "variadic_param", 32 | }, 33 | } 34 | } 35 | 36 | func (f VariadicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 37 | var varg []string 38 | 39 | resp.Error = req.Arguments.Get(ctx, &varg) 40 | 41 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, varg)) 42 | } 43 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | version: "2" 2 | linters: 3 | default: none 4 | enable: 5 | - copyloopvar 6 | - durationcheck 7 | - errcheck 8 | - forcetypeassert 9 | - govet 10 | - ineffassign 11 | - makezero 12 | - misspell 13 | - nilerr 14 | - predeclared 15 | - staticcheck 16 | - unconvert 17 | - unparam 18 | - unused 19 | - usetesting 20 | exclusions: 21 | generated: lax 22 | presets: 23 | - comments 24 | - common-false-positives 25 | - legacy 26 | - std-error-handling 27 | paths: 28 | - third_party$ 29 | - builtin$ 30 | - examples$ 31 | settings: 32 | staticcheck: 33 | checks: 34 | - all 35 | - '-QF1011' # could omit type *schema.Provider from declaration -- https://staticcheck.dev/docs/checks/#QF1011 36 | - '-ST1003' # example: "const autoTFVarsJson should be autoTFVarsJSON" -- https://staticcheck.dev/docs/checks/#ST1003 37 | - '-ST1005' # "error strings should not end with punctuation or newlines" -- https://staticcheck.dev/docs/checks/#ST1005 38 | issues: 39 | max-issues-per-linter: 0 40 | max-same-issues: 0 41 | formatters: 42 | enable: 43 | - gofmt 44 | exclusions: 45 | generated: lax 46 | paths: 47 | - third_party$ 48 | - builtin$ 49 | - examples$ 50 | -------------------------------------------------------------------------------- /internal/framework5provider/set_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = SetFunction{} 14 | 15 | func NewSetFunction() function.Function { 16 | return &SetFunction{} 17 | } 18 | 19 | type SetFunction struct{} 20 | 21 | func (f SetFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "set" 23 | } 24 | 25 | func (f SetFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.SetParameter{ 29 | ElementType: types.StringType, 30 | Name: "set_param", 31 | }, 32 | }, 33 | Return: function.SetReturn{ 34 | ElementType: types.StringType, 35 | }, 36 | } 37 | } 38 | 39 | func (f SetFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 40 | var arg []*string 41 | 42 | resp.Error = req.Arguments.Get(ctx, &arg) 43 | 44 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 45 | } 46 | -------------------------------------------------------------------------------- /internal/framework6provider/set_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = SetFunction{} 14 | 15 | func NewSetFunction() function.Function { 16 | return &SetFunction{} 17 | } 18 | 19 | type SetFunction struct{} 20 | 21 | func (f SetFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "set" 23 | } 24 | 25 | func (f SetFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.SetParameter{ 29 | ElementType: types.StringType, 30 | Name: "set_param", 31 | }, 32 | }, 33 | Return: function.SetReturn{ 34 | ElementType: types.StringType, 35 | }, 36 | } 37 | } 38 | 39 | func (f SetFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 40 | var arg []*string 41 | 42 | resp.Error = req.Arguments.Get(ctx, &arg) 43 | 44 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 45 | } 46 | -------------------------------------------------------------------------------- /internal/framework5provider/map_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = MapFunction{} 14 | 15 | func NewMapFunction() function.Function { 16 | return &MapFunction{} 17 | } 18 | 19 | type MapFunction struct{} 20 | 21 | func (f MapFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "map" 23 | } 24 | 25 | func (f MapFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.MapParameter{ 29 | ElementType: types.StringType, 30 | Name: "map_param", 31 | }, 32 | }, 33 | Return: function.MapReturn{ 34 | ElementType: types.StringType, 35 | }, 36 | } 37 | } 38 | 39 | func (f MapFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 40 | var arg map[string]*string 41 | 42 | resp.Error = req.Arguments.Get(ctx, &arg) 43 | 44 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 45 | } 46 | -------------------------------------------------------------------------------- /internal/framework6provider/map_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = MapFunction{} 14 | 15 | func NewMapFunction() function.Function { 16 | return &MapFunction{} 17 | } 18 | 19 | type MapFunction struct{} 20 | 21 | func (f MapFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "map" 23 | } 24 | 25 | func (f MapFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.MapParameter{ 29 | ElementType: types.StringType, 30 | Name: "map_param", 31 | }, 32 | }, 33 | Return: function.MapReturn{ 34 | ElementType: types.StringType, 35 | }, 36 | } 37 | } 38 | 39 | func (f MapFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 40 | var arg map[string]*string 41 | 42 | resp.Error = req.Arguments.Get(ctx, &arg) 43 | 44 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 45 | } 46 | -------------------------------------------------------------------------------- /internal/protocolprovider/function_bool_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 12 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 13 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 14 | ) 15 | 16 | func TestAccV5FunctionBool(t *testing.T) { 17 | resource.UnitTest(t, resource.TestCase{ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_8_0), 20 | }, 21 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 22 | //nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 23 | "corner": func() (tfprotov5.ProviderServer, error) { 24 | return Server(false), nil 25 | }, 26 | }, 27 | Steps: []resource.TestStep{ 28 | { 29 | Config: ` 30 | output "test" { 31 | value = provider::corner::bool(true) 32 | }`, 33 | ConfigStateChecks: []statecheck.StateCheck{ 34 | statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), 35 | }, 36 | }, 37 | }, 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /internal/protocolv6provider/function_bool_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 12 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 13 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 14 | ) 15 | 16 | func TestAccV6FunctionBool(t *testing.T) { 17 | resource.UnitTest(t, resource.TestCase{ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_8_0), 20 | }, 21 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 22 | //nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 23 | "corner": func() (tfprotov6.ProviderServer, error) { 24 | return Server(false), nil 25 | }, 26 | }, 27 | Steps: []resource.TestStep{ 28 | { 29 | Config: ` 30 | output "test" { 31 | value = provider::corner::bool(true) 32 | }`, 33 | ConfigStateChecks: []statecheck.StateCheck{ 34 | statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), 35 | }, 36 | }, 37 | }, 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /internal/framework5provider/list_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = ListFunction{} 14 | 15 | func NewListFunction() function.Function { 16 | return &ListFunction{} 17 | } 18 | 19 | type ListFunction struct{} 20 | 21 | func (f ListFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "list" 23 | } 24 | 25 | func (f ListFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.ListParameter{ 29 | ElementType: types.StringType, 30 | Name: "list_param", 31 | }, 32 | }, 33 | Return: function.ListReturn{ 34 | ElementType: types.StringType, 35 | }, 36 | } 37 | } 38 | 39 | func (f ListFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 40 | var arg []*string 41 | 42 | resp.Error = req.Arguments.Get(ctx, &arg) 43 | 44 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 45 | } 46 | -------------------------------------------------------------------------------- /internal/framework6provider/list_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = ListFunction{} 14 | 15 | func NewListFunction() function.Function { 16 | return &ListFunction{} 17 | } 18 | 19 | type ListFunction struct{} 20 | 21 | func (f ListFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "list" 23 | } 24 | 25 | func (f ListFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | Parameters: []function.Parameter{ 28 | function.ListParameter{ 29 | ElementType: types.StringType, 30 | Name: "list_param", 31 | }, 32 | }, 33 | Return: function.ListReturn{ 34 | ElementType: types.StringType, 35 | }, 36 | } 37 | } 38 | 39 | func (f ListFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 40 | var arg []*string 41 | 42 | resp.Error = req.Arguments.Get(ctx, &arg) 43 | 44 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 45 | } 46 | -------------------------------------------------------------------------------- /internal/framework5provider/dynamic_variadic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = DynamicVariadicFunction{} 14 | 15 | func NewDynamicVariadicFunction() function.Function { 16 | return &DynamicVariadicFunction{} 17 | } 18 | 19 | type DynamicVariadicFunction struct{} 20 | 21 | func (f DynamicVariadicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "dynamic_variadic" 23 | } 24 | 25 | func (f DynamicVariadicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | VariadicParameter: function.DynamicParameter{ 28 | Name: "dynamic_variadic_param", 29 | }, 30 | Return: function.DynamicReturn{}, 31 | } 32 | } 33 | 34 | func (f DynamicVariadicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 35 | var varg types.Tuple 36 | resp.Error = req.Arguments.Get(ctx, &varg) 37 | 38 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, types.DynamicValue(varg))) 39 | } 40 | -------------------------------------------------------------------------------- /internal/framework5provider/writeonly_move_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestWriteOnlyMoveResource(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Write-only attributes are only available in 1.11.0+ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_11_0), 20 | }, 21 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 22 | "framework": providerserver.NewProtocol5WithError(New()), 23 | }, 24 | Steps: []resource.TestStep{ 25 | { 26 | Config: `resource "terraform_data" "test" { 27 | input = "hello world!" 28 | }`, 29 | }, 30 | { 31 | Config: `resource "framework_writeonly_move" "test" { 32 | string_attr = "hello world!" 33 | writeonly_string = "fakepassword" 34 | } 35 | 36 | moved { 37 | from = terraform_data.test 38 | to = framework_writeonly_move.test 39 | }`, 40 | }, 41 | }, 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /internal/framework6provider/dynamic_variadic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/function" 10 | "github.com/hashicorp/terraform-plugin-framework/types" 11 | ) 12 | 13 | var _ function.Function = DynamicVariadicFunction{} 14 | 15 | func NewDynamicVariadicFunction() function.Function { 16 | return &DynamicVariadicFunction{} 17 | } 18 | 19 | type DynamicVariadicFunction struct{} 20 | 21 | func (f DynamicVariadicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 22 | resp.Name = "dynamic_variadic" 23 | } 24 | 25 | func (f DynamicVariadicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 26 | resp.Definition = function.Definition{ 27 | VariadicParameter: function.DynamicParameter{ 28 | Name: "dynamic_variadic_param", 29 | }, 30 | Return: function.DynamicReturn{}, 31 | } 32 | } 33 | 34 | func (f DynamicVariadicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 35 | var varg types.Tuple 36 | resp.Error = req.Arguments.Get(ctx, &varg) 37 | 38 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, types.DynamicValue(varg))) 39 | } 40 | -------------------------------------------------------------------------------- /internal/framework6provider/writeonly_move_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestWriteOnlyMoveResource(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Write-only attributes are only available in 1.11.0+ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_11_0), 20 | }, 21 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 22 | "framework": providerserver.NewProtocol6WithError(New()), 23 | }, 24 | Steps: []resource.TestStep{ 25 | { 26 | Config: `resource "terraform_data" "test" { 27 | input = "hello world!" 28 | }`, 29 | }, 30 | { 31 | Config: `resource "framework_writeonly_move" "test" { 32 | string_attr = "hello world!" 33 | writeonly_string = "fakepassword" 34 | } 35 | 36 | moved { 37 | from = terraform_data.test 38 | to = framework_writeonly_move.test 39 | }`, 40 | }, 41 | }, 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /internal/tf6to5provider/provider/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | ) 13 | 14 | func TestAccResourceUser(t *testing.T) { 15 | resource.UnitTest(t, resource.TestCase{ 16 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 17 | "tf6to5provider": providerserver.NewProtocol6WithError(New()), 18 | }, 19 | Steps: []resource.TestStep{ 20 | { 21 | Config: configResourceUserBasic, 22 | Check: resource.ComposeTestCheckFunc( 23 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "age", "123"), 24 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "email", "example@example.com"), 25 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "language", "en"), 26 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "name", "Example Name"), 27 | ), 28 | }, 29 | }, 30 | }) 31 | } 32 | 33 | const configResourceUserBasic = ` 34 | resource "tf6to5provider_user" "example" { 35 | age = 123 36 | email = "example@example.com" 37 | name = "Example Name" 38 | } 39 | ` 40 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider1/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider1 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | ) 13 | 14 | func TestAccResourceUser1(t *testing.T) { 15 | resource.UnitTest(t, resource.TestCase{ 16 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 17 | "tf6muxprovider": providerserver.NewProtocol6WithError(New()), 18 | }, 19 | Steps: []resource.TestStep{ 20 | { 21 | Config: configResourceUserBasic, 22 | Check: resource.ComposeTestCheckFunc( 23 | resource.TestCheckResourceAttr("tf6muxprovider_user1.example", "age", "123"), 24 | resource.TestCheckResourceAttr("tf6muxprovider_user1.example", "email", "example@example.com"), 25 | resource.TestCheckResourceAttr("tf6muxprovider_user1.example", "language", "en"), 26 | resource.TestCheckResourceAttr("tf6muxprovider_user1.example", "name", "Example Name"), 27 | ), 28 | }, 29 | }, 30 | }) 31 | } 32 | 33 | const configResourceUserBasic = ` 34 | resource "tf6muxprovider_user1" "example" { 35 | age = 123 36 | email = "example@example.com" 37 | name = "Example Name" 38 | } 39 | ` 40 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider2/resource_user_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | ) 13 | 14 | func TestAccResourceUser2(t *testing.T) { 15 | resource.UnitTest(t, resource.TestCase{ 16 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 17 | "tf6muxprovider": providerserver.NewProtocol6WithError(New()), 18 | }, 19 | Steps: []resource.TestStep{ 20 | { 21 | Config: configResourceUserBasic, 22 | Check: resource.ComposeTestCheckFunc( 23 | resource.TestCheckResourceAttr("tf6muxprovider_user2.example", "age", "123"), 24 | resource.TestCheckResourceAttr("tf6muxprovider_user2.example", "email", "example@example.com"), 25 | resource.TestCheckResourceAttr("tf6muxprovider_user2.example", "language", "en"), 26 | resource.TestCheckResourceAttr("tf6muxprovider_user2.example", "name", "Example Name"), 27 | ), 28 | }, 29 | }, 30 | }) 31 | } 32 | 33 | const configResourceUserBasic = ` 34 | resource "tf6muxprovider_user2" "example" { 35 | age = 123 36 | email = "example@example.com" 37 | name = "Example Name" 38 | } 39 | ` 40 | -------------------------------------------------------------------------------- /internal/sdkv2provider/data_source_regions.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 12 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 13 | ) 14 | 15 | func dataSourceRegions() *schema.Resource { 16 | return &schema.Resource{ 17 | EnableLegacyTypeSystemPlanErrors: true, 18 | EnableLegacyTypeSystemApplyErrors: true, 19 | 20 | ReadContext: dataSourceRegionsRead, 21 | 22 | Schema: map[string]*schema.Schema{ 23 | "names": { 24 | Type: schema.TypeList, 25 | Computed: true, 26 | Elem: &schema.Schema{Type: schema.TypeString}, 27 | }, 28 | }, 29 | } 30 | } 31 | 32 | func dataSourceRegionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 33 | client := meta.(*backend.Client) 34 | 35 | regions, err := client.ReadRegions() 36 | if err != nil { 37 | return diag.FromErr(err) 38 | } 39 | 40 | names := []string{} 41 | for _, r := range regions { 42 | names = append(names, r.Name) 43 | } 44 | 45 | d.SetId("regions") 46 | 47 | err = d.Set("names", names) 48 | if err != nil { 49 | return diag.FromErr(err) 50 | } 51 | 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /internal/protocolprovider/deferred_action_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestAccDataSourceDeferredAction_InvalidDeferredResponse(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Only run this test for Terraform clients that do not support deferred actions 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipAbove(tfversion.Version1_8_0), 20 | }, 21 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 22 | //nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 23 | "corner": func() (tfprotov5.ProviderServer, error) { 24 | return Server(false), nil 25 | }, 26 | }, 27 | // Test that terraform-plugin-go throws an error diagnostic when a 28 | // deferral is sent without the deferred action client capability 29 | Steps: []resource.TestStep{ 30 | { 31 | Config: `data "corner_deferred_action" "foo" {}`, 32 | ExpectError: regexp.MustCompile("Error: Invalid Deferred Response"), 33 | }, 34 | }, 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /internal/framework5provider/writeonly_import_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestWriteOnlyImportResource(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Write-only attributes are only available in 1.11.0+ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_11_0), 20 | }, 21 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 22 | "framework": providerserver.NewProtocol5WithError(New()), 23 | }, 24 | Steps: []resource.TestStep{ 25 | { 26 | Config: `resource "framework_writeonly_import" "test" { 27 | string_attr = "hello world!" 28 | writeonly_string = "fakepassword" 29 | }`, 30 | }, 31 | { 32 | ResourceName: "framework_writeonly_import.test", 33 | ImportState: true, 34 | ImportStateVerify: true, 35 | ImportStateVerifyIdentifierAttribute: "string_attr", 36 | }, 37 | }, 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /internal/framework6provider/writeonly_import_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestWriteOnlyImportResource(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Write-only attributes are only available in 1.11.0+ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_11_0), 20 | }, 21 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 22 | "framework": providerserver.NewProtocol6WithError(New()), 23 | }, 24 | Steps: []resource.TestStep{ 25 | { 26 | Config: `resource "framework_writeonly_import" "test" { 27 | string_attr = "hello world!" 28 | writeonly_string = "fakepassword" 29 | }`, 30 | }, 31 | { 32 | ResourceName: "framework_writeonly_import.test", 33 | ImportState: true, 34 | ImportStateVerify: true, 35 | ImportStateVerifyIdentifierAttribute: "string_attr", 36 | }, 37 | }, 38 | }) 39 | } 40 | -------------------------------------------------------------------------------- /internal/protocolv6provider/deferred_action_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestAccDataSourceDeferredAction_InvalidDeferredResponse(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Only run this test for Terraform clients that do not support deferred actions 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipAbove(tfversion.Version1_8_0), 20 | }, 21 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 22 | //nolint:unparam // False positive in unparam related to map: https://github.com/mvdan/unparam/issues/40 23 | "corner": func() (tfprotov6.ProviderServer, error) { 24 | return Server(false), nil 25 | }, 26 | }, 27 | // Test that terraform-plugin-go throws an error diagnostic when a 28 | // deferral is sent without the deferred action client capability 29 | Steps: []resource.TestStep{ 30 | { 31 | Config: `data "corner_v6_deferred_action" "foo" {}`, 32 | ExpectError: regexp.MustCompile("Error: Invalid Deferred Response"), 33 | }, 34 | }, 35 | }) 36 | } 37 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/data_source_regions.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2testingprovider 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 12 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 13 | ) 14 | 15 | func dataSourceRegions() *schema.Resource { 16 | return &schema.Resource{ 17 | EnableLegacyTypeSystemPlanErrors: true, 18 | EnableLegacyTypeSystemApplyErrors: true, 19 | 20 | ReadContext: dataSourceRegionsRead, 21 | 22 | Schema: map[string]*schema.Schema{ 23 | "names": { 24 | Type: schema.TypeList, 25 | Computed: true, 26 | Elem: &schema.Schema{Type: schema.TypeString}, 27 | }, 28 | }, 29 | } 30 | } 31 | 32 | func dataSourceRegionsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 33 | client := meta.(*backend.Client) 34 | 35 | regions, err := client.ReadRegions() 36 | if err != nil { 37 | return diag.FromErr(err) 38 | } 39 | 40 | names := []string{} 41 | for _, r := range regions { 42 | names = append(names, r.Name) 43 | } 44 | 45 | d.SetId("regions") 46 | 47 | err = d.Set("names", names) 48 | if err != nil { 49 | return diag.FromErr(err) 50 | } 51 | 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /internal/cornertesting/string_required_on_create.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | package cornertesting 4 | 5 | import ( 6 | "context" 7 | "fmt" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" 10 | ) 11 | 12 | func RequiredOnCreate() planmodifier.String { 13 | return requiredOnCreateModifier{} 14 | } 15 | 16 | type requiredOnCreateModifier struct{} 17 | 18 | func (m requiredOnCreateModifier) Description(_ context.Context) string { 19 | return "This attribute is required only when creating the resource." 20 | } 21 | 22 | func (m requiredOnCreateModifier) MarkdownDescription(_ context.Context) string { 23 | return "This attribute is required only when creating the resource." 24 | } 25 | 26 | func (m requiredOnCreateModifier) PlanModifyString(ctx context.Context, req planmodifier.StringRequest, resp *planmodifier.StringResponse) { 27 | // If there is a non-null state, we are destroying or updating so no validation is needed 28 | if !req.State.Raw.IsNull() { 29 | return 30 | } 31 | 32 | // We are creating, but the attribute value is not present in config, return an error. 33 | if req.ConfigValue.IsNull() { 34 | resp.Diagnostics.AddAttributeError( 35 | req.Path, 36 | "Attribute Required when Creating", 37 | fmt.Sprintf("Must set a configuration value for the %s attribute when creating.", req.Path.String()), 38 | ) 39 | return 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_user_identity_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 10 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 11 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func testAccResourceUserIdentity(t *testing.T) resource.TestCase { 16 | return resource.TestCase{ 17 | PreCheck: func() { testAccPreCheck(t) }, 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_12_0), 20 | }, 21 | Providers: testAccProviders, 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: configResourceBasicIdentity, 25 | ConfigStateChecks: []statecheck.StateCheck{ 26 | statecheck.ExpectIdentity("corner_user_identity.foo", map[string]knownvalue.Check{ 27 | "email": knownvalue.StringExact("ford@prefect.co"), 28 | }), 29 | }, 30 | }, 31 | { 32 | ResourceName: "corner_user_identity.foo", 33 | ImportState: true, 34 | ImportStateKind: resource.ImportBlockWithResourceIdentity, 35 | }, 36 | }, 37 | } 38 | } 39 | 40 | const configResourceBasicIdentity = ` 41 | resource "corner_user_identity" "foo" { 42 | email = "ford@prefect.co" 43 | name = "Ford Prefect" 44 | age = 200 45 | } 46 | ` 47 | -------------------------------------------------------------------------------- /internal/framework5provider/writeonly_upgrade_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestWriteOnlyUpgradeResource(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Write-only attributes are only available in 1.11.0+ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_11_0), 20 | }, 21 | Steps: []resource.TestStep{ 22 | { 23 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 24 | "framework": providerserver.NewProtocol5WithError(NewWithUpgradeVersion(0)), 25 | }, 26 | Config: `resource "framework_writeonly_upgrade" "test" { 27 | string_attr = "hello!" 28 | writeonly_string = "fakepassword" 29 | }`, 30 | }, 31 | { 32 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 33 | "framework": providerserver.NewProtocol5WithError(NewWithUpgradeVersion(1)), 34 | }, 35 | Config: `resource "framework_writeonly_upgrade" "test" { 36 | string_attr = "world!" 37 | writeonly_string = "fakepassword" 38 | }`, 39 | }, 40 | }, 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /internal/framework6provider/writeonly_upgrade_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 13 | ) 14 | 15 | func TestWriteOnlyUpgradeResource(t *testing.T) { 16 | resource.UnitTest(t, resource.TestCase{ 17 | // Write-only attributes are only available in 1.11.0+ 18 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 19 | tfversion.SkipBelow(tfversion.Version1_11_0), 20 | }, 21 | Steps: []resource.TestStep{ 22 | { 23 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 24 | "framework": providerserver.NewProtocol6WithError(NewWithUpgradeVersion(0)), 25 | }, 26 | Config: `resource "framework_writeonly_upgrade" "test" { 27 | string_attr = "hello!" 28 | writeonly_string = "fakepassword" 29 | }`, 30 | }, 31 | { 32 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 33 | "framework": providerserver.NewProtocol6WithError(NewWithUpgradeVersion(1)), 34 | }, 35 | Config: `resource "framework_writeonly_upgrade" "test" { 36 | string_attr = "world!" 37 | writeonly_string = "fakepassword" 38 | }`, 39 | }, 40 | }, 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | ) 12 | 13 | var testAccProviders map[string]*schema.Provider 14 | var testAccProvider *schema.Provider 15 | 16 | func init() { 17 | testAccProvider = New() 18 | testAccProviders = map[string]*schema.Provider{ 19 | "corner": testAccProvider, 20 | } 21 | } 22 | 23 | func TestProvider(t *testing.T) { 24 | if err := New().InternalValidate(); err != nil { 25 | t.Fatalf("err: %s", err) 26 | } 27 | } 28 | 29 | func TestProvider_impl(t *testing.T) { 30 | var _ *schema.Provider = New() 31 | } 32 | 33 | func testAccPreCheck(t *testing.T) { 34 | } 35 | 36 | func TestAccTests(t *testing.T) { 37 | for name, c := range TestCases { 38 | t.Helper() 39 | t.Run(name, func(t *testing.T) { 40 | resource.Test(t, c(t)) 41 | }) 42 | } 43 | } 44 | 45 | // public map of test cases that can be imported by Core/SDK etc. 46 | var TestCases = map[string]func(*testing.T) resource.TestCase{ 47 | "corner_user": testAccResourceUser, 48 | "corner_regions": testAccDataSourceRegions, 49 | "corner_bigint_data": testAccDataSourceBigint, 50 | "corner_bigint": testAccResourceBigint, 51 | "corner_user_cty": testAccResourceUserCty, 52 | "corner_regions_cty": testAccDataSourceRegionsCty, 53 | } 54 | -------------------------------------------------------------------------------- /internal/framework5provider/timeouts_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | ) 13 | 14 | func TestTimeoutsResource_unconfigured(t *testing.T) { 15 | resource.UnitTest(t, resource.TestCase{ 16 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 17 | "framework": providerserver.NewProtocol5WithError(New()), 18 | }, 19 | Steps: []resource.TestStep{ 20 | { 21 | Config: `resource "framework_timeouts" "test" {}`, 22 | Check: resource.ComposeAggregateTestCheckFunc( 23 | resource.TestCheckNoResourceAttr("framework_timeouts.test", "timeouts"), 24 | ), 25 | }, 26 | }, 27 | }) 28 | } 29 | 30 | func TestTimeoutsResource_configured(t *testing.T) { 31 | resource.UnitTest(t, resource.TestCase{ 32 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 33 | "framework": providerserver.NewProtocol5WithError(New()), 34 | }, 35 | Steps: []resource.TestStep{ 36 | { 37 | Config: `resource "framework_timeouts" "test" { 38 | timeouts { 39 | create = "120s" 40 | } 41 | }`, 42 | Check: resource.ComposeAggregateTestCheckFunc( 43 | resource.TestCheckResourceAttr("framework_timeouts.test", "timeouts.create", "120s"), 44 | ), 45 | }, 46 | }, 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /internal/framework6provider/timeouts_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | ) 13 | 14 | func TestTimeoutsResource_unconfigured(t *testing.T) { 15 | resource.UnitTest(t, resource.TestCase{ 16 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 17 | "framework": providerserver.NewProtocol6WithError(New()), 18 | }, 19 | Steps: []resource.TestStep{ 20 | { 21 | Config: `resource "framework_timeouts" "test" {}`, 22 | Check: resource.ComposeAggregateTestCheckFunc( 23 | resource.TestCheckNoResourceAttr("framework_timeouts.test", "timeouts"), 24 | ), 25 | }, 26 | }, 27 | }) 28 | } 29 | 30 | func TestTimeoutsResource_configured(t *testing.T) { 31 | resource.UnitTest(t, resource.TestCase{ 32 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 33 | "framework": providerserver.NewProtocol6WithError(New()), 34 | }, 35 | Steps: []resource.TestStep{ 36 | { 37 | Config: `resource "framework_timeouts" "test" { 38 | timeouts = { 39 | create = "120s" 40 | } 41 | }`, 42 | Check: resource.ComposeAggregateTestCheckFunc( 43 | resource.TestCheckResourceAttr("framework_timeouts.test", "timeouts.create", "120s"), 44 | ), 45 | }, 46 | }, 47 | }) 48 | } 49 | -------------------------------------------------------------------------------- /internal/protocolprovider/data_time.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 12 | "github.com/hashicorp/terraform-plugin-go/tftypes" 13 | ) 14 | 15 | type dataSourceTime struct{} 16 | 17 | func (d dataSourceTime) ReadDataSource(ctx context.Context, req *tfprotov5.ReadDataSourceRequest) (*tfprotov5.ReadDataSourceResponse, error) { 18 | state, err := tfprotov5.NewDynamicValue(tftypes.Object{ 19 | AttributeTypes: map[string]tftypes.Type{ 20 | "current": tftypes.String, 21 | }, 22 | }, tftypes.NewValue(tftypes.Object{ 23 | AttributeTypes: map[string]tftypes.Type{ 24 | "current": tftypes.String, 25 | }, 26 | }, map[string]tftypes.Value{ 27 | "current": tftypes.NewValue(tftypes.String, time.Now().Format(time.RFC3339)), 28 | })) 29 | if err != nil { 30 | return &tfprotov5.ReadDataSourceResponse{ 31 | Diagnostics: []*tfprotov5.Diagnostic{ 32 | { 33 | Severity: tfprotov5.DiagnosticSeverityError, 34 | Summary: "Error encoding state", 35 | Detail: fmt.Sprintf("Error encoding state: %s", err.Error()), 36 | }, 37 | }, 38 | }, nil 39 | } 40 | return &tfprotov5.ReadDataSourceResponse{ 41 | State: &state, 42 | }, nil 43 | } 44 | 45 | func (d dataSourceTime) ValidateDataSourceConfig(ctx context.Context, req *tfprotov5.ValidateDataSourceConfigRequest) (*tfprotov5.ValidateDataSourceConfigResponse, error) { 46 | return &tfprotov5.ValidateDataSourceConfigResponse{}, nil 47 | } 48 | -------------------------------------------------------------------------------- /internal/protocolv6provider/data_time.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 12 | "github.com/hashicorp/terraform-plugin-go/tftypes" 13 | ) 14 | 15 | type dataSourceTime struct{} 16 | 17 | func (d dataSourceTime) ReadDataSource(ctx context.Context, req *tfprotov6.ReadDataSourceRequest) (*tfprotov6.ReadDataSourceResponse, error) { 18 | state, err := tfprotov6.NewDynamicValue(tftypes.Object{ 19 | AttributeTypes: map[string]tftypes.Type{ 20 | "current": tftypes.String, 21 | }, 22 | }, tftypes.NewValue(tftypes.Object{ 23 | AttributeTypes: map[string]tftypes.Type{ 24 | "current": tftypes.String, 25 | }, 26 | }, map[string]tftypes.Value{ 27 | "current": tftypes.NewValue(tftypes.String, time.Now().Format(time.RFC3339)), 28 | })) 29 | if err != nil { 30 | return &tfprotov6.ReadDataSourceResponse{ 31 | Diagnostics: []*tfprotov6.Diagnostic{ 32 | { 33 | Severity: tfprotov6.DiagnosticSeverityError, 34 | Summary: "Error encoding state", 35 | Detail: fmt.Sprintf("Error encoding state: %s", err.Error()), 36 | }, 37 | }, 38 | }, nil 39 | } 40 | return &tfprotov6.ReadDataSourceResponse{ 41 | State: &state, 42 | }, nil 43 | } 44 | 45 | func (d dataSourceTime) ValidateDataResourceConfig(ctx context.Context, req *tfprotov6.ValidateDataResourceConfigRequest) (*tfprotov6.ValidateDataResourceConfigResponse, error) { 46 | return &tfprotov6.ValidateDataResourceConfigResponse{}, nil 47 | } 48 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_user_cty_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 10 | ) 11 | 12 | func testAccResourceUserCty(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configResourceUserCtyBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttr( 21 | "corner_user_cty.foo", "email", "ford@prefect.co"), 22 | resource.TestCheckResourceAttr( 23 | "corner_user_cty.foo", "name", "Ford Prefect"), 24 | resource.TestCheckResourceAttr( 25 | "corner_user_cty.foo", "age", "200"), 26 | ), 27 | }, 28 | { 29 | Config: configResourceUserCtyUpdate, 30 | Check: resource.ComposeTestCheckFunc( 31 | resource.TestCheckResourceAttr( 32 | "corner_user_cty.foo", "email", "ford@prefect.co"), 33 | resource.TestCheckResourceAttr( 34 | "corner_user_cty.foo", "name", "Ford Prefect II"), 35 | resource.TestCheckResourceAttr( 36 | "corner_user_cty.foo", "age", "300"), 37 | ), 38 | }, 39 | }, 40 | } 41 | } 42 | 43 | const configResourceUserCtyBasic = ` 44 | resource "corner_user_cty" "foo" { 45 | email = "ford@prefect.co" 46 | name = "Ford Prefect" 47 | age = 200 48 | } 49 | ` 50 | 51 | const configResourceUserCtyUpdate = ` 52 | resource "corner_user_cty" "foo" { 53 | email = "ford@prefect.co" 54 | name = "Ford Prefect II" 55 | age = 300 56 | } 57 | ` 58 | -------------------------------------------------------------------------------- /internal/framework5provider/object_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/attr" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ function.Function = ObjectFunction{} 15 | 16 | func NewObjectFunction() function.Function { 17 | return &ObjectFunction{} 18 | } 19 | 20 | type ObjectFunction struct{} 21 | 22 | func (f ObjectFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 23 | resp.Name = "object" 24 | } 25 | 26 | func (f ObjectFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 27 | resp.Definition = function.Definition{ 28 | Parameters: []function.Parameter{ 29 | function.ObjectParameter{ 30 | AttributeTypes: map[string]attr.Type{ 31 | "attr1": types.StringType, 32 | "attr2": types.Int64Type, 33 | }, 34 | Name: "object_param", 35 | }, 36 | }, 37 | Return: function.ObjectReturn{ 38 | AttributeTypes: map[string]attr.Type{ 39 | "attr1": types.StringType, 40 | "attr2": types.Int64Type, 41 | }, 42 | }, 43 | } 44 | } 45 | 46 | func (f ObjectFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 47 | var arg struct { 48 | Attr1 *string `tfsdk:"attr1"` 49 | Attr2 *int64 `tfsdk:"attr2"` 50 | } 51 | 52 | resp.Error = req.Arguments.Get(ctx, &arg) 53 | 54 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 55 | } 56 | -------------------------------------------------------------------------------- /internal/framework6provider/object_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/attr" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ function.Function = ObjectFunction{} 15 | 16 | func NewObjectFunction() function.Function { 17 | return &ObjectFunction{} 18 | } 19 | 20 | type ObjectFunction struct{} 21 | 22 | func (f ObjectFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 23 | resp.Name = "object" 24 | } 25 | 26 | func (f ObjectFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 27 | resp.Definition = function.Definition{ 28 | Parameters: []function.Parameter{ 29 | function.ObjectParameter{ 30 | AttributeTypes: map[string]attr.Type{ 31 | "attr1": types.StringType, 32 | "attr2": types.Int64Type, 33 | }, 34 | Name: "object_param", 35 | }, 36 | }, 37 | Return: function.ObjectReturn{ 38 | AttributeTypes: map[string]attr.Type{ 39 | "attr1": types.StringType, 40 | "attr2": types.Int64Type, 41 | }, 42 | }, 43 | } 44 | } 45 | 46 | func (f ObjectFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 47 | var arg struct { 48 | Attr1 *string `tfsdk:"attr1"` 49 | Attr2 *int64 `tfsdk:"attr2"` 50 | } 51 | 52 | resp.Error = req.Arguments.Get(ctx, &arg) 53 | 54 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 55 | } 56 | -------------------------------------------------------------------------------- /internal/sdkv2provider/data_source_regions_cty.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2 6 | 7 | import ( 8 | "context" 9 | "errors" 10 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 13 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 14 | ) 15 | 16 | func dataSourceRegionsCty() *schema.Resource { 17 | return &schema.Resource{ 18 | EnableLegacyTypeSystemPlanErrors: true, 19 | EnableLegacyTypeSystemApplyErrors: true, 20 | 21 | ReadContext: dataSourceRegionsCtyRead, 22 | 23 | Schema: map[string]*schema.Schema{ 24 | "filter": { 25 | Type: schema.TypeString, 26 | Required: true, 27 | }, 28 | "names": { 29 | Type: schema.TypeList, 30 | Computed: true, 31 | Elem: &schema.Schema{Type: schema.TypeString}, 32 | }, 33 | }, 34 | } 35 | } 36 | 37 | func dataSourceRegionsCtyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 38 | client := meta.(*backend.Client) 39 | 40 | config := d.GetRawConfig().AsValueMap() 41 | filter := config["filter"].AsString() 42 | if filter == "" { 43 | return diag.FromErr(errors.New("filter wasn't set")) 44 | } 45 | 46 | regions, err := client.ReadRegions() 47 | if err != nil { 48 | return diag.FromErr(err) 49 | } 50 | 51 | names := []string{} 52 | for _, r := range regions { 53 | names = append(names, r.Name) 54 | } 55 | 56 | d.SetId("regions") 57 | 58 | err = d.Set("names", names) 59 | if err != nil { 60 | return diag.FromErr(err) 61 | } 62 | 63 | return nil 64 | } 65 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/resource_user_cty_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2testingprovider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" 10 | ) 11 | 12 | func testAccResourceUserCty(t *testing.T) resource.TestCase { 13 | return resource.TestCase{ 14 | PreCheck: func() { testAccPreCheck(t) }, 15 | Providers: testAccProviders, 16 | Steps: []resource.TestStep{ 17 | { 18 | Config: configResourceUserCtyBasic, 19 | Check: resource.ComposeTestCheckFunc( 20 | resource.TestCheckResourceAttr( 21 | "corner_user_cty.foo", "email", "ford@prefect.co"), 22 | resource.TestCheckResourceAttr( 23 | "corner_user_cty.foo", "name", "Ford Prefect"), 24 | resource.TestCheckResourceAttr( 25 | "corner_user_cty.foo", "age", "200"), 26 | ), 27 | }, 28 | { 29 | Config: configResourceUserCtyUpdate, 30 | Check: resource.ComposeTestCheckFunc( 31 | resource.TestCheckResourceAttr( 32 | "corner_user_cty.foo", "email", "ford@prefect.co"), 33 | resource.TestCheckResourceAttr( 34 | "corner_user_cty.foo", "name", "Ford Prefect II"), 35 | resource.TestCheckResourceAttr( 36 | "corner_user_cty.foo", "age", "300"), 37 | ), 38 | }, 39 | }, 40 | } 41 | } 42 | 43 | const configResourceUserCtyBasic = ` 44 | resource "corner_user_cty" "foo" { 45 | email = "ford@prefect.co" 46 | name = "Ford Prefect" 47 | age = 200 48 | } 49 | ` 50 | 51 | const configResourceUserCtyUpdate = ` 52 | resource "corner_user_cty" "foo" { 53 | email = "ford@prefect.co" 54 | name = "Ford Prefect II" 55 | age = 300 56 | } 57 | ` 58 | -------------------------------------------------------------------------------- /internal/protocolprovider/data_deferred_action.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocol 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 12 | "github.com/hashicorp/terraform-plugin-go/tftypes" 13 | ) 14 | 15 | type dataDeferredAction struct{} 16 | 17 | func (d dataDeferredAction) ReadDataSource(ctx context.Context, req *tfprotov5.ReadDataSourceRequest) (*tfprotov5.ReadDataSourceResponse, error) { 18 | state, err := tfprotov5.NewDynamicValue(tftypes.Object{ 19 | AttributeTypes: map[string]tftypes.Type{ 20 | "current": tftypes.String, 21 | }, 22 | }, tftypes.NewValue(tftypes.Object{ 23 | AttributeTypes: map[string]tftypes.Type{ 24 | "current": tftypes.String, 25 | }, 26 | }, map[string]tftypes.Value{ 27 | "current": tftypes.NewValue(tftypes.String, time.Now().Format(time.RFC3339)), 28 | })) 29 | if err != nil { 30 | return &tfprotov5.ReadDataSourceResponse{ 31 | Diagnostics: []*tfprotov5.Diagnostic{ 32 | { 33 | Severity: tfprotov5.DiagnosticSeverityError, 34 | Summary: "Error encoding state", 35 | Detail: fmt.Sprintf("Error encoding state: %s", err.Error()), 36 | }, 37 | }, 38 | }, nil 39 | } 40 | return &tfprotov5.ReadDataSourceResponse{ 41 | State: &state, 42 | Deferred: &tfprotov5.Deferred{ 43 | Reason: tfprotov5.DeferredReasonResourceConfigUnknown, 44 | }, 45 | }, nil 46 | } 47 | 48 | func (d dataDeferredAction) ValidateDataSourceConfig(ctx context.Context, req *tfprotov5.ValidateDataSourceConfigRequest) (*tfprotov5.ValidateDataSourceConfigResponse, error) { 49 | return &tfprotov5.ValidateDataSourceConfigResponse{}, nil 50 | } 51 | -------------------------------------------------------------------------------- /internal/tf5muxprovider/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf5muxprovider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | ) 12 | 13 | func TestAccResourceUser(t *testing.T) { 14 | resource.UnitTest(t, resource.TestCase{ 15 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 16 | "tf5muxprovider": func() (tfprotov5.ProviderServer, error) { 17 | provider, err := New() 18 | 19 | return provider(), err 20 | }, 21 | }, 22 | Steps: []resource.TestStep{ 23 | { 24 | Config: configResourceUserBasic, 25 | Check: resource.ComposeTestCheckFunc( 26 | resource.TestCheckResourceAttr("tf5muxprovider_user1.example", "age", "123"), 27 | resource.TestCheckResourceAttr("tf5muxprovider_user1.example", "email", "example1@example.com"), 28 | resource.TestCheckResourceAttr("tf5muxprovider_user1.example", "name", "Example Name 1"), 29 | resource.TestCheckResourceAttr("tf5muxprovider_user2.example", "age", "234"), 30 | resource.TestCheckResourceAttr("tf5muxprovider_user2.example", "email", "example2@example.com"), 31 | resource.TestCheckResourceAttr("tf5muxprovider_user2.example", "name", "Example Name 2"), 32 | ), 33 | }, 34 | }, 35 | }) 36 | } 37 | 38 | const configResourceUserBasic = ` 39 | resource "tf5muxprovider_user1" "example" { 40 | age = 123 41 | email = "example1@example.com" 42 | name = "Example Name 1" 43 | } 44 | 45 | resource "tf5muxprovider_user2" "example" { 46 | age = 234 47 | email = "example2@example.com" 48 | name = "Example Name 2" 49 | } 50 | ` 51 | -------------------------------------------------------------------------------- /internal/protocolv6provider/data_deferred_action.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package protocolv6 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | "time" 10 | 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 12 | "github.com/hashicorp/terraform-plugin-go/tftypes" 13 | ) 14 | 15 | type dataSourceDeferredAction struct{} 16 | 17 | func (d dataSourceDeferredAction) ReadDataSource(ctx context.Context, req *tfprotov6.ReadDataSourceRequest) (*tfprotov6.ReadDataSourceResponse, error) { 18 | state, err := tfprotov6.NewDynamicValue(tftypes.Object{ 19 | AttributeTypes: map[string]tftypes.Type{ 20 | "current": tftypes.String, 21 | }, 22 | }, tftypes.NewValue(tftypes.Object{ 23 | AttributeTypes: map[string]tftypes.Type{ 24 | "current": tftypes.String, 25 | }, 26 | }, map[string]tftypes.Value{ 27 | "current": tftypes.NewValue(tftypes.String, time.Now().Format(time.RFC3339)), 28 | })) 29 | if err != nil { 30 | return &tfprotov6.ReadDataSourceResponse{ 31 | Diagnostics: []*tfprotov6.Diagnostic{ 32 | { 33 | Severity: tfprotov6.DiagnosticSeverityError, 34 | Summary: "Error encoding state", 35 | Detail: fmt.Sprintf("Error encoding state: %s", err.Error()), 36 | }, 37 | }, 38 | }, nil 39 | } 40 | return &tfprotov6.ReadDataSourceResponse{ 41 | State: &state, 42 | Deferred: &tfprotov6.Deferred{ 43 | Reason: tfprotov6.DeferredReasonResourceConfigUnknown, 44 | }, 45 | }, nil 46 | } 47 | 48 | func (d dataSourceDeferredAction) ValidateDataResourceConfig(ctx context.Context, req *tfprotov6.ValidateDataResourceConfigRequest) (*tfprotov6.ValidateDataResourceConfigResponse, error) { 49 | return &tfprotov6.ValidateDataResourceConfigResponse{}, nil 50 | } 51 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/data_source_regions_cty.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2testingprovider 6 | 7 | import ( 8 | "context" 9 | "errors" 10 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 13 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 14 | ) 15 | 16 | func dataSourceRegionsCty() *schema.Resource { 17 | return &schema.Resource{ 18 | // Prevent any accidental data inconsistencies 19 | EnableLegacyTypeSystemPlanErrors: true, 20 | EnableLegacyTypeSystemApplyErrors: true, 21 | 22 | ReadContext: dataSourceRegionsCtyRead, 23 | 24 | Schema: map[string]*schema.Schema{ 25 | "filter": { 26 | Type: schema.TypeString, 27 | Required: true, 28 | }, 29 | "names": { 30 | Type: schema.TypeList, 31 | Computed: true, 32 | Elem: &schema.Schema{Type: schema.TypeString}, 33 | }, 34 | }, 35 | } 36 | } 37 | 38 | func dataSourceRegionsCtyRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 39 | client := meta.(*backend.Client) 40 | 41 | config := d.GetRawConfig().AsValueMap() 42 | filter := config["filter"].AsString() 43 | if filter == "" { 44 | return diag.FromErr(errors.New("filter wasn't set")) 45 | } 46 | 47 | regions, err := client.ReadRegions() 48 | if err != nil { 49 | return diag.FromErr(err) 50 | } 51 | 52 | names := []string{} 53 | for _, r := range regions { 54 | names = append(names, r.Name) 55 | } 56 | 57 | d.SetId("regions") 58 | 59 | err = d.Set("names", names) 60 | if err != nil { 61 | return diag.FromErr(err) 62 | } 63 | 64 | return nil 65 | } 66 | -------------------------------------------------------------------------------- /internal/framework5provider/object_with_dynamic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/attr" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ function.Function = ObjectWithDynamicFunction{} 15 | 16 | func NewObjectWithDynamicFunction() function.Function { 17 | return &ObjectWithDynamicFunction{} 18 | } 19 | 20 | type ObjectWithDynamicFunction struct{} 21 | 22 | func (f ObjectWithDynamicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 23 | resp.Name = "object_with_dynamic" 24 | } 25 | 26 | func (f ObjectWithDynamicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 27 | resp.Definition = function.Definition{ 28 | Parameters: []function.Parameter{ 29 | function.ObjectParameter{ 30 | AttributeTypes: map[string]attr.Type{ 31 | "dynamic_attr1": types.DynamicType, 32 | "dynamic_attr2": types.DynamicType, 33 | }, 34 | Name: "object_param", 35 | }, 36 | }, 37 | Return: function.ObjectReturn{ 38 | AttributeTypes: map[string]attr.Type{ 39 | "dynamic_attr1": types.DynamicType, 40 | "dynamic_attr2": types.DynamicType, 41 | }, 42 | }, 43 | } 44 | } 45 | 46 | func (f ObjectWithDynamicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 47 | var arg struct { 48 | DynamicAttr1 types.Dynamic `tfsdk:"dynamic_attr1"` 49 | DynamicAttr2 types.Dynamic `tfsdk:"dynamic_attr2"` 50 | } 51 | 52 | resp.Error = req.Arguments.Get(ctx, &arg) 53 | 54 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 55 | } 56 | -------------------------------------------------------------------------------- /internal/framework6provider/object_with_dynamic_function.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/attr" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ function.Function = ObjectWithDynamicFunction{} 15 | 16 | func NewObjectWithDynamicFunction() function.Function { 17 | return &ObjectWithDynamicFunction{} 18 | } 19 | 20 | type ObjectWithDynamicFunction struct{} 21 | 22 | func (f ObjectWithDynamicFunction) Metadata(ctx context.Context, req function.MetadataRequest, resp *function.MetadataResponse) { 23 | resp.Name = "object_with_dynamic" 24 | } 25 | 26 | func (f ObjectWithDynamicFunction) Definition(ctx context.Context, req function.DefinitionRequest, resp *function.DefinitionResponse) { 27 | resp.Definition = function.Definition{ 28 | Parameters: []function.Parameter{ 29 | function.ObjectParameter{ 30 | AttributeTypes: map[string]attr.Type{ 31 | "dynamic_attr1": types.DynamicType, 32 | "dynamic_attr2": types.DynamicType, 33 | }, 34 | Name: "object_param", 35 | }, 36 | }, 37 | Return: function.ObjectReturn{ 38 | AttributeTypes: map[string]attr.Type{ 39 | "dynamic_attr1": types.DynamicType, 40 | "dynamic_attr2": types.DynamicType, 41 | }, 42 | }, 43 | } 44 | } 45 | 46 | func (f ObjectWithDynamicFunction) Run(ctx context.Context, req function.RunRequest, resp *function.RunResponse) { 47 | var arg struct { 48 | DynamicAttr1 types.Dynamic `tfsdk:"dynamic_attr1"` 49 | DynamicAttr2 types.Dynamic `tfsdk:"dynamic_attr2"` 50 | } 51 | 52 | resp.Error = req.Arguments.Get(ctx, &arg) 53 | 54 | resp.Error = function.ConcatFuncErrors(resp.Error, resp.Result.Set(ctx, arg)) 55 | } 56 | -------------------------------------------------------------------------------- /internal/cornertesting/expect_output_type_state_check.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package cornertesting 5 | 6 | import ( 7 | "context" 8 | "fmt" 9 | 10 | tfjson "github.com/hashicorp/terraform-json" 11 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 12 | "github.com/zclconf/go-cty/cty" 13 | ) 14 | 15 | var _ statecheck.StateCheck = expectOutputType{} 16 | 17 | type expectOutputType struct { 18 | outputAddress string 19 | expectedType cty.Type 20 | } 21 | 22 | func (e expectOutputType) CheckState(ctx context.Context, req statecheck.CheckStateRequest, resp *statecheck.CheckStateResponse) { 23 | var output *tfjson.StateOutput 24 | 25 | if req.State == nil { 26 | resp.Error = fmt.Errorf("state is nil") 27 | 28 | return 29 | } 30 | 31 | if req.State.Values == nil { 32 | resp.Error = fmt.Errorf("state does not contain any state values") 33 | 34 | return 35 | } 36 | 37 | for address, oc := range req.State.Values.Outputs { 38 | if e.outputAddress == address { 39 | output = oc 40 | 41 | break 42 | } 43 | } 44 | 45 | if output == nil { 46 | resp.Error = fmt.Errorf("%s - Output not found in state", e.outputAddress) 47 | 48 | return 49 | } 50 | 51 | if !output.Type.Equals(e.expectedType) { 52 | resp.Error = fmt.Errorf("expected %q output type to be %q, got %q", e.outputAddress, e.expectedType.FriendlyName(), output.Type.FriendlyName()) 53 | } 54 | } 55 | 56 | // ExpectOutputType returns a state check that asserts that the specified output has a cty.Type that matches `expectedType` 57 | // 58 | // NOTE: This check is only useful for output values that are populated by dynamic attributes or dynamic function returns. 59 | func ExpectOutputType(outputAddress string, expectedType cty.Type) statecheck.StateCheck { 60 | return expectOutputType{ 61 | outputAddress: outputAddress, 62 | expectedType: expectedType, 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider1/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider1 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/datasource" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/provider" 12 | "github.com/hashicorp/terraform-plugin-framework/provider/schema" 13 | "github.com/hashicorp/terraform-plugin-framework/resource" 14 | 15 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 16 | ) 17 | 18 | func New() provider.Provider { 19 | return &testProvider{} 20 | } 21 | 22 | type testProvider struct{} 23 | 24 | func (p *testProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) { 25 | resp.TypeName = "tf6muxprovider" 26 | } 27 | 28 | func (p *testProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) { 29 | resp.Schema = schema.Schema{ 30 | Attributes: map[string]schema.Attribute{ 31 | "example": schema.StringAttribute{ 32 | Optional: true, 33 | }, 34 | }, 35 | } 36 | } 37 | 38 | func (p *testProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { 39 | client, err := backend.NewClient() 40 | if err != nil { 41 | resp.Diagnostics.AddError("Error initialising client", err.Error()) 42 | } 43 | resp.ResourceData = client 44 | } 45 | 46 | func (p *testProvider) Resources(_ context.Context) []func() resource.Resource { 47 | return []func() resource.Resource{ 48 | NewUserResource, 49 | } 50 | } 51 | 52 | func (p *testProvider) DataSources(_ context.Context) []func() datasource.DataSource { 53 | return nil 54 | } 55 | 56 | func (p *testProvider) Functions(ctx context.Context) []func() function.Function { 57 | return []func() function.Function{ 58 | NewStringFunction, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /internal/tf6muxprovider/provider2/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider2 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/datasource" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/provider" 12 | "github.com/hashicorp/terraform-plugin-framework/provider/schema" 13 | "github.com/hashicorp/terraform-plugin-framework/resource" 14 | 15 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 16 | ) 17 | 18 | func New() provider.Provider { 19 | return &testProvider{} 20 | } 21 | 22 | type testProvider struct{} 23 | 24 | func (p *testProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) { 25 | resp.TypeName = "tf6muxprovider" 26 | } 27 | 28 | func (p *testProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) { 29 | resp.Schema = schema.Schema{ 30 | Attributes: map[string]schema.Attribute{ 31 | "example": schema.StringAttribute{ 32 | Optional: true, 33 | }, 34 | }, 35 | } 36 | } 37 | 38 | func (p *testProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { 39 | client, err := backend.NewClient() 40 | if err != nil { 41 | resp.Diagnostics.AddError("Error initialising client", err.Error()) 42 | } 43 | resp.ResourceData = client 44 | } 45 | 46 | func (p *testProvider) Resources(_ context.Context) []func() resource.Resource { 47 | return []func() resource.Resource{ 48 | NewUserResource, 49 | } 50 | } 51 | 52 | func (p *testProvider) DataSources(_ context.Context) []func() datasource.DataSource { 53 | return nil 54 | } 55 | 56 | func (p *testProvider) Functions(ctx context.Context) []func() function.Function { 57 | return []func() function.Function{ 58 | NewStringFunction, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /internal/tf6to5provider/provider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package provider 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/datasource" 10 | "github.com/hashicorp/terraform-plugin-framework/function" 11 | "github.com/hashicorp/terraform-plugin-framework/provider" 12 | "github.com/hashicorp/terraform-plugin-framework/provider/schema" 13 | "github.com/hashicorp/terraform-plugin-framework/resource" 14 | 15 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 16 | ) 17 | 18 | func New() provider.Provider { 19 | return &testProvider{} 20 | } 21 | 22 | type testProvider struct{} 23 | 24 | func (p *testProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) { 25 | resp.TypeName = "tf6to5provider" 26 | } 27 | 28 | func (p *testProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) { 29 | resp.Schema = schema.Schema{ 30 | Attributes: map[string]schema.Attribute{ 31 | "example": schema.StringAttribute{ 32 | Optional: true, 33 | }, 34 | }, 35 | } 36 | } 37 | 38 | func (p *testProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { 39 | client, err := backend.NewClient() 40 | if err != nil { 41 | resp.Diagnostics.AddError("Error initialising client", err.Error()) 42 | } 43 | resp.ResourceData = client 44 | } 45 | 46 | func (p *testProvider) Resources(_ context.Context) []func() resource.Resource { 47 | return []func() resource.Resource{ 48 | NewUserResource, 49 | } 50 | } 51 | 52 | func (p *testProvider) DataSources(_ context.Context) []func() datasource.DataSource { 53 | return nil 54 | } 55 | 56 | func (p *testProvider) Functions(ctx context.Context) []func() function.Function { 57 | return []func() function.Function{ 58 | NewStringFunction, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /internal/sdkv2provider/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | ) 12 | 13 | var testAccProviders map[string]*schema.Provider 14 | var testAccProvider *schema.Provider 15 | 16 | func init() { 17 | testAccProvider = New() 18 | testAccProviders = map[string]*schema.Provider{ 19 | "corner": testAccProvider, 20 | } 21 | } 22 | 23 | func TestProvider(t *testing.T) { 24 | if err := New().InternalValidate(); err != nil { 25 | t.Fatalf("err: %s", err) 26 | } 27 | } 28 | 29 | func TestProvider_impl(t *testing.T) { 30 | var _ *schema.Provider = New() 31 | } 32 | 33 | func testAccPreCheck(t *testing.T) { 34 | } 35 | 36 | func TestAccTests(t *testing.T) { 37 | for name, c := range TestCases { 38 | t.Helper() 39 | t.Run(name, func(t *testing.T) { 40 | resource.Test(t, c(t)) 41 | }) 42 | } 43 | } 44 | 45 | // public map of test cases that can be imported by Core/SDK etc. 46 | var TestCases = map[string]func(*testing.T) resource.TestCase{ 47 | "corner_user": testAccResourceUser, 48 | "corner_user_identity": testAccResourceUserIdentity, 49 | "corner_user_identity_upgrade": testAccResourceUserIdentityUpgrade, 50 | "corner_regions": testAccDataSourceRegions, 51 | "corner_bigint_data": testAccDataSourceBigint, 52 | "corner_bigint": testAccResourceBigint, 53 | "corner_user_cty": testAccResourceUserCty, 54 | "corner_regions_cty": testAccDataSourceRegionsCty, 55 | "corner_deferred_action": testAccResourceDeferredAction, 56 | "corner_deferred_action_plan_modification": testAccResourceDeferredActionPlanModification, 57 | } 58 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_write_only_upgrade_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 12 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 13 | "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" 14 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 15 | ) 16 | 17 | func TestWriteOnlyUpgradeResource(t *testing.T) { 18 | t.Parallel() 19 | 20 | resource.UnitTest(t, resource.TestCase{ 21 | // Write-only attributes are only available in 1.11.0+ 22 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 23 | tfversion.SkipBelow(tfversion.Version1_11_0), 24 | }, 25 | Steps: []resource.TestStep{ 26 | { 27 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 28 | "corner": func() (tfprotov5.ProviderServer, error) { //nolint 29 | return NewWithUpgradeVersion(0).GRPCProvider(), nil 30 | }, 31 | }, 32 | Config: `resource "corner_writeonly_upgrade" "test" { 33 | string_attr = "hello!" 34 | writeonly_string = "fakepassword" 35 | }`, 36 | ConfigStateChecks: []statecheck.StateCheck{ 37 | statecheck.ExpectKnownValue("corner_writeonly_upgrade.test", tfjsonpath.New("writeonly_string"), knownvalue.Null()), 38 | }, 39 | }, 40 | { 41 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 42 | "corner": func() (tfprotov5.ProviderServer, error) { //nolint 43 | return NewWithUpgradeVersion(1).GRPCProvider(), nil 44 | }, 45 | }, 46 | Config: `resource "corner_writeonly_upgrade" "test" { 47 | string_attr = "world!" 48 | writeonly_string = "fakepassword" 49 | }`, 50 | ConfigStateChecks: []statecheck.StateCheck{ 51 | statecheck.ExpectKnownValue("corner_writeonly_upgrade.test", tfjsonpath.New("writeonly_string"), knownvalue.Null()), 52 | }, 53 | }, 54 | }, 55 | }) 56 | } 57 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_bigint.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2 6 | 7 | import ( 8 | "context" 9 | "strconv" 10 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 13 | ) 14 | 15 | func resourceBigint() *schema.Resource { 16 | return &schema.Resource{ 17 | // Prevent any accidental data inconsistencies 18 | EnableLegacyTypeSystemPlanErrors: true, 19 | EnableLegacyTypeSystemApplyErrors: true, 20 | 21 | CreateContext: resourceBigintCreate, 22 | ReadContext: resourceBigintRead, 23 | UpdateContext: resourceBigintUpdate, 24 | DeleteContext: resourceBigintDelete, 25 | UseJSONNumber: true, 26 | 27 | Schema: map[string]*schema.Schema{ 28 | "number": { 29 | Type: schema.TypeInt, 30 | Required: true, 31 | }, 32 | "int64": { 33 | Type: schema.TypeInt, 34 | Computed: true, 35 | }, 36 | }, 37 | } 38 | } 39 | 40 | func resourceBigintCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 41 | number := d.Get("number").(int) 42 | d.SetId(strconv.Itoa(number)) 43 | 44 | if err := d.Set("int64", number); err != nil { 45 | return diag.FromErr(err) 46 | } 47 | return resourceBigintRead(ctx, d, meta) 48 | } 49 | 50 | func resourceBigintRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 51 | number, err := strconv.ParseInt(d.Id(), 10, 64) 52 | if err != nil { 53 | return diag.FromErr(err) 54 | } 55 | 56 | if err = d.Set("int64", number); err != nil { 57 | return diag.FromErr(err) 58 | } 59 | return nil 60 | } 61 | 62 | func resourceBigintUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 63 | number := d.Get("number").(int) 64 | d.SetId(strconv.Itoa(number)) 65 | if err := d.Set("int64", number); err != nil { 66 | return diag.FromErr(err) 67 | } 68 | return nil 69 | } 70 | 71 | func resourceBigintDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 72 | return nil 73 | } 74 | -------------------------------------------------------------------------------- /internal/sdkv2testingprovider/resource_bigint.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2testingprovider 6 | 7 | import ( 8 | "context" 9 | "strconv" 10 | 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 12 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 13 | ) 14 | 15 | func resourceBigint() *schema.Resource { 16 | return &schema.Resource{ 17 | // Prevent any accidental data inconsistencies 18 | EnableLegacyTypeSystemPlanErrors: true, 19 | EnableLegacyTypeSystemApplyErrors: true, 20 | 21 | CreateContext: resourceBigintCreate, 22 | ReadContext: resourceBigintRead, 23 | UpdateContext: resourceBigintUpdate, 24 | DeleteContext: resourceBigintDelete, 25 | UseJSONNumber: true, 26 | 27 | Schema: map[string]*schema.Schema{ 28 | "number": { 29 | Type: schema.TypeInt, 30 | Required: true, 31 | }, 32 | "int64": { 33 | Type: schema.TypeInt, 34 | Computed: true, 35 | }, 36 | }, 37 | } 38 | } 39 | 40 | func resourceBigintCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 41 | number := d.Get("number").(int) 42 | d.SetId(strconv.Itoa(number)) 43 | 44 | if err := d.Set("int64", number); err != nil { 45 | return diag.FromErr(err) 46 | } 47 | return resourceBigintRead(ctx, d, meta) 48 | } 49 | 50 | func resourceBigintRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 51 | number, err := strconv.ParseInt(d.Id(), 10, 64) 52 | if err != nil { 53 | return diag.FromErr(err) 54 | } 55 | 56 | if err = d.Set("int64", number); err != nil { 57 | return diag.FromErr(err) 58 | } 59 | return nil 60 | } 61 | 62 | func resourceBigintUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 63 | number := d.Get("number").(int) 64 | d.SetId(strconv.Itoa(number)) 65 | if err := d.Set("int64", number); err != nil { 66 | return diag.FromErr(err) 67 | } 68 | return nil 69 | } 70 | 71 | func resourceBigintDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 72 | return nil 73 | } 74 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_user_identity_upgrade_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 12 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 13 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 14 | ) 15 | 16 | func testAccResourceUserIdentityUpgrade(t *testing.T) resource.TestCase { 17 | return resource.TestCase{ 18 | PreCheck: func() { testAccPreCheck(t) }, 19 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 20 | tfversion.SkipBelow(tfversion.Version1_12_0), 21 | }, 22 | Steps: []resource.TestStep{ 23 | { 24 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 25 | "corner": func() (tfprotov5.ProviderServer, error) { //nolint 26 | return NewWithIdentityUpgradeVersion(0).GRPCProvider(), nil 27 | }, 28 | }, 29 | Config: `resource "corner_user_identity_upgrade" "foo" { 30 | email = "ford@prefect.co" 31 | name = "Ford Prefect" 32 | age = 200 33 | }`, 34 | ConfigStateChecks: []statecheck.StateCheck{ 35 | statecheck.ExpectIdentity("corner_user_identity_upgrade.foo", map[string]knownvalue.Check{ 36 | "email": knownvalue.StringExact("ford@prefect.co"), 37 | }), 38 | }, 39 | }, 40 | { 41 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 42 | "corner": func() (tfprotov5.ProviderServer, error) { //nolint 43 | return NewWithIdentityUpgradeVersion(1).GRPCProvider(), nil 44 | }, 45 | }, 46 | Config: `resource "corner_user_identity_upgrade" "foo" { 47 | email = "ford@prefect.co" 48 | name = "Ford Prefect" 49 | age = 200 50 | }`, 51 | ConfigStateChecks: []statecheck.StateCheck{ 52 | statecheck.ExpectIdentity("corner_user_identity_upgrade.foo", map[string]knownvalue.Check{ 53 | "local_part": knownvalue.StringExact("ford"), 54 | "domain": knownvalue.StringExact("prefect.co"), 55 | }), 56 | }, 57 | }, 58 | }, 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /internal/tf6to5provider/provider_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package tf6to5provider 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 10 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 11 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 12 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 13 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 14 | ) 15 | 16 | func TestAccResourceUser(t *testing.T) { 17 | resource.UnitTest(t, resource.TestCase{ 18 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 19 | "tf6to5provider": func() (tfprotov5.ProviderServer, error) { 20 | provider, err := New() 21 | 22 | return provider(), err 23 | }, 24 | }, 25 | Steps: []resource.TestStep{ 26 | { 27 | Config: configResourceUserBasic, 28 | Check: resource.ComposeTestCheckFunc( 29 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "age", "123"), 30 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "email", "example@example.com"), 31 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "language", "en"), 32 | resource.TestCheckResourceAttr("tf6to5provider_user.example", "name", "Example Name"), 33 | ), 34 | }, 35 | }, 36 | }) 37 | } 38 | 39 | const configResourceUserBasic = ` 40 | resource "tf6to5provider_user" "example" { 41 | age = 123 42 | email = "example@example.com" 43 | name = "Example Name" 44 | } 45 | ` 46 | 47 | func TestAccFunctionString(t *testing.T) { 48 | resource.UnitTest(t, resource.TestCase{ 49 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 50 | tfversion.SkipBelow(tfversion.Version1_8_0), 51 | }, 52 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 53 | "tf6to5provider": func() (tfprotov5.ProviderServer, error) { 54 | provider, err := New() 55 | 56 | return provider(), err 57 | }, 58 | }, 59 | Steps: []resource.TestStep{ 60 | { 61 | Config: ` 62 | output "test1" { 63 | value = provider::tf6to5provider::string("str") 64 | }`, 65 | ConfigStateChecks: []statecheck.StateCheck{ 66 | statecheck.ExpectKnownOutputValue("test1", knownvalue.StringExact("str")), 67 | }, 68 | }, 69 | }, 70 | }) 71 | } 72 | -------------------------------------------------------------------------------- /internal/framework5provider/timeouts_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" 10 | "github.com/hashicorp/terraform-plugin-framework/resource" 11 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 12 | ) 13 | 14 | var _ resource.Resource = TimeoutsResource{} 15 | 16 | func NewTimeoutsResource() resource.Resource { 17 | return &TimeoutsResource{} 18 | } 19 | 20 | // TimeoutsResource is for testing all schema types. 21 | type TimeoutsResource struct{} 22 | 23 | func (r TimeoutsResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_timeouts" 25 | } 26 | 27 | func (r TimeoutsResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Blocks: map[string]schema.Block{ 30 | "timeouts": timeouts.Block(ctx, timeouts.Opts{ 31 | Create: true, 32 | }), 33 | }, 34 | } 35 | } 36 | 37 | func (r TimeoutsResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 38 | var data TimeoutsResourceModel 39 | 40 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 41 | 42 | if resp.Diagnostics.HasError() { 43 | return 44 | } 45 | 46 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 47 | } 48 | 49 | func (r TimeoutsResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 50 | var data TimeoutsResourceModel 51 | 52 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 53 | 54 | if resp.Diagnostics.HasError() { 55 | return 56 | } 57 | 58 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 59 | } 60 | 61 | func (r TimeoutsResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 62 | var data TimeoutsResourceModel 63 | 64 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 65 | 66 | if resp.Diagnostics.HasError() { 67 | return 68 | } 69 | 70 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 71 | } 72 | 73 | func (r TimeoutsResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 74 | } 75 | 76 | type TimeoutsResourceModel struct { 77 | Timeouts timeouts.Value `tfsdk:"timeouts"` 78 | } 79 | -------------------------------------------------------------------------------- /internal/framework6provider/timeouts_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework-timeouts/resource/timeouts" 10 | "github.com/hashicorp/terraform-plugin-framework/resource" 11 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 12 | ) 13 | 14 | var _ resource.Resource = TimeoutsResource{} 15 | 16 | func NewTimeoutsResource() resource.Resource { 17 | return &TimeoutsResource{} 18 | } 19 | 20 | // TimeoutsResource is for testing all schema types. 21 | type TimeoutsResource struct{} 22 | 23 | func (r TimeoutsResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_timeouts" 25 | } 26 | 27 | func (r TimeoutsResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Attributes: map[string]schema.Attribute{ 30 | "timeouts": timeouts.Attributes(ctx, timeouts.Opts{ 31 | Create: true, 32 | }), 33 | }, 34 | } 35 | } 36 | 37 | func (r TimeoutsResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 38 | var data TimeoutsResourceModel 39 | 40 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 41 | 42 | if resp.Diagnostics.HasError() { 43 | return 44 | } 45 | 46 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 47 | } 48 | 49 | func (r TimeoutsResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 50 | var data TimeoutsResourceModel 51 | 52 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 53 | 54 | if resp.Diagnostics.HasError() { 55 | return 56 | } 57 | 58 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 59 | } 60 | 61 | func (r TimeoutsResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 62 | var data TimeoutsResourceModel 63 | 64 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 65 | 66 | if resp.Diagnostics.HasError() { 67 | return 68 | } 69 | 70 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 71 | } 72 | 73 | func (r TimeoutsResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 74 | } 75 | 76 | type TimeoutsResourceModel struct { 77 | Timeouts timeouts.Value `tfsdk:"timeouts"` 78 | } 79 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_write_only_upgrade.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 12 | ) 13 | 14 | func resourceWriteOnlyUpgrade(version int) *schema.Resource { 15 | rSchema := &schema.Resource{ 16 | // Prevent any accidental data inconsistencies 17 | EnableLegacyTypeSystemPlanErrors: true, 18 | EnableLegacyTypeSystemApplyErrors: true, 19 | 20 | SchemaVersion: version, 21 | 22 | CreateContext: resourceWriteOnlyUpgradeCreate, 23 | ReadContext: resourceWriteOnlyUpgradeRead, 24 | UpdateContext: resourceWriteOnlyUpgradeUpdate, 25 | DeleteContext: resourceWriteOnlyUpgradeDelete, 26 | 27 | Schema: map[string]*schema.Schema{ 28 | "string_attr": { 29 | Type: schema.TypeString, 30 | Required: true, 31 | }, 32 | "writeonly_string": { 33 | Type: schema.TypeString, 34 | Optional: true, 35 | WriteOnly: true, 36 | }, 37 | }, 38 | } 39 | 40 | // Avoid the internal validate error for defining a state upgrade that is equal to the schema version 41 | if version > 0 { 42 | rSchema.StateUpgraders = []schema.StateUpgrader{ 43 | { 44 | Version: 0, 45 | Type: rSchema.CoreConfigSchema().ImpliedType(), 46 | Upgrade: func(ctx context.Context, rawState map[string]interface{}, meta interface{}) (map[string]interface{}, error) { 47 | upgradedState := map[string]any{ 48 | "id": "fakeid-123", 49 | "string_attr": "hello world!", 50 | "writeonly_string": "this shouldn't cause an error", 51 | } 52 | 53 | return upgradedState, nil 54 | }, 55 | }, 56 | } 57 | } 58 | return rSchema 59 | } 60 | 61 | func resourceWriteOnlyUpgradeCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 62 | d.SetId("fakeid-123") 63 | 64 | return nil 65 | } 66 | 67 | func resourceWriteOnlyUpgradeRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 68 | return nil 69 | } 70 | 71 | func resourceWriteOnlyUpgradeUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 72 | return nil 73 | } 74 | 75 | func resourceWriteOnlyUpgradeDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 76 | return nil 77 | } 78 | -------------------------------------------------------------------------------- /internal/sdkv2provider/resource_write_only_import.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | //nolint:forcetypeassert // Test SDK provider 5 | package sdkv2 6 | 7 | import ( 8 | "context" 9 | 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 11 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 12 | ) 13 | 14 | func resourceWriteOnlyImport() *schema.Resource { 15 | return &schema.Resource{ 16 | // Prevent any accidental data inconsistencies 17 | EnableLegacyTypeSystemPlanErrors: true, 18 | EnableLegacyTypeSystemApplyErrors: true, 19 | 20 | CreateContext: resourceWriteOnlyImportCreate, 21 | ReadContext: resourceWriteOnlyImportRead, 22 | UpdateContext: resourceWriteOnlyImportUpdate, 23 | DeleteContext: resourceWriteOnlyImportDelete, 24 | 25 | Importer: &schema.ResourceImporter{ 26 | StateContext: func(_ context.Context, d *schema.ResourceData, _ interface{}) ([]*schema.ResourceData, error) { 27 | // Setting shouldn't result in anything sent back to Terraform, but we want to test that 28 | // our SDKv2 logic would revert these changes. 29 | err := d.Set("writeonly_string", "different value") 30 | if err != nil { 31 | return nil, err 32 | } 33 | 34 | return []*schema.ResourceData{d}, nil 35 | }, 36 | }, 37 | 38 | Schema: map[string]*schema.Schema{ 39 | "string_attr": { 40 | Type: schema.TypeString, 41 | Required: true, 42 | }, 43 | "writeonly_string": { 44 | Type: schema.TypeString, 45 | Optional: true, 46 | WriteOnly: true, 47 | }, 48 | }, 49 | } 50 | } 51 | 52 | func resourceWriteOnlyImportCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 53 | d.SetId("fakeid-123") 54 | 55 | return nil 56 | } 57 | 58 | func resourceWriteOnlyImportRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 59 | err := d.Set("string_attr", "hello world!") 60 | if err != nil { 61 | return diag.FromErr(err) 62 | } 63 | 64 | // Setting shouldn't result in anything sent back to Terraform, but we want to test that 65 | // our SDKv2 logic would revert these changes. 66 | err = d.Set("writeonly_string", "different value") 67 | if err != nil { 68 | return diag.FromErr(err) 69 | } 70 | 71 | return nil 72 | } 73 | 74 | func resourceWriteOnlyImportUpdate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 75 | return nil 76 | } 77 | 78 | func resourceWriteOnlyImportDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { 79 | return nil 80 | } 81 | -------------------------------------------------------------------------------- /internal/framework5provider/list_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework_test 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/google/go-cmp/cmp" 10 | "github.com/google/go-cmp/cmp/cmpopts" 11 | frameworktypes "github.com/hashicorp/terraform-plugin-framework/provider" 12 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 13 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 14 | "github.com/hashicorp/terraform-plugin-go/tftypes" 15 | framework "github.com/hashicorp/terraform-provider-corner/internal/framework5provider" 16 | ) 17 | 18 | func TestListResource(t *testing.T) { 19 | t.Parallel() 20 | ctx := t.Context() 21 | 22 | rawProvider := framework.New() 23 | provider, ok := rawProvider.(frameworktypes.ProviderWithListResources) 24 | if !ok { 25 | t.Fatalf("Expected provider to implement ProviderWithListResources, got %T", rawProvider) 26 | } 27 | 28 | rawS, err := providerserver.NewProtocol5WithError(provider)() 29 | if err != nil { 30 | t.Fatalf("Failed to create provider server: %v", err) 31 | } 32 | 33 | s, ok := rawS.(tfprotov5.ProviderServerWithListResource) //nolint:staticcheck 34 | if !ok { 35 | t.Fatalf("Expected server to implement ProviderServerWithListResource, got %T", rawS) 36 | } 37 | 38 | config, err := tfprotov5.NewDynamicValue( 39 | tftypes.Object{ 40 | AttributeTypes: map[string]tftypes.Type{ 41 | "filter": tftypes.String, 42 | }, 43 | }, 44 | tftypes.NewValue( 45 | tftypes.Object{ 46 | AttributeTypes: map[string]tftypes.Type{ 47 | "filter": tftypes.String, 48 | }, 49 | }, 50 | map[string]tftypes.Value{ 51 | "filter": tftypes.NewValue(tftypes.String, "plat"), 52 | }, 53 | ), 54 | ) 55 | if err != nil { 56 | t.Fatalf("Failed to create dynamic value: %v", err) 57 | } 58 | 59 | listRequest := &tfprotov5.ListResourceRequest{ 60 | TypeName: "framework_list_resource", 61 | Config: &config, 62 | } 63 | 64 | stream, err := s.ListResource(ctx, listRequest) 65 | if err != nil { 66 | t.Fatalf("Failed to list resources: %v", err) 67 | } 68 | 69 | got := []string{} 70 | wanted := []string{"plateau", "platinum", "platypus"} 71 | for result := range stream.Results { 72 | got = append(got, result.DisplayName) 73 | 74 | if len(result.Diagnostics) > 0 { 75 | t.Errorf("expected 0 diagnostics; got: %v", result.Diagnostics) 76 | } 77 | } 78 | 79 | opts := cmp.Options{ 80 | cmpopts.SortSlices(func(x, y string) bool { return x < y }), 81 | } 82 | if diff := cmp.Diff(got, wanted, opts); diff != "" { 83 | t.Errorf("ListResource results mismatch (-got +wanted):\n%s", diff) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /internal/sdkv2provider/provider.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package sdkv2 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-sdk/v2/diag" 10 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" 11 | 12 | "github.com/hashicorp/terraform-provider-corner/internal/backend" 13 | ) 14 | 15 | func New() *schema.Provider { 16 | p := &schema.Provider{ 17 | Schema: map[string]*schema.Schema{ 18 | "deferral": { 19 | Type: schema.TypeBool, 20 | Optional: true, 21 | }, 22 | }, 23 | DataSourcesMap: map[string]*schema.Resource{ 24 | "corner_regions": dataSourceRegions(), 25 | "corner_bigint": dataSourceBigint(), 26 | "corner_regions_cty": dataSourceRegionsCty(), 27 | }, 28 | ResourcesMap: map[string]*schema.Resource{ 29 | "corner_user": resourceUser(), 30 | "corner_user_identity": resourceUserIdentity(), 31 | "corner_user_identity_upgrade": resourceUserIdentityUpgrade(0), 32 | "corner_writeonly": resourceWriteOnly(), 33 | "corner_writeonly_import": resourceWriteOnlyImport(), 34 | "corner_writeonly_upgrade": resourceWriteOnlyUpgrade(0), 35 | "corner_writeonce": resourceWriteOnce(), 36 | "corner_writeonly_validations": resourceWriteOnlyValidations(), 37 | "corner_bigint": resourceBigint(), 38 | "corner_user_cty": resourceUserCty(), 39 | "corner_deferred_action": resourceDeferredAction(), 40 | "corner_deferred_action_plan_modification": resourceDeferredActionPlanModification(), 41 | }, 42 | } 43 | 44 | p.ConfigureProvider = func(ctx context.Context, req schema.ConfigureProviderRequest, resp *schema.ConfigureProviderResponse) { 45 | client, err := backend.NewClient() 46 | if err != nil { 47 | resp.Diagnostics = diag.FromErr(err) 48 | } 49 | 50 | if req.ResourceData.Get("deferral") == true && req.DeferralAllowed { 51 | resp.Deferred = &schema.Deferred{ 52 | Reason: schema.DeferredReasonProviderConfigUnknown, 53 | } 54 | } 55 | resp.Meta = client 56 | } 57 | 58 | return p 59 | } 60 | 61 | func NewWithUpgradeVersion(version int) *schema.Provider { 62 | p := New() 63 | p.ResourcesMap["corner_writeonly_upgrade"] = resourceWriteOnlyUpgrade(version) 64 | 65 | return p 66 | } 67 | 68 | func NewWithIdentityUpgradeVersion(version int) *schema.Provider { 69 | p := New() 70 | p.ResourcesMap["corner_user_identity_upgrade"] = resourceUserIdentityUpgrade(version) 71 | 72 | return p 73 | } 74 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package main 5 | 6 | import ( 7 | "context" 8 | "flag" 9 | "log" 10 | 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 12 | "github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server" 13 | "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" 14 | protocol "github.com/hashicorp/terraform-provider-corner/internal/protocolprovider" 15 | sdkv2 "github.com/hashicorp/terraform-provider-corner/internal/sdkv2provider" 16 | ) 17 | 18 | // MAINTAINER NOTE: The current main function does not include all of the available corner resource types 19 | // as the corner provider is rarely needed to be built as a single binary. The corner CI testing suite executes 20 | // Go test directly against the internal packages which contain provider servers that have conflicting type names 21 | // and different provider namespaces (testing both v5 and v6 protocols). Debugging those provider servers can also 22 | // be achieved with Go's testing tools and a debugger such as delve. 23 | // 24 | // In the future, if we want to adjust this provider to be built as a single binary, we will need to refactor all of the 25 | // internal provider packages and resource type names to avoid conflicts, as well as allow the provider binary to be built 26 | // with protocol v5 or v6 conditionally. 27 | func main() { 28 | debugFlag := flag.Bool("debug", false, "Start provider in debug mode.") 29 | debugEnvFilePath := flag.String("debug-env-file", "", "Path to the debug environment file to which reattach config gets written.") 30 | flag.Parse() 31 | 32 | ctx := context.Background() 33 | providers := []func() tfprotov5.ProviderServer{ 34 | func() tfprotov5.ProviderServer { 35 | return protocol.Server(false) 36 | }, 37 | sdkv2.New().GRPCProvider, 38 | } 39 | 40 | muxServer, err := tf5muxserver.NewMuxServer(ctx, providers...) 41 | 42 | if err != nil { 43 | log.Fatalf("unable to create provider: %s", err) 44 | } 45 | 46 | var serveOpts []tf5server.ServeOpt 47 | 48 | if *debugFlag { 49 | serveOpts = append( 50 | serveOpts, 51 | tf5server.WithManagedDebug(), 52 | ) 53 | } 54 | 55 | if *debugEnvFilePath != "" { 56 | if !*debugFlag { 57 | log.Fatalf("debug environment file path provided without debug flag, please also set -debug") 58 | } 59 | 60 | serveOpts = append( 61 | serveOpts, 62 | tf5server.WithManagedDebugEnvFilePath(*debugEnvFilePath), 63 | ) 64 | } 65 | 66 | err = tf5server.Serve("registry.terraform.io/hashicorp/corner", 67 | muxServer.ProviderServer, 68 | serveOpts..., 69 | ) 70 | 71 | if err != nil { 72 | log.Fatalf("unable to serve provider: %s", err) 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /internal/framework5provider/timetypes_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" 10 | "github.com/hashicorp/terraform-plugin-framework/resource" 11 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 12 | ) 13 | 14 | var _ resource.Resource = TimeTypesResource{} 15 | 16 | func NewTimeTypesResource() resource.Resource { 17 | return &TimeTypesResource{} 18 | } 19 | 20 | // TimeTypesResource is for testing all schema types. 21 | type TimeTypesResource struct{} 22 | 23 | func (r TimeTypesResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_timetypes" 25 | } 26 | 27 | func (r TimeTypesResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Attributes: map[string]schema.Attribute{ 30 | "go_duration": schema.StringAttribute{ 31 | CustomType: timetypes.GoDurationType{}, 32 | Optional: true, 33 | }, 34 | "rfc3339": schema.StringAttribute{ 35 | CustomType: timetypes.RFC3339Type{}, 36 | Optional: true, 37 | }, 38 | }, 39 | } 40 | } 41 | 42 | func (r TimeTypesResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 43 | var data TimeTypesResourceModel 44 | 45 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 46 | 47 | if resp.Diagnostics.HasError() { 48 | return 49 | } 50 | 51 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 52 | } 53 | 54 | func (r TimeTypesResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 55 | var data TimeTypesResourceModel 56 | 57 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 58 | 59 | if resp.Diagnostics.HasError() { 60 | return 61 | } 62 | 63 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 64 | } 65 | 66 | func (r TimeTypesResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 67 | var data TimeTypesResourceModel 68 | 69 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 70 | 71 | if resp.Diagnostics.HasError() { 72 | return 73 | } 74 | 75 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 76 | } 77 | 78 | func (r TimeTypesResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 79 | } 80 | 81 | type TimeTypesResourceModel struct { 82 | GoDuration timetypes.GoDuration `tfsdk:"go_duration"` 83 | Rfc3339 timetypes.RFC3339 `tfsdk:"rfc3339"` 84 | } 85 | -------------------------------------------------------------------------------- /internal/framework6provider/timetypes_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes" 10 | "github.com/hashicorp/terraform-plugin-framework/resource" 11 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 12 | ) 13 | 14 | var _ resource.Resource = TimeTypesResource{} 15 | 16 | func NewTimeTypesResource() resource.Resource { 17 | return &TimeTypesResource{} 18 | } 19 | 20 | // TimeTypesResource is for testing all schema types. 21 | type TimeTypesResource struct{} 22 | 23 | func (r TimeTypesResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_timetypes" 25 | } 26 | 27 | func (r TimeTypesResource) Schema(ctx context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Attributes: map[string]schema.Attribute{ 30 | "go_duration": schema.StringAttribute{ 31 | CustomType: timetypes.GoDurationType{}, 32 | Optional: true, 33 | }, 34 | "rfc3339": schema.StringAttribute{ 35 | CustomType: timetypes.RFC3339Type{}, 36 | Optional: true, 37 | }, 38 | }, 39 | } 40 | } 41 | 42 | func (r TimeTypesResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 43 | var data TimeTypesResourceModel 44 | 45 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 46 | 47 | if resp.Diagnostics.HasError() { 48 | return 49 | } 50 | 51 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 52 | } 53 | 54 | func (r TimeTypesResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 55 | var data TimeTypesResourceModel 56 | 57 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 58 | 59 | if resp.Diagnostics.HasError() { 60 | return 61 | } 62 | 63 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 64 | } 65 | 66 | func (r TimeTypesResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 67 | var data TimeTypesResourceModel 68 | 69 | resp.Diagnostics.Append(req.Plan.Get(ctx, &data)...) 70 | 71 | if resp.Diagnostics.HasError() { 72 | return 73 | } 74 | 75 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 76 | } 77 | 78 | func (r TimeTypesResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 79 | } 80 | 81 | type TimeTypesResourceModel struct { 82 | GoDuration timetypes.GoDuration `tfsdk:"go_duration"` 83 | Rfc3339 timetypes.RFC3339 `tfsdk:"rfc3339"` 84 | } 85 | -------------------------------------------------------------------------------- /tools/go.mod: -------------------------------------------------------------------------------- 1 | module tools 2 | 3 | go 1.24.0 4 | 5 | require github.com/hashicorp/copywrite v0.22.0 6 | 7 | require ( 8 | github.com/AlecAivazis/survey/v2 v2.3.7 // indirect 9 | github.com/ProtonMail/go-crypto v0.0.0-20230217124315-7d5c6f04bbb8 // indirect 10 | github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect 11 | github.com/bmatcuk/doublestar/v4 v4.6.0 // indirect 12 | github.com/bradleyfalzon/ghinstallation/v2 v2.5.0 // indirect 13 | github.com/cli/go-gh/v2 v2.12.1 // indirect 14 | github.com/cli/safeexec v1.0.0 // indirect 15 | github.com/cloudflare/circl v1.6.1 // indirect 16 | github.com/fatih/color v1.13.0 // indirect 17 | github.com/fsnotify/fsnotify v1.5.4 // indirect 18 | github.com/go-openapi/errors v0.20.2 // indirect 19 | github.com/go-openapi/strfmt v0.21.3 // indirect 20 | github.com/golang-jwt/jwt/v4 v4.5.2 // indirect 21 | github.com/google/go-github/v45 v45.2.0 // indirect 22 | github.com/google/go-github/v53 v53.0.0 // indirect 23 | github.com/google/go-querystring v1.1.0 // indirect 24 | github.com/hashicorp/go-hclog v1.5.0 // indirect 25 | github.com/hashicorp/hcl v1.0.0 // indirect 26 | github.com/inconshreveable/mousetrap v1.0.1 // indirect 27 | github.com/jedib0t/go-pretty v4.3.0+incompatible // indirect 28 | github.com/jedib0t/go-pretty/v6 v6.4.6 // indirect 29 | github.com/joho/godotenv v1.3.0 // indirect 30 | github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect 31 | github.com/knadh/koanf v1.5.0 // indirect 32 | github.com/mattn/go-colorable v0.1.13 // indirect 33 | github.com/mattn/go-isatty v0.0.20 // indirect 34 | github.com/mattn/go-runewidth v0.0.16 // indirect 35 | github.com/mergestat/timediff v0.0.3 // indirect 36 | github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect 37 | github.com/mitchellh/copystructure v1.2.0 // indirect 38 | github.com/mitchellh/go-homedir v1.1.0 // indirect 39 | github.com/mitchellh/mapstructure v1.5.0 // indirect 40 | github.com/mitchellh/reflectwalk v1.0.2 // indirect 41 | github.com/oklog/ulid v1.3.1 // indirect 42 | github.com/rivo/uniseg v0.4.7 // indirect 43 | github.com/rogpeppe/go-internal v1.10.0 // indirect 44 | github.com/samber/lo v1.37.0 // indirect 45 | github.com/spf13/cobra v1.6.1 // indirect 46 | github.com/spf13/pflag v1.0.5 // indirect 47 | github.com/thanhpk/randstr v1.0.4 // indirect 48 | go.mongodb.org/mongo-driver v1.10.0 // indirect 49 | golang.org/x/crypto v0.45.0 // indirect 50 | golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect 51 | golang.org/x/oauth2 v0.27.0 // indirect 52 | golang.org/x/sync v0.18.0 // indirect 53 | golang.org/x/sys v0.38.0 // indirect 54 | golang.org/x/term v0.37.0 // indirect 55 | golang.org/x/text v0.31.0 // indirect 56 | gopkg.in/yaml.v3 v3.0.1 // indirect 57 | ) 58 | -------------------------------------------------------------------------------- /internal/framework5provider/dynamic_computed_type_change_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 13 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 14 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 15 | "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" 16 | ) 17 | 18 | // Ref: https://github.com/hashicorp/terraform-plugin-framework/issues/969 19 | // This test confirms that dynamic computed attributes are marked as unknown, both value AND type. 20 | // Dynamic computed attributes can change the type after plan in this scenario. 21 | func TestDynamicComputedTypeChange(t *testing.T) { 22 | resource.UnitTest(t, resource.TestCase{ 23 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 24 | "framework": providerserver.NewProtocol5WithError(New()), 25 | }, 26 | Steps: []resource.TestStep{ 27 | { 28 | Config: `resource "framework_dynamic_computed_type_change" "test" { 29 | required_dynamic = "value1" 30 | }`, 31 | ConfigPlanChecks: resource.ConfigPlanChecks{ 32 | PreApply: []plancheck.PlanCheck{ 33 | plancheck.ExpectUnknownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes")), 34 | }, 35 | }, 36 | ConfigStateChecks: []statecheck.StateCheck{ 37 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("required_dynamic"), knownvalue.StringExact("value1")), 38 | // Created as a boolean 39 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes"), knownvalue.Bool(true)), 40 | }, 41 | }, 42 | { 43 | Config: `resource "framework_dynamic_computed_type_change" "test" { 44 | required_dynamic = "new value" 45 | }`, 46 | ConfigPlanChecks: resource.ConfigPlanChecks{ 47 | PreApply: []plancheck.PlanCheck{ 48 | plancheck.ExpectUnknownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes")), 49 | }, 50 | }, 51 | ConfigStateChecks: []statecheck.StateCheck{ 52 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("required_dynamic"), knownvalue.StringExact("new value")), 53 | // After update, it's a number! 54 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes"), knownvalue.Int64Exact(200)), 55 | }, 56 | }, 57 | }, 58 | }) 59 | } 60 | -------------------------------------------------------------------------------- /internal/framework6provider/dynamic_computed_type_change_resource_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "testing" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 10 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 11 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 12 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 13 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 14 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 15 | "github.com/hashicorp/terraform-plugin-testing/tfjsonpath" 16 | ) 17 | 18 | // Ref: https://github.com/hashicorp/terraform-plugin-framework/issues/969 19 | // This test confirms that dynamic computed attributes are marked as unknown, both value AND type. 20 | // Dynamic computed attributes can change the type after plan in this scenario. 21 | func TestDynamicComputedTypeChange(t *testing.T) { 22 | resource.UnitTest(t, resource.TestCase{ 23 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 24 | "framework": providerserver.NewProtocol6WithError(New()), 25 | }, 26 | Steps: []resource.TestStep{ 27 | { 28 | Config: `resource "framework_dynamic_computed_type_change" "test" { 29 | required_dynamic = "value1" 30 | }`, 31 | ConfigPlanChecks: resource.ConfigPlanChecks{ 32 | PreApply: []plancheck.PlanCheck{ 33 | plancheck.ExpectUnknownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes")), 34 | }, 35 | }, 36 | ConfigStateChecks: []statecheck.StateCheck{ 37 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("required_dynamic"), knownvalue.StringExact("value1")), 38 | // Created as a boolean 39 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes"), knownvalue.Bool(true)), 40 | }, 41 | }, 42 | { 43 | Config: `resource "framework_dynamic_computed_type_change" "test" { 44 | required_dynamic = "new value" 45 | }`, 46 | ConfigPlanChecks: resource.ConfigPlanChecks{ 47 | PreApply: []plancheck.PlanCheck{ 48 | plancheck.ExpectUnknownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes")), 49 | }, 50 | }, 51 | ConfigStateChecks: []statecheck.StateCheck{ 52 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("required_dynamic"), knownvalue.StringExact("new value")), 53 | // After update, it's a number! 54 | statecheck.ExpectKnownValue("framework_dynamic_computed_type_change.test", tfjsonpath.New("computed_dynamic_type_changes"), knownvalue.Int64Exact(200)), 55 | }, 56 | }, 57 | }, 58 | }) 59 | } 60 | -------------------------------------------------------------------------------- /internal/framework5provider/writeonly_import_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/resource" 10 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ resource.Resource = WriteOnlyImportResource{} 15 | var _ resource.ResourceWithImportState = WriteOnlyImportResource{} 16 | 17 | func NewWriteOnlyImportResource() resource.Resource { 18 | return &WriteOnlyImportResource{} 19 | } 20 | 21 | type WriteOnlyImportResource struct{} 22 | 23 | func (r WriteOnlyImportResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_writeonly_import" 25 | } 26 | 27 | func (r WriteOnlyImportResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Attributes: map[string]schema.Attribute{ 30 | "string_attr": schema.StringAttribute{ 31 | Required: true, 32 | }, 33 | "writeonly_string": schema.StringAttribute{ 34 | Optional: true, 35 | WriteOnly: true, 36 | }, 37 | }, 38 | } 39 | } 40 | 41 | func (r WriteOnlyImportResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 42 | var config WriteOnlyImportResourceModel 43 | resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) 44 | if resp.Diagnostics.HasError() { 45 | return 46 | } 47 | 48 | resp.Diagnostics.Append(resp.State.Set(ctx, &config)...) 49 | } 50 | 51 | func (r WriteOnlyImportResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 52 | var data WriteOnlyImportResourceModel 53 | 54 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 55 | if resp.Diagnostics.HasError() { 56 | return 57 | } 58 | 59 | data.StringAttr = types.StringValue("hello world!") 60 | 61 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 62 | } 63 | 64 | func (r WriteOnlyImportResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 65 | } 66 | 67 | func (r WriteOnlyImportResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 68 | } 69 | 70 | func (r WriteOnlyImportResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { 71 | 72 | resp.Diagnostics.Append(resp.State.Set( 73 | ctx, 74 | WriteOnlyUpgradeResourceModel{ 75 | StringAttr: types.StringValue("hello world!"), 76 | WriteOnlyString: types.StringValue("this shouldn't cause an error"), 77 | }, 78 | )...) 79 | } 80 | 81 | type WriteOnlyImportResourceModel struct { 82 | StringAttr types.String `tfsdk:"string_attr"` 83 | WriteOnlyString types.String `tfsdk:"writeonly_string"` 84 | } 85 | -------------------------------------------------------------------------------- /internal/framework6provider/writeonly_import_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/resource" 10 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ resource.Resource = WriteOnlyImportResource{} 15 | var _ resource.ResourceWithImportState = WriteOnlyImportResource{} 16 | 17 | func NewWriteOnlyImportResource() resource.Resource { 18 | return &WriteOnlyImportResource{} 19 | } 20 | 21 | type WriteOnlyImportResource struct{} 22 | 23 | func (r WriteOnlyImportResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_writeonly_import" 25 | } 26 | 27 | func (r WriteOnlyImportResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Attributes: map[string]schema.Attribute{ 30 | "string_attr": schema.StringAttribute{ 31 | Required: true, 32 | }, 33 | "writeonly_string": schema.StringAttribute{ 34 | Optional: true, 35 | WriteOnly: true, 36 | }, 37 | }, 38 | } 39 | } 40 | 41 | func (r WriteOnlyImportResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 42 | var config WriteOnlyImportResourceModel 43 | resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) 44 | if resp.Diagnostics.HasError() { 45 | return 46 | } 47 | 48 | resp.Diagnostics.Append(resp.State.Set(ctx, &config)...) 49 | } 50 | 51 | func (r WriteOnlyImportResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 52 | var data WriteOnlyImportResourceModel 53 | 54 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 55 | if resp.Diagnostics.HasError() { 56 | return 57 | } 58 | 59 | data.StringAttr = types.StringValue("hello world!") 60 | 61 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 62 | } 63 | 64 | func (r WriteOnlyImportResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 65 | } 66 | 67 | func (r WriteOnlyImportResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 68 | } 69 | 70 | func (r WriteOnlyImportResource) ImportState(ctx context.Context, req resource.ImportStateRequest, resp *resource.ImportStateResponse) { 71 | 72 | resp.Diagnostics.Append(resp.State.Set( 73 | ctx, 74 | WriteOnlyUpgradeResourceModel{ 75 | StringAttr: types.StringValue("hello world!"), 76 | WriteOnlyString: types.StringValue("this shouldn't cause an error"), 77 | }, 78 | )...) 79 | } 80 | 81 | type WriteOnlyImportResourceModel struct { 82 | StringAttr types.String `tfsdk:"string_attr"` 83 | WriteOnlyString types.String `tfsdk:"writeonly_string"` 84 | } 85 | -------------------------------------------------------------------------------- /internal/framework5provider/bool_function_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 12 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 13 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 14 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 15 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 16 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 17 | ) 18 | 19 | func TestBoolFunction_known(t *testing.T) { 20 | resource.UnitTest(t, resource.TestCase{ 21 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 22 | tfversion.SkipBelow(tfversion.Version1_8_0), 23 | }, 24 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 25 | "framework": providerserver.NewProtocol5WithError(New()), 26 | }, 27 | Steps: []resource.TestStep{ 28 | { 29 | Config: ` 30 | output "test" { 31 | value = provider::framework::bool(true) 32 | }`, 33 | ConfigStateChecks: []statecheck.StateCheck{ 34 | statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), 35 | }, 36 | }, 37 | }, 38 | }) 39 | } 40 | 41 | func TestBoolFunction_null(t *testing.T) { 42 | resource.UnitTest(t, resource.TestCase{ 43 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 44 | tfversion.SkipBelow(tfversion.Version1_8_0), 45 | }, 46 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 47 | "framework": providerserver.NewProtocol5WithError(New()), 48 | }, 49 | Steps: []resource.TestStep{ 50 | { 51 | Config: ` 52 | output "test" { 53 | value = provider::framework::bool(null) 54 | }`, 55 | ExpectError: regexp.MustCompile("Invalid function argument"), 56 | }, 57 | }, 58 | }) 59 | } 60 | 61 | func TestBoolFunction_unknown(t *testing.T) { 62 | resource.UnitTest(t, resource.TestCase{ 63 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 64 | tfversion.SkipBelow(tfversion.Version1_8_0), 65 | }, 66 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 67 | "framework": providerserver.NewProtocol5WithError(New()), 68 | }, 69 | Steps: []resource.TestStep{ 70 | { 71 | Config: ` 72 | resource "terraform_data" "test" { 73 | input = provider::framework::bool(true) 74 | } 75 | 76 | output "test" { 77 | value = terraform_data.test.output 78 | }`, 79 | ConfigPlanChecks: resource.ConfigPlanChecks{ 80 | PreApply: []plancheck.PlanCheck{ 81 | plancheck.ExpectUnknownOutputValue("test"), 82 | }, 83 | }, 84 | ConfigStateChecks: []statecheck.StateCheck{ 85 | statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), 86 | }, 87 | }, 88 | }, 89 | }) 90 | } 91 | -------------------------------------------------------------------------------- /internal/framework6provider/bool_function_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov6" 12 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 13 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 14 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 15 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 16 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 17 | ) 18 | 19 | func TestBoolFunction_known(t *testing.T) { 20 | resource.UnitTest(t, resource.TestCase{ 21 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 22 | tfversion.SkipBelow(tfversion.Version1_8_0), 23 | }, 24 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 25 | "framework": providerserver.NewProtocol6WithError(New()), 26 | }, 27 | Steps: []resource.TestStep{ 28 | { 29 | Config: ` 30 | output "test" { 31 | value = provider::framework::bool(true) 32 | }`, 33 | ConfigStateChecks: []statecheck.StateCheck{ 34 | statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), 35 | }, 36 | }, 37 | }, 38 | }) 39 | } 40 | 41 | func TestBoolFunction_null(t *testing.T) { 42 | resource.UnitTest(t, resource.TestCase{ 43 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 44 | tfversion.SkipBelow(tfversion.Version1_8_0), 45 | }, 46 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 47 | "framework": providerserver.NewProtocol6WithError(New()), 48 | }, 49 | Steps: []resource.TestStep{ 50 | { 51 | Config: ` 52 | output "test" { 53 | value = provider::framework::bool(null) 54 | }`, 55 | ExpectError: regexp.MustCompile("Invalid function argument"), 56 | }, 57 | }, 58 | }) 59 | } 60 | 61 | func TestBoolFunction_unknown(t *testing.T) { 62 | resource.UnitTest(t, resource.TestCase{ 63 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 64 | tfversion.SkipBelow(tfversion.Version1_8_0), 65 | }, 66 | ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ 67 | "framework": providerserver.NewProtocol6WithError(New()), 68 | }, 69 | Steps: []resource.TestStep{ 70 | { 71 | Config: ` 72 | resource "terraform_data" "test" { 73 | input = provider::framework::bool(true) 74 | } 75 | 76 | output "test" { 77 | value = terraform_data.test.output 78 | }`, 79 | ConfigPlanChecks: resource.ConfigPlanChecks{ 80 | PreApply: []plancheck.PlanCheck{ 81 | plancheck.ExpectUnknownOutputValue("test"), 82 | }, 83 | }, 84 | ConfigStateChecks: []statecheck.StateCheck{ 85 | statecheck.ExpectKnownOutputValue("test", knownvalue.Bool(true)), 86 | }, 87 | }, 88 | }, 89 | }) 90 | } 91 | -------------------------------------------------------------------------------- /internal/framework5provider/writeonly_move_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/resource" 10 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ resource.Resource = WriteOnlyMoveResource{} 15 | var _ resource.ResourceWithMoveState = WriteOnlyMoveResource{} 16 | 17 | func NewWriteOnlyMoveResource() resource.Resource { 18 | return &WriteOnlyMoveResource{} 19 | } 20 | 21 | type WriteOnlyMoveResource struct{} 22 | 23 | func (r WriteOnlyMoveResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_writeonly_move" 25 | } 26 | 27 | func (r WriteOnlyMoveResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Attributes: map[string]schema.Attribute{ 30 | "string_attr": schema.StringAttribute{ 31 | Required: true, 32 | }, 33 | "writeonly_string": schema.StringAttribute{ 34 | Optional: true, 35 | WriteOnly: true, 36 | }, 37 | }, 38 | } 39 | } 40 | 41 | func (r WriteOnlyMoveResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 42 | var config WriteOnlyMoveResourceModel 43 | resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) 44 | if resp.Diagnostics.HasError() { 45 | return 46 | } 47 | 48 | resp.Diagnostics.Append(resp.State.Set(ctx, &config)...) 49 | } 50 | 51 | func (r WriteOnlyMoveResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 52 | var data WriteOnlyMoveResourceModel 53 | 54 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 55 | if resp.Diagnostics.HasError() { 56 | return 57 | } 58 | 59 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 60 | } 61 | 62 | func (r WriteOnlyMoveResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 63 | } 64 | 65 | func (r WriteOnlyMoveResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 66 | } 67 | 68 | func (r WriteOnlyMoveResource) MoveState(ctx context.Context) []resource.StateMover { 69 | return []resource.StateMover{ 70 | { 71 | StateMover: func(ctx context.Context, req resource.MoveStateRequest, resp *resource.MoveStateResponse) { 72 | resp.Diagnostics.Append(resp.TargetState.Set(ctx, WriteOnlyMoveResourceModel{ 73 | StringAttr: types.StringValue("hello world!"), 74 | WriteOnlyString: types.StringValue("this shouldn't cause an error"), 75 | })...) 76 | }, 77 | }, 78 | } 79 | } 80 | 81 | type WriteOnlyMoveResourceModel struct { 82 | StringAttr types.String `tfsdk:"string_attr"` 83 | WriteOnlyString types.String `tfsdk:"writeonly_string"` 84 | } 85 | -------------------------------------------------------------------------------- /internal/framework6provider/writeonly_move_resource.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "context" 8 | 9 | "github.com/hashicorp/terraform-plugin-framework/resource" 10 | "github.com/hashicorp/terraform-plugin-framework/resource/schema" 11 | "github.com/hashicorp/terraform-plugin-framework/types" 12 | ) 13 | 14 | var _ resource.Resource = WriteOnlyMoveResource{} 15 | var _ resource.ResourceWithMoveState = WriteOnlyMoveResource{} 16 | 17 | func NewWriteOnlyMoveResource() resource.Resource { 18 | return &WriteOnlyMoveResource{} 19 | } 20 | 21 | type WriteOnlyMoveResource struct{} 22 | 23 | func (r WriteOnlyMoveResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) { 24 | resp.TypeName = req.ProviderTypeName + "_writeonly_move" 25 | } 26 | 27 | func (r WriteOnlyMoveResource) Schema(_ context.Context, _ resource.SchemaRequest, resp *resource.SchemaResponse) { 28 | resp.Schema = schema.Schema{ 29 | Attributes: map[string]schema.Attribute{ 30 | "string_attr": schema.StringAttribute{ 31 | Required: true, 32 | }, 33 | "writeonly_string": schema.StringAttribute{ 34 | Optional: true, 35 | WriteOnly: true, 36 | }, 37 | }, 38 | } 39 | } 40 | 41 | func (r WriteOnlyMoveResource) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) { 42 | var config WriteOnlyMoveResourceModel 43 | resp.Diagnostics.Append(req.Config.Get(ctx, &config)...) 44 | if resp.Diagnostics.HasError() { 45 | return 46 | } 47 | 48 | resp.Diagnostics.Append(resp.State.Set(ctx, &config)...) 49 | } 50 | 51 | func (r WriteOnlyMoveResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) { 52 | var data WriteOnlyMoveResourceModel 53 | 54 | resp.Diagnostics.Append(req.State.Get(ctx, &data)...) 55 | if resp.Diagnostics.HasError() { 56 | return 57 | } 58 | 59 | resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) 60 | } 61 | 62 | func (r WriteOnlyMoveResource) Update(ctx context.Context, req resource.UpdateRequest, resp *resource.UpdateResponse) { 63 | } 64 | 65 | func (r WriteOnlyMoveResource) Delete(ctx context.Context, req resource.DeleteRequest, resp *resource.DeleteResponse) { 66 | } 67 | 68 | func (r WriteOnlyMoveResource) MoveState(ctx context.Context) []resource.StateMover { 69 | return []resource.StateMover{ 70 | { 71 | StateMover: func(ctx context.Context, req resource.MoveStateRequest, resp *resource.MoveStateResponse) { 72 | resp.Diagnostics.Append(resp.TargetState.Set(ctx, WriteOnlyMoveResourceModel{ 73 | StringAttr: types.StringValue("hello world!"), 74 | WriteOnlyString: types.StringValue("this shouldn't cause an error"), 75 | })...) 76 | }, 77 | }, 78 | } 79 | } 80 | 81 | type WriteOnlyMoveResourceModel struct { 82 | StringAttr types.String `tfsdk:"string_attr"` 83 | WriteOnlyString types.String `tfsdk:"writeonly_string"` 84 | } 85 | -------------------------------------------------------------------------------- /internal/framework5provider/int32_function_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 12 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 13 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 14 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 15 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 16 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 17 | ) 18 | 19 | func TestInt32Function_known(t *testing.T) { 20 | resource.UnitTest(t, resource.TestCase{ 21 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 22 | tfversion.SkipBelow(tfversion.Version1_8_0), 23 | }, 24 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 25 | "framework": providerserver.NewProtocol5WithError(New()), 26 | }, 27 | Steps: []resource.TestStep{ 28 | { 29 | Config: ` 30 | output "test" { 31 | value = provider::framework::int32(123) 32 | }`, 33 | ConfigStateChecks: []statecheck.StateCheck{ 34 | statecheck.ExpectKnownOutputValue("test", knownvalue.Int32Exact(123)), 35 | }, 36 | }, 37 | }, 38 | }) 39 | } 40 | 41 | func TestInt32Function_null(t *testing.T) { 42 | resource.UnitTest(t, resource.TestCase{ 43 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 44 | tfversion.SkipBelow(tfversion.Version1_8_0), 45 | }, 46 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 47 | "framework": providerserver.NewProtocol5WithError(New()), 48 | }, 49 | Steps: []resource.TestStep{ 50 | { 51 | Config: ` 52 | output "test" { 53 | value = provider::framework::int32(null) 54 | }`, 55 | ExpectError: regexp.MustCompile("Invalid function argument"), 56 | }, 57 | }, 58 | }) 59 | } 60 | 61 | func TestInt32Function_unknown(t *testing.T) { 62 | resource.UnitTest(t, resource.TestCase{ 63 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 64 | tfversion.SkipBelow(tfversion.Version1_8_0), 65 | }, 66 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 67 | "framework": providerserver.NewProtocol5WithError(New()), 68 | }, 69 | Steps: []resource.TestStep{ 70 | { 71 | Config: ` 72 | resource "terraform_data" "test" { 73 | input = provider::framework::int32(123) 74 | } 75 | 76 | output "test" { 77 | value = terraform_data.test.output 78 | }`, 79 | ConfigPlanChecks: resource.ConfigPlanChecks{ 80 | PreApply: []plancheck.PlanCheck{ 81 | plancheck.ExpectUnknownOutputValue("test"), 82 | }, 83 | }, 84 | ConfigStateChecks: []statecheck.StateCheck{ 85 | statecheck.ExpectKnownOutputValue("test", knownvalue.Int32Exact(123)), 86 | }, 87 | }, 88 | }, 89 | }) 90 | } 91 | -------------------------------------------------------------------------------- /internal/framework5provider/int64_function_test.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package framework 5 | 6 | import ( 7 | "regexp" 8 | "testing" 9 | 10 | "github.com/hashicorp/terraform-plugin-framework/providerserver" 11 | "github.com/hashicorp/terraform-plugin-go/tfprotov5" 12 | "github.com/hashicorp/terraform-plugin-testing/helper/resource" 13 | "github.com/hashicorp/terraform-plugin-testing/knownvalue" 14 | "github.com/hashicorp/terraform-plugin-testing/plancheck" 15 | "github.com/hashicorp/terraform-plugin-testing/statecheck" 16 | "github.com/hashicorp/terraform-plugin-testing/tfversion" 17 | ) 18 | 19 | func TestInt64Function_known(t *testing.T) { 20 | resource.UnitTest(t, resource.TestCase{ 21 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 22 | tfversion.SkipBelow(tfversion.Version1_8_0), 23 | }, 24 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 25 | "framework": providerserver.NewProtocol5WithError(New()), 26 | }, 27 | Steps: []resource.TestStep{ 28 | { 29 | Config: ` 30 | output "test" { 31 | value = provider::framework::int64(123) 32 | }`, 33 | ConfigStateChecks: []statecheck.StateCheck{ 34 | statecheck.ExpectKnownOutputValue("test", knownvalue.Int64Exact(123)), 35 | }, 36 | }, 37 | }, 38 | }) 39 | } 40 | 41 | func TestInt64Function_null(t *testing.T) { 42 | resource.UnitTest(t, resource.TestCase{ 43 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 44 | tfversion.SkipBelow(tfversion.Version1_8_0), 45 | }, 46 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 47 | "framework": providerserver.NewProtocol5WithError(New()), 48 | }, 49 | Steps: []resource.TestStep{ 50 | { 51 | Config: ` 52 | output "test" { 53 | value = provider::framework::int64(null) 54 | }`, 55 | ExpectError: regexp.MustCompile("Invalid function argument"), 56 | }, 57 | }, 58 | }) 59 | } 60 | 61 | func TestInt64Function_unknown(t *testing.T) { 62 | resource.UnitTest(t, resource.TestCase{ 63 | TerraformVersionChecks: []tfversion.TerraformVersionCheck{ 64 | tfversion.SkipBelow(tfversion.Version1_8_0), 65 | }, 66 | ProtoV5ProviderFactories: map[string]func() (tfprotov5.ProviderServer, error){ 67 | "framework": providerserver.NewProtocol5WithError(New()), 68 | }, 69 | Steps: []resource.TestStep{ 70 | { 71 | Config: ` 72 | resource "terraform_data" "test" { 73 | input = provider::framework::int64(123) 74 | } 75 | 76 | output "test" { 77 | value = terraform_data.test.output 78 | }`, 79 | ConfigPlanChecks: resource.ConfigPlanChecks{ 80 | PreApply: []plancheck.PlanCheck{ 81 | plancheck.ExpectUnknownOutputValue("test"), 82 | }, 83 | }, 84 | ConfigStateChecks: []statecheck.StateCheck{ 85 | statecheck.ExpectKnownOutputValue("test", knownvalue.Int64Exact(123)), 86 | }, 87 | }, 88 | }, 89 | }) 90 | } 91 | --------------------------------------------------------------------------------