Skip to content

Commit 3fa4684

Browse files
authored
DHCP options example, doc and test update (#216)
* DHCP options example, doc and test update * also removes retry for running acceptance tests * gofmt
1 parent 6ab44aa commit 3fa4684

File tree

8 files changed

+179
-39
lines changed

8 files changed

+179
-39
lines changed

crud/helpers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ import (
1717
)
1818

1919
var (
20-
FiveMinutes time.Duration = 5 * time.Minute
21-
TwoHours time.Duration = 120 * time.Minute
22-
ZeroTime time.Duration = 0
20+
FiveMinutes time.Duration = 5 * time.Minute
21+
TwoHours time.Duration = 120 * time.Minute
22+
ZeroTime time.Duration = 0
2323

24-
DefaultTimeout = &schema.ResourceTimeout{
24+
DefaultTimeout = &schema.ResourceTimeout{
2525
Create: &FiveMinutes,
2626
Update: &FiveMinutes,
2727
Delete: &FiveMinutes,
@@ -185,7 +185,7 @@ func CreateDBSystemResource(d *schema.ResourceData, sync ResourceCreator) (e err
185185
shape := d.Get("shape")
186186
timeout = d.Timeout(schema.TimeoutCreate)
187187
if timeout == 0 {
188-
if strings.HasPrefix(shape.(string), "Exadata"){
188+
if strings.HasPrefix(shape.(string), "Exadata") {
189189
timeout = time.Duration(12) * time.Hour
190190
} else {
191191
timeout = time.Duration(2) * time.Hour

data_source_obmcs_database_db_version.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ func DBVersionDatasource() *schema.Resource {
3030
Type: schema.TypeString,
3131
Computed: true,
3232
},
33-
"supports_pdb":{
34-
Type: schema.TypeBool,
33+
"supports_pdb": {
34+
Type: schema.TypeBool,
3535
Computed: true,
3636
},
3737
},
@@ -95,7 +95,7 @@ func (s *DBVersionDatasourceCrud) SetData() {
9595
resources := []map[string]interface{}{}
9696
for _, v := range s.Res.DBVersions {
9797
res := map[string]interface{}{
98-
"version": v.Version,
98+
"version": v.Version,
9999
"supports_pdb": v.SupportsPDB,
100100
}
101101
resources = append(resources, res)
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This example demonstrates the various dhcp option configurations.
3+
*/
4+
5+
variable "tenancy_ocid" {}
6+
variable "user_ocid" {}
7+
variable "fingerprint" {}
8+
variable "private_key_path" {}
9+
variable "compartment_ocid" {}
10+
variable "region" {}
11+
12+
variable "vcn_ocid" {}
13+
14+
15+
provider "baremetal" {
16+
tenancy_ocid = "${var.tenancy_ocid}"
17+
user_ocid = "${var.user_ocid}"
18+
fingerprint = "${var.fingerprint}"
19+
private_key_path = "${var.private_key_path}"
20+
region = "${var.region}"
21+
}
22+
23+
24+
resource "baremetal_core_dhcp_options" "dhcp-options1" {
25+
compartment_id = "${var.compartment_ocid}"
26+
vcn_id = "${var.vcn_ocid}"
27+
display_name = "dhcp-options1"
28+
29+
// required
30+
options {
31+
type = "DomainNameServer"
32+
server_type = "VcnLocalPlusInternet"
33+
}
34+
35+
// optional
36+
options {
37+
type = "SearchDomain"
38+
search_domain_names = [ "test.com" ]
39+
}
40+
}
41+
42+
43+
resource "baremetal_core_dhcp_options" "dhcp-options2" {
44+
compartment_id = "${var.compartment_ocid}"
45+
vcn_id = "${var.vcn_ocid}"
46+
display_name = "dhcp-options2"
47+
48+
// required
49+
options {
50+
type = "DomainNameServer"
51+
server_type = "CustomDnsServer"
52+
custom_dns_servers = [ "8.8.4.4", "8.8.8.8" ]
53+
}
54+
55+
// optional
56+
options {
57+
type = "SearchDomain"
58+
search_domain_names = [ "test.com" ]
59+
}
60+
}

docs/resources/core/dhcp_option.md

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,52 @@
22

33
Provide a Dhcp Options resource.
44

5+
For more information, see
6+
[DNS in Your Virtual Cloud Network](https://docs.us-phoenix-1.oraclecloud.com/Content/Network/Concepts/dns.htm)
7+
58
## Example Usage
69

10+
#### VCN Local with Internet
11+
```
12+
resource "baremetal_core_dhcp_options" "dhcp-options1" {
13+
compartment_id = "${var.compartment_ocid}"
14+
vcn_id = "${var.vcn_ocid}"
15+
display_name = "dhcp-options1"
16+
17+
// required
18+
options {
19+
type = "DomainNameServer"
20+
server_type = "VcnLocalPlusInternet"
21+
}
22+
23+
// optional
24+
options {
25+
type = "SearchDomain"
26+
search_domain_names = [ "test.com" ]
27+
}
28+
}
29+
```
30+
31+
#### Custom DNS Server
32+
733
```
8-
resource "baremetal_core_dhcp_options" "t" {
9-
compartment_id = "compartment_id"
10-
display_name = "display_name"
11-
options {
12-
type = "type"
13-
custom_dns_servers = [ "custom_dns_servers" ]
14-
server_type = "server_type"
15-
}
16-
options {
17-
type = "type"
18-
custom_dns_servers = [ "custom_dns_servers" ]
19-
server_type = "server_type"
20-
}
21-
vcn_id = "vcn_id"
34+
resource "baremetal_core_dhcp_options" "dhcp-options2" {
35+
compartment_id = "${var.compartment_ocid}"
36+
vcn_id = "${var.vcn_ocid}"
37+
display_name = "dhcp-options3"
38+
39+
// required
40+
options {
41+
type = "DomainNameServer"
42+
server_type = "CustomDnsServer"
43+
custom_dns_servers = [ "192.168.0.2", "192.168.0.11", "192.168.0.19" ]
44+
}
45+
46+
// optional
47+
options {
48+
type = "SearchDomain"
49+
search_domain_names = [ "test.com" ]
50+
}
2251
}
2352
```
2453

@@ -29,7 +58,7 @@ The following arguments are supported:
2958
* `compartment_id` - (Required) The OCID of the compartment.
3059
* `vcn_id` - (Required) The OCID of the VCN.
3160
* `display_name` - (Optional) A user-friendly name. Does not have to be unique, and it's changeable.
32-
* `options` - (Required) A set of DHCP options.
61+
* `options` - (Required) A set of [DHCP Options](https://docs.us-phoenix-1.oraclecloud.com/api/#/en/iaas/20160918/DhcpDnsOption/).
3362

3463
## Attributes Reference
3564
* `compartment_id` - The OCID of the compartment containing the set of DHCP options.

helpers_objectstorage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ var preauthenticatedRequestSchema = map[string]*schema.Schema{
110110
string(baremetal.ObjectRead)}, true),
111111
},
112112
"access_uri": {
113-
Type: schema.TypeString,
113+
Type: schema.TypeString,
114114
Computed: true,
115115
Optional: true,
116116
},

provider_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ func GetTestProvider() mockableClient {
294294
d.Set("private_key_path", getRequiredEnvSetting("private_key_path"))
295295
d.Set("private_key_password", getEnvSetting("private_key_password", ""))
296296
d.Set("private_key", getEnvSetting("private_key", ""))
297+
d.Set("disable_auto_retries", true)
297298

298299
client, err := providerConfig(d)
299300
if err != nil {

resource_obmcs_core_dhcp_options_test.go

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,58 @@ func (s *ResourceCoreDHCPOptionsTestSuite) SetupTest() {
4747
compartment_id = "${var.compartment_id}"
4848
display_name = "network_name"
4949
}
50-
resource "baremetal_core_dhcp_options" "t" {
51-
compartment_id = "${var.compartment_id}"
52-
display_name = "display_name"
53-
options {
54-
type = "DomainNameServer"
55-
custom_dns_servers = [ "8.8.8.8" ]
56-
server_type = "CustomDnsServer"
57-
}
58-
vcn_id = "${baremetal_core_virtual_network.t.id}"
50+
51+
resource "baremetal_core_dhcp_options" "opt1" {
52+
compartment_id = "${var.compartment_id}"
53+
vcn_id = "${baremetal_core_virtual_network.t.id}"
54+
display_name = "display_name"
55+
options {
56+
type = "DomainNameServer"
57+
server_type = "VcnLocalPlusInternet"
58+
}
59+
}
60+
61+
resource "baremetal_core_dhcp_options" "opt2" {
62+
compartment_id = "${var.compartment_id}"
63+
vcn_id = "${baremetal_core_virtual_network.t.id}"
64+
display_name = "display_name"
65+
options {
66+
type = "DomainNameServer"
67+
server_type = "VcnLocalPlusInternet"
68+
}
69+
options {
70+
type = "SearchDomain"
71+
search_domain_names = [ "test.com" ]
72+
}
73+
}
74+
75+
resource "baremetal_core_dhcp_options" "opt3" {
76+
compartment_id = "${var.compartment_id}"
77+
vcn_id = "${baremetal_core_virtual_network.t.id}"
78+
display_name = "display_name"
79+
options {
80+
type = "DomainNameServer"
81+
server_type = "CustomDnsServer"
82+
custom_dns_servers = [ "8.8.4.4", "8.8.8.8" ]
83+
}
84+
}
85+
86+
resource "baremetal_core_dhcp_options" "opt4" {
87+
compartment_id = "${var.compartment_id}"
88+
vcn_id = "${baremetal_core_virtual_network.t.id}"
89+
display_name = "display_name"
90+
options {
91+
type = "DomainNameServer"
92+
server_type = "CustomDnsServer"
93+
custom_dns_servers = [ "8.8.4.4", "8.8.8.8" ]
94+
}
95+
options {
96+
type = "SearchDomain"
97+
search_domain_names = [ "test.com" ]
98+
}
5999
}
60100
`
61101
s.Config += testProviderConfig()
62-
63-
s.ResourceName = "baremetal_core_dhcp_options.t"
64102
}
65103

66104
func (s *ResourceCoreDHCPOptionsTestSuite) TestCreateResourceCoreDHCPOptions() {
@@ -74,9 +112,21 @@ func (s *ResourceCoreDHCPOptionsTestSuite) TestCreateResourceCoreDHCPOptions() {
74112
Config: s.Config,
75113
Check: resource.ComposeTestCheckFunc(
76114

77-
resource.TestCheckResourceAttr(s.ResourceName, "display_name", "display_name"),
78-
resource.TestCheckResourceAttr(s.ResourceName, "options.0.type", "DomainNameServer"),
79-
resource.TestCheckResourceAttr(s.ResourceName, "options.0.server_type", "CustomDnsServer"),
115+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt1", "display_name", "display_name"),
116+
117+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt1", "options.0.type", "DomainNameServer"),
118+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt1", "options.0.server_type", "VcnLocalPlusInternet"),
119+
120+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt2", "options.0.type", "DomainNameServer"),
121+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt2", "options.0.server_type", "VcnLocalPlusInternet"),
122+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt2", "options.1.type", "SearchDomain"),
123+
124+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt3", "options.0.type", "DomainNameServer"),
125+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt3", "options.0.server_type", "CustomDnsServer"),
126+
127+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt4", "options.0.type", "DomainNameServer"),
128+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt4", "options.0.server_type", "CustomDnsServer"),
129+
resource.TestCheckResourceAttr("baremetal_core_dhcp_options.opt4", "options.1.type", "SearchDomain"),
80130
),
81131
},
82132
},

resource_obmcs_core_instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ package main
55
import (
66
"log"
77

8+
"encoding/json"
89
"github.com/MustWin/baremetal-sdk-go"
910
"github.com/hashicorp/terraform/helper/schema"
1011
"github.com/oracle/terraform-provider-baremetal/client"
1112
"github.com/oracle/terraform-provider-baremetal/crud"
1213
"github.com/oracle/terraform-provider-baremetal/options"
13-
"encoding/json"
1414
)
1515

1616
func InstanceResource() *schema.Resource {

0 commit comments

Comments
 (0)