@ -20,6 +20,10 @@ import (
"github.com/hashicorp/terraform/internal/terraform"
)
func ptrOf [ T any ] ( v T ) * T {
return & v
}
func TestMarshalOutputs ( t * testing . T ) {
tests := [ ] struct {
Outputs map [ string ] * states . OutputValue
@ -620,6 +624,115 @@ func TestMarshalResources(t *testing.T) {
} ,
false ,
} ,
"single resource with identity" : {
map [ string ] * states . Resource {
"test_identity.bar" : {
Addr : addrs . AbsResource {
Resource : addrs . Resource {
Mode : addrs . ManagedResourceMode ,
Type : "test_identity" ,
Name : "bar" ,
} ,
} ,
Instances : map [ addrs . InstanceKey ] * states . ResourceInstance {
addrs . NoKey : {
Current : & states . ResourceInstanceObjectSrc {
Status : states . ObjectReady ,
AttrsJSON : [ ] byte ( ` { "woozles":"confuzles","foozles":"sensuzles","name":"bar"} ` ) ,
IdentityJSON : [ ] byte ( ` { "foozles":"sensuzles","name":"bar"} ` ) ,
} ,
} ,
} ,
ProviderConfig : addrs . AbsProviderConfig {
Provider : addrs . NewDefaultProvider ( "test" ) ,
Module : addrs . RootModule ,
} ,
} ,
} ,
testSchemas ( ) ,
[ ] Resource {
{
Address : "test_identity.bar" ,
Mode : "managed" ,
Type : "test_identity" ,
Name : "bar" ,
Index : nil ,
ProviderName : "registry.terraform.io/hashicorp/test" ,
AttributeValues : AttributeValues {
"name" : json . RawMessage ( ` "bar" ` ) ,
"foozles" : json . RawMessage ( ` "sensuzles" ` ) ,
"woozles" : json . RawMessage ( ` "confuzles" ` ) ,
} ,
SensitiveValues : json . RawMessage ( "{\"foozles\":true}" ) ,
IdentityValues : IdentityValues {
"name" : json . RawMessage ( ` "bar" ` ) ,
"foozles" : json . RawMessage ( ` "sensuzles" ` ) ,
} ,
IdentitySchemaVersion : ptrOf [ uint64 ] ( 0 ) ,
} ,
} ,
false ,
} ,
"single resource wrong identity schema" : {
map [ string ] * states . Resource {
"test_identity.bar" : {
Addr : addrs . AbsResource {
Resource : addrs . Resource {
Mode : addrs . ManagedResourceMode ,
Type : "test_identity" ,
Name : "bar" ,
} ,
} ,
Instances : map [ addrs . InstanceKey ] * states . ResourceInstance {
addrs . NoKey : {
Current : & states . ResourceInstanceObjectSrc {
Status : states . ObjectReady ,
AttrsJSON : [ ] byte ( ` { "woozles":"confuzles","foozles":"sensuzles","name":"bar"} ` ) ,
IdentitySchemaVersion : 1 ,
IdentityJSON : [ ] byte ( ` { "foozles":"sensuzles","name":"bar"} ` ) ,
} ,
} ,
} ,
ProviderConfig : addrs . AbsProviderConfig {
Provider : addrs . NewDefaultProvider ( "test" ) ,
Module : addrs . RootModule ,
} ,
} ,
} ,
testSchemas ( ) ,
nil ,
true ,
} ,
"single resource missing identity schema" : {
map [ string ] * states . Resource {
"test_thing.bar" : {
Addr : addrs . AbsResource {
Resource : addrs . Resource {
Mode : addrs . ManagedResourceMode ,
Type : "test_thing" ,
Name : "bar" ,
} ,
} ,
Instances : map [ addrs . InstanceKey ] * states . ResourceInstance {
addrs . NoKey : {
Current : & states . ResourceInstanceObjectSrc {
Status : states . ObjectReady ,
AttrsJSON : [ ] byte ( ` { "woozles":"confuzles","foozles":"sensuzles"} ` ) ,
IdentitySchemaVersion : 0 ,
IdentityJSON : [ ] byte ( ` { "foozles":"sensuzles","name":"bar"} ` ) ,
} ,
} ,
} ,
ProviderConfig : addrs . AbsProviderConfig {
Provider : addrs . NewDefaultProvider ( "test" ) ,
Module : addrs . RootModule ,
} ,
} ,
} ,
testSchemas ( ) ,
nil ,
true ,
} ,
}
for name , test := range tests {
@ -867,6 +980,22 @@ func testSchemas() *terraform.Schemas {
} ,
} ,
} ,
"test_identity" : {
Body : & configschema . Block {
Attributes : map [ string ] * configschema . Attribute {
"name" : { Type : cty . String , Required : true } ,
"woozles" : { Type : cty . String , Optional : true , Computed : true } ,
"foozles" : { Type : cty . String , Optional : true , Sensitive : true } ,
} ,
} ,
Identity : & configschema . Object {
Attributes : map [ string ] * configschema . Attribute {
"name" : { Type : cty . String , Required : true } ,
"foozles" : { Type : cty . String , Optional : true } ,
} ,
Nesting : configschema . NestingSingle ,
} ,
} ,
} ,
} ,
} ,