Skip to content

Commit a644554

Browse files
committed
support for dedicated VM hosts
1 parent f4b7cd0 commit a644554

28 files changed

+2210
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
###Added
44
- Add `resource_group` optional field for metrics
5+
- Support for dedicated virtual machine hosts
56

67
## 3.39.0 (August 21, 2019)
78

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
3+
variable "tenancy_ocid" {}
4+
variable "user_ocid" {}
5+
variable "fingerprint" {}
6+
variable "private_key_path" {}
7+
variable "region" {}
8+
variable "compartment_ocid" {}
9+
10+
variable "instance_image_ocid" {
11+
type = "map"
12+
13+
default = {
14+
# See https://docs.us-phoenix-1.oraclecloud.com/images/
15+
# Oracle-provided image "Oracle-Linux-7.5-2018.10.16-0"
16+
us-phoenix-1 = "ocid1.image.oc1.phx.aaaaaaaaoqj42sokaoh42l76wsyhn3k2beuntrh5maj3gmgmzeyr55zzrwwa"
17+
18+
us-ashburn-1 = "ocid1.image.oc1.iad.aaaaaaaageeenzyuxgia726xur4ztaoxbxyjlxogdhreu3ngfj2gji3bayda"
19+
eu-frankfurt-1 = "ocid1.image.oc1.eu-frankfurt-1.aaaaaaaaitzn6tdyjer7jl34h2ujz74jwy5nkbukbh55ekp6oyzwrtfa4zma"
20+
uk-london-1 = "ocid1.image.oc1.uk-london-1.aaaaaaaa32voyikkkzfxyo4xbdmadc2dmvorfxxgdhpnk6dw64fa3l4jh7wa"
21+
}
22+
}
23+
24+
provider "oci" {
25+
tenancy_ocid = "${var.tenancy_ocid}"
26+
user_ocid = "${var.user_ocid}"
27+
fingerprint = "${var.fingerprint}"
28+
private_key_path = "${var.private_key_path}"
29+
region = "${var.region}"
30+
}
31+
32+
data "oci_identity_availability_domain" "ad" {
33+
compartment_id = "${var.tenancy_ocid}"
34+
ad_number = 1
35+
}
36+
37+
resource "oci_core_dedicated_vm_host" "test_dedicated_vm_host" {
38+
#Required
39+
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
40+
compartment_id = "${var.compartment_ocid}"
41+
dedicated_vm_host_shape = "DVH.Standard2.52"
42+
43+
#Optional
44+
#defined_tags = "${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "${var.dedicated_vm_host_defined_tags_value}")}"
45+
#freeform_tags = "${var.dedicated_vm_host_freeform_tags}"
46+
display_name = "TestDedicatedVmHost"
47+
}
48+
49+
# instance using dedicated vm host
50+
resource "oci_core_instance" "test_instance" {
51+
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
52+
compartment_id = "${var.compartment_ocid}"
53+
display_name = "TestInstance"
54+
shape = "VM.Standard2.1"
55+
56+
create_vnic_details {
57+
subnet_id = "${oci_core_subnet.test_subnet.id}"
58+
display_name = "Primaryvnic"
59+
assign_public_ip = true
60+
hostname_label = "TestInstanceLabel"
61+
}
62+
63+
dedicated_vm_host_id = "${oci_core_dedicated_vm_host.test_dedicated_vm_host.id}"
64+
65+
source_details {
66+
source_type = "image"
67+
source_id = "${var.instance_image_ocid[var.region]}"
68+
69+
# Apply this to set the size of the boot volume that's created for this instance.
70+
# Otherwise, the default boot volume size of the image is used.
71+
# This should only be specified when source_type is set to "image".
72+
#boot_volume_size_in_gbs = "60"
73+
}
74+
75+
timeouts {
76+
create = "60m"
77+
}
78+
}
79+
80+
resource "oci_core_vcn" "test_vcn" {
81+
cidr_block = "10.1.0.0/16"
82+
compartment_id = "${var.compartment_ocid}"
83+
display_name = "TestVcn"
84+
dns_label = "testvcn"
85+
}
86+
87+
resource "oci_core_subnet" "test_subnet" {
88+
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
89+
cidr_block = "10.1.20.0/24"
90+
display_name = "TestSubnet"
91+
dns_label = "testsubnet"
92+
security_list_ids = ["${oci_core_vcn.test_vcn.default_security_list_id}"]
93+
compartment_id = "${var.compartment_ocid}"
94+
vcn_id = "${oci_core_vcn.test_vcn.id}"
95+
route_table_id = "${oci_core_vcn.test_vcn.default_route_table_id}"
96+
dhcp_options_id = "${oci_core_vcn.test_vcn.default_dhcp_options_id}"
97+
}
98+
99+
data "oci_core_dedicated_vm_hosts" "test_dedicated_vm_hosts" {
100+
#Required
101+
compartment_id = "${var.compartment_ocid}"
102+
103+
#Optional
104+
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
105+
display_name = "TestDedicatedVmHost"
106+
instance_shape_name = "VM.Standard2.1"
107+
state = "ACTIVE"
108+
}
109+
110+
data "oci_core_dedicated_vm_host_instance_shapes" "test_dedicated_vm_host_instance_shapes" {
111+
#Required
112+
compartment_id = "${var.compartment_ocid}"
113+
114+
#Optional
115+
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
116+
dedicated_vm_host_shape = "DVH.Standard2.52"
117+
}
118+
119+
data "oci_core_dedicated_vm_host_shapes" "test_dedicated_vm_host_shapes" {
120+
#Required
121+
compartment_id = "${var.compartment_ocid}"
122+
123+
#Optional
124+
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
125+
instance_shape_name = "VM.Standard2.1"
126+
}
127+
128+
data "oci_core_dedicated_vm_hosts_instances" "test_dedicated_vm_hosts_instances" {
129+
#Required
130+
compartment_id = "${var.compartment_ocid}"
131+
dedicated_vm_host_id = "${oci_core_dedicated_vm_host.test_dedicated_vm_host.id}"
132+
133+
#Optional
134+
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
135+
depends_on = ["oci_core_instance.test_instance"]
136+
}
137+
138+
#output the dedidcated vm host ids
139+
output "dedicated_hos_idst" {
140+
value = ["${data.oci_core_dedicated_vm_hosts.test_dedicated_vm_hosts.id}"]
141+
}
142+
143+
#output the dedidcated vm host ids
144+
output "dedicated_host_shapes" {
145+
value = ["${data.oci_core_dedicated_vm_host_shapes.test_dedicated_vm_host_shapes.dedicated_vm_host_shapes}"]
146+
}
147+
148+
output "dedicated_vm_host_instances" {
149+
value = ["${data.oci_core_dedicated_vm_hosts_instances.test_dedicated_vm_hosts_instances.dedicated_vm_host_instances}"]
150+
}
151+
152+
output "dedicated_vm_host_instance_shapes" {
153+
value = ["${data.oci_core_dedicated_vm_host_instance_shapes.test_dedicated_vm_host_instance_shapes.dedicated_vm_host_instance_shapes}"]
154+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
3+
package provider
4+
5+
import (
6+
"context"
7+
8+
"github.com/hashicorp/terraform/helper/schema"
9+
oci_core "github.com/oracle/oci-go-sdk/core"
10+
)
11+
12+
func CoreDedicatedVmHostDataSource() *schema.Resource {
13+
fieldMap := make(map[string]*schema.Schema)
14+
fieldMap["dedicated_vm_host_id"] = &schema.Schema{
15+
Type: schema.TypeString,
16+
Required: true,
17+
}
18+
return GetSingularDataSourceItemSchema(CoreDedicatedVmHostResource(), fieldMap, readSingularCoreDedicatedVmHost)
19+
}
20+
21+
func readSingularCoreDedicatedVmHost(d *schema.ResourceData, m interface{}) error {
22+
sync := &CoreDedicatedVmHostDataSourceCrud{}
23+
sync.D = d
24+
sync.Client = m.(*OracleClients).computeClient
25+
26+
return ReadResource(sync)
27+
}
28+
29+
type CoreDedicatedVmHostDataSourceCrud struct {
30+
D *schema.ResourceData
31+
Client *oci_core.ComputeClient
32+
Res *oci_core.GetDedicatedVmHostResponse
33+
}
34+
35+
func (s *CoreDedicatedVmHostDataSourceCrud) VoidState() {
36+
s.D.SetId("")
37+
}
38+
39+
func (s *CoreDedicatedVmHostDataSourceCrud) Get() error {
40+
request := oci_core.GetDedicatedVmHostRequest{}
41+
42+
if dedicatedVmHostId, ok := s.D.GetOkExists("dedicated_vm_host_id"); ok {
43+
tmp := dedicatedVmHostId.(string)
44+
request.DedicatedVmHostId = &tmp
45+
}
46+
47+
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "core")
48+
49+
response, err := s.Client.GetDedicatedVmHost(context.Background(), request)
50+
if err != nil {
51+
return err
52+
}
53+
54+
s.Res = &response
55+
return nil
56+
}
57+
58+
func (s *CoreDedicatedVmHostDataSourceCrud) SetData() error {
59+
if s.Res == nil {
60+
return nil
61+
}
62+
63+
s.D.SetId(*s.Res.Id)
64+
65+
if s.Res.AvailabilityDomain != nil {
66+
s.D.Set("availability_domain", *s.Res.AvailabilityDomain)
67+
}
68+
69+
if s.Res.CompartmentId != nil {
70+
s.D.Set("compartment_id", *s.Res.CompartmentId)
71+
}
72+
73+
if s.Res.DedicatedVmHostShape != nil {
74+
s.D.Set("dedicated_vm_host_shape", *s.Res.DedicatedVmHostShape)
75+
}
76+
77+
if s.Res.DefinedTags != nil {
78+
s.D.Set("defined_tags", definedTagsToMap(s.Res.DefinedTags))
79+
}
80+
81+
if s.Res.DisplayName != nil {
82+
s.D.Set("display_name", *s.Res.DisplayName)
83+
}
84+
85+
if s.Res.FaultDomain != nil {
86+
s.D.Set("fault_domain", *s.Res.FaultDomain)
87+
}
88+
89+
s.D.Set("freeform_tags", s.Res.FreeformTags)
90+
91+
if s.Res.RemainingOcpus != nil {
92+
s.D.Set("remaining_ocpus", *s.Res.RemainingOcpus)
93+
}
94+
95+
s.D.Set("state", s.Res.LifecycleState)
96+
97+
if s.Res.TimeCreated != nil {
98+
s.D.Set("time_created", s.Res.TimeCreated.String())
99+
}
100+
101+
if s.Res.TotalOcpus != nil {
102+
s.D.Set("total_ocpus", *s.Res.TotalOcpus)
103+
}
104+
105+
return nil
106+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
2+
3+
package provider
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform/helper/resource"
10+
"github.com/hashicorp/terraform/terraform"
11+
12+
"github.com/terraform-providers/terraform-provider-oci/httpreplay"
13+
)
14+
15+
var (
16+
dedicatedVmHostInstanceShapeDataSourceRepresentation = map[string]interface{}{
17+
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
18+
"availability_domain": Representation{repType: Optional, create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
19+
"dedicated_vm_host_shape": Representation{repType: Optional, create: `DVH.Standard2.52`},
20+
}
21+
22+
DedicatedVmHostInstanceShapeResourceConfig = ""
23+
)
24+
25+
func TestCoreDedicatedVmHostInstanceShapeResource_basic(t *testing.T) {
26+
httpreplay.SetScenario("TestCoreDedicatedVmHostInstanceShapeResource_basic")
27+
defer httpreplay.SaveScenario()
28+
29+
provider := testAccProvider
30+
config := testProviderConfig()
31+
32+
compartmentId := getEnvSettingWithBlankDefault("compartment_ocid")
33+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
34+
35+
datasourceName := "data.oci_core_dedicated_vm_host_instance_shapes.test_dedicated_vm_host_instance_shapes"
36+
37+
resource.Test(t, resource.TestCase{
38+
PreCheck: func() { testAccPreCheck(t) },
39+
Providers: map[string]terraform.ResourceProvider{
40+
"oci": provider,
41+
},
42+
Steps: []resource.TestStep{
43+
// verify datasource
44+
{
45+
Config: config +
46+
generateDataSourceFromRepresentationMap("oci_core_dedicated_vm_host_instance_shapes", "test_dedicated_vm_host_instance_shapes", Required, Create, dedicatedVmHostInstanceShapeDataSourceRepresentation) +
47+
compartmentIdVariableStr + DedicatedVmHostInstanceShapeResourceConfig,
48+
Check: resource.ComposeAggregateTestCheckFunc(
49+
resource.TestCheckResourceAttr(datasourceName, "compartment_id", compartmentId),
50+
51+
resource.TestCheckResourceAttrSet(datasourceName, "dedicated_vm_host_instance_shapes.#"),
52+
resource.TestCheckResourceAttrSet(datasourceName, "dedicated_vm_host_instance_shapes.0.availability_domain"),
53+
resource.TestCheckResourceAttrSet(datasourceName, "dedicated_vm_host_instance_shapes.0.instance_shape_name"),
54+
),
55+
},
56+
},
57+
})
58+
}

0 commit comments

Comments
 (0)