forked from oracle/terraform-provider-oci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_source_obmcs_core_instances_test.go
116 lines (102 loc) · 3.75 KB
/
data_source_obmcs_core_instances_test.go
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
package main
import (
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
baremetal "github.com/oracle/bmcs-go-sdk"
"github.com/stretchr/testify/suite"
)
type DatasourceCoreInstanceTestSuite struct {
suite.Suite
Client *baremetal.Client
Config string
Provider terraform.ResourceProvider
Providers map[string]terraform.ResourceProvider
ResourceName string
Token string
TokenFn func(string, map[string]string) string
}
func (s *DatasourceCoreInstanceTestSuite) SetupTest() {
s.Token, s.TokenFn = tokenize()
s.Client = testAccClient
s.Provider = testAccProvider
s.Providers = testAccProviders
s.Config = testProviderConfig() + s.TokenFn(`
data "oci_identity_availability_domains" "ADs" {
compartment_id = "${var.compartment_id}"
}
resource "oci_core_virtual_network" "t" {
compartment_id = "${var.compartment_id}"
display_name = "-tf-vcn"
cidr_block = "10.0.0.0/16"
}
resource "oci_core_subnet" "t" {
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[0],"name")}"
compartment_id = "${var.compartment_id}"
vcn_id = "${oci_core_virtual_network.t.id}"
display_name = "-tf-subnet"
cidr_block = "10.0.1.0/24"
dhcp_options_id = "${oci_core_virtual_network.t.default_dhcp_options_id}"
route_table_id = "${oci_core_virtual_network.t.default_route_table_id}"
security_list_ids = ["${oci_core_virtual_network.t.default_security_list_id}"]
}
data "oci_core_images" "t" {
compartment_id = "${var.compartment_id}"
operating_system = "Oracle Linux"
operating_system_version = "7.3"
limit = 1
}
resource "oci_core_instance" "t" {
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
compartment_id = "${var.compartment_id}"
display_name = "{{.token}}"
subnet_id = "${oci_core_subnet.t.id}"
image = "${data.oci_core_images.t.images.0.id}"
shape = "VM.Standard1.1"
metadata {
ssh_authorized_keys = "${var.ssh_public_key}"
}
timeouts {
create = "15m"
}
}`, nil)
s.ResourceName = "data.oci_core_instances.t"
}
func (s *DatasourceCoreInstanceTestSuite) TestAccDatasourceCoreInstance_basic() {
resource.Test(s.T(), resource.TestCase{
PreventPostDestroyRefresh: true,
Providers: s.Providers,
Steps: []resource.TestStep{
{
ImportState: true,
ImportStateVerify: true,
Config: s.Config + s.TokenFn(`
data "oci_core_instances" "t" {
compartment_id = "${var.compartment_id}"
availability_domain = "${data.oci_identity_availability_domains.ADs.availability_domains.0.name}"
display_name = "{{.token}}"
filter {
name = "id"
values = ["${oci_core_instance.t.id}"]
}
}`, nil),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(s.ResourceName, "instances.#", "1"),
resource.TestCheckResourceAttr(s.ResourceName, "instances.0.display_name", s.Token),
resource.TestCheckResourceAttr(s.ResourceName, "instances.0.state", "RUNNING"),
resource.TestCheckResourceAttr(s.ResourceName, "instances.0.shape", "VM.Standard1.1"),
resource.TestCheckResourceAttrSet(s.ResourceName, "instances.0.availability_domain"),
resource.TestCheckResourceAttrSet(s.ResourceName, "instances.0.id"),
resource.TestCheckResourceAttrSet(s.ResourceName, "instances.0.region"),
resource.TestCheckResourceAttrSet(s.ResourceName, "instances.0.image"),
resource.TestCheckResourceAttrSet(s.ResourceName, "instances.0.metadata.%"),
),
},
},
},
)
}
func TestDatasourceCoreInstanceTestSuite(t *testing.T) {
suite.Run(t, new(DatasourceCoreInstanceTestSuite))
}