-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_source_openstack_compute_instance_v2_test.go
More file actions
73 lines (64 loc) · 1.91 KB
/
Copy pathdata_source_openstack_compute_instance_v2_test.go
File metadata and controls
73 lines (64 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package openstack
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccComputeV2InstanceDataSource(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
testAccPreCheckNonAdminOnly(t)
},
ProviderFactories: testAccProviders,
Steps: []resource.TestStep{
{
Config: testAccComputeV2InstanceDataSourceBasic(),
},
{
Config: testAccComputeV2InstanceDataSourceSource(),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeInstanceV2DataSourceID("data.openstack_compute_instance_v2.source_1"),
resource.TestCheckResourceAttr("data.openstack_compute_instance_v2.source_1", "name", "instance_1"),
resource.TestCheckResourceAttrPair("data.openstack_compute_instance_v2.source_1", "metadata", "openstack_compute_instance_v2.instance_1", "metadata"),
resource.TestCheckResourceAttrSet("data.openstack_compute_instance_v2.source_1", "network.0.name"),
),
},
},
})
}
func testAccCheckComputeInstanceV2DataSourceID(n string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Can't find compute instance data source: %s", n)
}
if rs.Primary.ID == "" {
return fmt.Errorf("Compute instance data source ID not set")
}
return nil
}
}
func testAccComputeV2InstanceDataSourceBasic() string {
return fmt.Sprintf(`
resource "openstack_compute_instance_v2" "instance_1" {
name = "instance_1"
security_groups = ["default"]
metadata = {
foo = "bar"
}
network {
uuid = "%s"
}
}
`, osNetworkID)
}
func testAccComputeV2InstanceDataSourceSource() string {
return fmt.Sprintf(`
%s
data "openstack_compute_instance_v2" "source_1" {
id = "${openstack_compute_instance_v2.instance_1.id}"
}
`, testAccComputeV2InstanceDataSourceBasic())
}