mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-15 19:22:46 -06:00
19d0b42911
Previously the consul_keys resource did double-duty as both a reader and writer of values from the Consul key/value store, but that made its interface rather confusing and complex, as well as having all of the other general problems associated with read-only resources. Here we split the functionality such that reading is done with the consul_keys data source while writing is done with the consul_keys resource. The old read behavior of the resource is still supported, but it's no longer documented (except as a deprecation note) and will generate deprecation warnings when used. In future it should be possible to simplify the consul_keys resource by removing all of the read support, but that is deferred for now to give users a chance to gracefully migrate to the new data source.
45 lines
934 B
Go
45 lines
934 B
Go
package consul
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
)
|
|
|
|
func TestAccDataConsulKeys_basic(t *testing.T) {
|
|
resource.Test(t, resource.TestCase{
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
Providers: testAccProviders,
|
|
Steps: []resource.TestStep{
|
|
resource.TestStep{
|
|
Config: testAccDataConsulKeysConfig,
|
|
Check: resource.ComposeTestCheckFunc(
|
|
testAccCheckConsulKeysValue("data.consul_keys.read", "read", "written"),
|
|
),
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
const testAccDataConsulKeysConfig = `
|
|
resource "consul_keys" "write" {
|
|
datacenter = "dc1"
|
|
|
|
key {
|
|
path = "test/data_source"
|
|
value = "written"
|
|
}
|
|
}
|
|
|
|
data "consul_keys" "read" {
|
|
# Create a dependency on the resource so we're sure to
|
|
# have the value in place before we try to read it.
|
|
datacenter = "${consul_keys.write.datacenter}"
|
|
|
|
key {
|
|
path = "test/data_source"
|
|
name = "read"
|
|
}
|
|
}
|
|
`
|