terraform-provider-dokploy/internal/provider/example_ephemeral_resource_test.go
Bruno Schaatsbergen 3cdbd2dca9
add ephemeral example resource (#264)
* eph: add ephemeral resource

Adds a new example ephemeral resource using a required configurable attribute and an example ID.

* tools: bump terraform-plugin-docs

Bump to the latest stable release, as it includes support for ephemeral resource documentation generation.

* docs: add ephemeral resource documentation

* provider: register new example ephemeral resource

* eph: improve alphabetical ordering of struct fields

* eph: use a computed 'value' attribute

To help provider developers easily understand the concept of ephemeral resources, we use a 'value' attribute in the schema, which is set to an example token (token-123).

* docs: update ephemeral resource docs

* provider: create a separate echo provider factory container

Since not every acceptance test requires an ephemeral provider server for the CLI to connect to and interact with, this introduces a separate provider factory container that includes the echo provider.

* eph: add basic acceptance test for ephemeral resource

* docs: rename ephemeral resource configuration file

* eph: improve http response diag
2025-01-13 10:17:03 -05:00

49 lines
1.4 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package provider
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
"github.com/hashicorp/terraform-plugin-testing/statecheck"
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
"github.com/hashicorp/terraform-plugin-testing/tfversion"
)
func TestAccExampleEphemeralResource(t *testing.T) {
resource.Test(t, resource.TestCase{
// Ephemeral resources are only available in 1.10 and later
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
tfversion.SkipBelow(tfversion.Version1_10_0),
},
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactoriesWithEcho,
Steps: []resource.TestStep{
{
Config: testAccExampleEphemeralResourceConfig("example"),
ConfigStateChecks: []statecheck.StateCheck{
statecheck.ExpectKnownValue("echo.test", tfjsonpath.New("data").AtMapKey("value"), knownvalue.StringExact("token-123")),
},
},
},
})
}
func testAccExampleEphemeralResourceConfig(configurableAttribute string) string {
return fmt.Sprintf(`
ephemeral "scaffolding_example" "test" {
configurable_attribute = %[1]q
}
provider "echo" {
data = ephemeral.scaffolding_example.test
}
resource "echo" "test" {}
`, configurableAttribute)
}