|
| 1 | +// Copyright (c) HashiCorp, Inc. |
| 2 | +// SPDX-License-Identifier: MPL-2.0 |
| 3 | + |
| 4 | +package resource |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/hashicorp/terraform-plugin-go/tfprotov6" |
| 10 | + "github.com/hashicorp/terraform-plugin-go/tftypes" |
| 11 | + |
| 12 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" |
| 13 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" |
| 14 | + "github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/resource" |
| 15 | + "github.com/hashicorp/terraform-plugin-testing/tfversion" |
| 16 | +) |
| 17 | + |
| 18 | +func TestTest_TestStep_ImportBlockId(t *testing.T) { |
| 19 | + t.Parallel() |
| 20 | + |
| 21 | + UnitTest(t, TestCase{ |
| 22 | + TerraformVersionChecks: []tfversion.TerraformVersionCheck{ |
| 23 | + tfversion.SkipBelow(tfversion.Version1_5_0), // ProtoV6ProviderFactories |
| 24 | + }, |
| 25 | + ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ |
| 26 | + "examplecloud": providerserver.NewProviderServer(testprovider.Provider{ |
| 27 | + Resources: map[string]testprovider.Resource{ |
| 28 | + "examplecloud_container": { |
| 29 | + CreateResponse: &resource.CreateResponse{ |
| 30 | + NewState: tftypes.NewValue( |
| 31 | + tftypes.Object{ |
| 32 | + AttributeTypes: map[string]tftypes.Type{ |
| 33 | + "id": tftypes.String, |
| 34 | + "location": tftypes.String, |
| 35 | + "name": tftypes.String, |
| 36 | + }, |
| 37 | + }, |
| 38 | + map[string]tftypes.Value{ |
| 39 | + "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), |
| 40 | + "location": tftypes.NewValue(tftypes.String, "westeurope"), |
| 41 | + "name": tftypes.NewValue(tftypes.String, "somevalue"), |
| 42 | + }, |
| 43 | + ), |
| 44 | + }, |
| 45 | + ImportStateResponse: &resource.ImportStateResponse{ |
| 46 | + State: tftypes.NewValue( |
| 47 | + tftypes.Object{ |
| 48 | + AttributeTypes: map[string]tftypes.Type{ |
| 49 | + "id": tftypes.String, |
| 50 | + "location": tftypes.String, |
| 51 | + "name": tftypes.String, |
| 52 | + }, |
| 53 | + }, |
| 54 | + map[string]tftypes.Value{ |
| 55 | + "id": tftypes.NewValue(tftypes.String, "westeurope/somevalue"), |
| 56 | + "location": tftypes.NewValue(tftypes.String, "westeurope"), |
| 57 | + "name": tftypes.NewValue(tftypes.String, "somevalue"), |
| 58 | + }, |
| 59 | + ), |
| 60 | + }, |
| 61 | + SchemaResponse: &resource.SchemaResponse{ |
| 62 | + Schema: &tfprotov6.Schema{ |
| 63 | + Block: &tfprotov6.SchemaBlock{ |
| 64 | + Attributes: []*tfprotov6.SchemaAttribute{ |
| 65 | + { |
| 66 | + Name: "id", |
| 67 | + Type: tftypes.String, |
| 68 | + Computed: true, |
| 69 | + }, |
| 70 | + { |
| 71 | + Name: "location", |
| 72 | + Type: tftypes.String, |
| 73 | + Required: true, |
| 74 | + }, |
| 75 | + { |
| 76 | + Name: "name", |
| 77 | + Type: tftypes.String, |
| 78 | + Required: true, |
| 79 | + }, |
| 80 | + }, |
| 81 | + }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + }, |
| 85 | + }, |
| 86 | + }), |
| 87 | + }, |
| 88 | + Steps: []TestStep{ |
| 89 | + { |
| 90 | + Config: ` |
| 91 | + resource "examplecloud_container" "test" { |
| 92 | + location = "westeurope" |
| 93 | + name = "somevalue" |
| 94 | + }`, |
| 95 | + }, |
| 96 | + { |
| 97 | + ResourceName: "examplecloud_container.test", |
| 98 | + ImportState: true, |
| 99 | + ImportStateKind: ImportBlockWithId, |
| 100 | + ImportStateVerify: true, |
| 101 | + }, |
| 102 | + }, |
| 103 | + }) |
| 104 | +} |
0 commit comments