Skip to content

Commit c7ab8a5

Browse files
committed
add failing test
1 parent e801590 commit c7ab8a5

File tree

2 files changed

+148
-0
lines changed

2 files changed

+148
-0
lines changed

helper/resource/importstate/examplecloud_test.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,3 +479,120 @@ func examplecloudResourceWithEveryIdentitySchemaType() testprovider.Resource {
479479
},
480480
}
481481
}
482+
483+
func examplecloudResourceWithNullIdentityAttr() testprovider.Resource {
484+
return testprovider.Resource{
485+
CreateResponse: &resource.CreateResponse{
486+
NewState: tftypes.NewValue(
487+
tftypes.Object{
488+
AttributeTypes: map[string]tftypes.Type{
489+
"id": tftypes.String,
490+
"location": tftypes.String,
491+
"name": tftypes.String,
492+
},
493+
},
494+
map[string]tftypes.Value{
495+
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
496+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
497+
"name": tftypes.NewValue(tftypes.String, "somevalue"),
498+
},
499+
),
500+
NewIdentity: teststep.Pointer(tftypes.NewValue(
501+
tftypes.Object{
502+
AttributeTypes: map[string]tftypes.Type{
503+
"id": tftypes.String,
504+
"value_we_dont_always_need": tftypes.String,
505+
},
506+
},
507+
map[string]tftypes.Value{
508+
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
509+
"value_we_dont_always_need": tftypes.NewValue(tftypes.String, nil),
510+
},
511+
)),
512+
},
513+
ReadResponse: &resource.ReadResponse{
514+
NewState: tftypes.NewValue(
515+
tftypes.Object{
516+
AttributeTypes: map[string]tftypes.Type{
517+
"id": tftypes.String,
518+
"location": tftypes.String,
519+
"name": tftypes.String,
520+
},
521+
},
522+
map[string]tftypes.Value{
523+
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
524+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
525+
"name": tftypes.NewValue(tftypes.String, "somevalue"),
526+
},
527+
),
528+
NewIdentity: teststep.Pointer(tftypes.NewValue(
529+
tftypes.Object{
530+
AttributeTypes: map[string]tftypes.Type{
531+
"id": tftypes.String,
532+
"value_we_dont_always_need": tftypes.String,
533+
},
534+
},
535+
map[string]tftypes.Value{
536+
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
537+
"value_we_dont_always_need": tftypes.NewValue(tftypes.String, nil),
538+
},
539+
)),
540+
},
541+
ImportStateResponse: &resource.ImportStateResponse{
542+
State: tftypes.NewValue(
543+
tftypes.Object{
544+
AttributeTypes: map[string]tftypes.Type{
545+
"id": tftypes.String,
546+
"location": tftypes.String,
547+
"name": tftypes.String,
548+
},
549+
},
550+
map[string]tftypes.Value{
551+
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
552+
"location": tftypes.NewValue(tftypes.String, "westeurope"),
553+
"name": tftypes.NewValue(tftypes.String, "somevalue"),
554+
},
555+
),
556+
Identity: teststep.Pointer(tftypes.NewValue(
557+
tftypes.Object{
558+
AttributeTypes: map[string]tftypes.Type{
559+
"id": tftypes.String,
560+
"value_we_dont_always_need": tftypes.String,
561+
},
562+
},
563+
map[string]tftypes.Value{
564+
"id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"),
565+
"value_we_dont_always_need": tftypes.NewValue(tftypes.String, nil),
566+
},
567+
)),
568+
},
569+
SchemaResponse: &resource.SchemaResponse{
570+
Schema: &tfprotov6.Schema{
571+
Block: &tfprotov6.SchemaBlock{
572+
Attributes: []*tfprotov6.SchemaAttribute{
573+
ComputedStringAttribute("id"),
574+
RequiredStringAttribute("location"),
575+
RequiredStringAttribute("name"),
576+
},
577+
},
578+
},
579+
},
580+
IdentitySchemaResponse: &resource.IdentitySchemaResponse{
581+
Schema: &tfprotov6.ResourceIdentitySchema{
582+
Version: 1,
583+
IdentityAttributes: []*tfprotov6.ResourceIdentitySchemaAttribute{
584+
{
585+
Name: "id",
586+
Type: tftypes.String,
587+
RequiredForImport: true,
588+
},
589+
{
590+
Name: "value_we_dont_always_need",
591+
Type: tftypes.String,
592+
OptionalForImport: true,
593+
},
594+
},
595+
},
596+
},
597+
}
598+
}

helper/resource/importstate/import_block_with_resource_identity_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,37 @@ func TestImportBlock_WithResourceIdentity(t *testing.T) {
4747
})
4848
}
4949

50+
func TestImportBlock_WithResourceIdentity_NullAttribute(t *testing.T) {
51+
t.Parallel()
52+
53+
r.UnitTest(t, r.TestCase{
54+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
55+
tfversion.SkipBelow(tfversion.Version1_12_0), // ImportBlockWithResourceIdentity requires Terraform 1.12.0 or later
56+
},
57+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
58+
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
59+
Resources: map[string]testprovider.Resource{
60+
"examplecloud_container": examplecloudResourceWithNullIdentityAttr(),
61+
},
62+
}),
63+
},
64+
Steps: []r.TestStep{
65+
{
66+
Config: `
67+
resource "examplecloud_container" "test" {
68+
location = "westeurope"
69+
name = "somevalue"
70+
}`,
71+
},
72+
{
73+
ResourceName: "examplecloud_container.test",
74+
ImportState: true,
75+
ImportStateKind: r.ImportBlockWithResourceIdentity,
76+
},
77+
},
78+
})
79+
}
80+
5081
func TestImportBlock_WithResourceIdentity_WithEveryType(t *testing.T) {
5182
t.Parallel()
5283

0 commit comments

Comments
 (0)