Skip to content

Commit c20da97

Browse files
authored
Launch instance body supports nested CreateVnicDetails, related parameter updates to Vnics and Subnets (#102)
* Launch instance body supports nested CreateVnicDetails, related parameter updates to Vnics and Subnets * ipxeScript to launch instance * adds ProhibitPublicIpOnVnic to subnet creation and HostnameLabel to vnic * does not removed deprecated subnetId from top launch instance body yet * create subnet optional routeTableId, securityListIds * remove merge conflict artifacts * ignore mac hidden files
1 parent 372eac3 commit c20da97

File tree

16 files changed

+178
-37
lines changed

16 files changed

+178
-37
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@ crash.log
4040
terraform-encrypted-des.sh
4141
terraform-encrypted.sh
4242
terraform-plain.sh
43+
.DS_Store

data_source_obmcs_core_instance.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func resourceCoreInstance() *schema.Resource {
6565
Type: schema.TypeString,
6666
Computed: true,
6767
},
68+
"ipxe_script": {
69+
Type: schema.TypeString,
70+
Computed: true,
71+
},
6872
"metadata": {
6973
Type: schema.TypeMap,
7074
Computed: true,
@@ -144,6 +148,7 @@ func (s *InstanceDatasourceCrud) SetData() {
144148
"display_name": v.DisplayName,
145149
"id": v.ID,
146150
"image": v.ImageID,
151+
"ipxe_script": v.IpxeScript,
147152
"metadata": v.Metadata,
148153
"region": v.Region,
149154
"shape": v.Shape,

data_source_obmcs_core_subnet.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func resourceCoreSubnets() *schema.Resource {
8080
Type: schema.TypeString,
8181
Computed: true,
8282
},
83+
"prohibit_public_ip_on_vnic": {
84+
Type: schema.TypeBool,
85+
Computed: true,
86+
},
8387
"state": {
8488
Type: schema.TypeString,
8589
Computed: true,
@@ -154,10 +158,11 @@ func (s *SubnetDatasourceCrud) SetData() {
154158
"security_list_ids": v.SecurityListIDs,
155159
"display_name": v.DisplayName,
156160
"id": v.ID,
157-
"state": v.State,
158-
"time_created": v.TimeCreated.String(),
159-
"virtual_router_ip": v.VirtualRouterIP,
160-
"virtual_router_mac": v.VirtualRouterMac,
161+
"prohibit_public_ip_on_vnic": v.ProhibitPublicIpOnVnic,
162+
"state": v.State,
163+
"time_created": v.TimeCreated.String(),
164+
"virtual_router_ip": v.VirtualRouterIP,
165+
"virtual_router_mac": v.VirtualRouterMac,
161166
}
162167
resources = append(resources, res)
163168
}

data_source_obmcs_core_vnic.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ func VnicDatasource() *schema.Resource {
3434
Type: schema.TypeString,
3535
Computed: true,
3636
},
37+
"hostname_label": {
38+
Type: schema.TypeString,
39+
Computed: true,
40+
},
3741
"state": {
3842
Type: schema.TypeString,
3943
Computed: true,
@@ -81,6 +85,7 @@ func (v *VnicDatasourceCrud) SetData() {
8185
v.D.Set("availability_domain", v.Resource.AvailabilityDomain)
8286
v.D.Set("compartment_id", v.Resource.CompartmentID)
8387
v.D.Set("display_name", v.Resource.DisplayName)
88+
v.D.Set("hostname_label", v.Resource.HostnameLabel)
8489
v.D.Set("state", v.Resource.State)
8590
v.D.Set("private_ip_address", v.Resource.PrivateIPAddress)
8691
v.D.Set("public_ip_address", v.Resource.PublicIPAddress)

docs/datasources/core/subnet.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ The following attributes are exported:
3535
* `security_list_ids` - OCIDs for the security lists to use for VNICs in this subnet.
3636
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable.
3737
* `id` - The subnet's Oracle ID (OCID).
38+
* `prohibit_public_ip_on_vnic` - Whether VNICs within this subnet can have public IP addresses.
3839
* `vcn_id` - The OCID of the VCN the subnet is in.
3940
* `state` - The VCN's current state. [PROVISIONING, AVAILABLE, TERMINATING, TERMINATED]
4041
* `time_created` - The date and time the VCN was created.

docs/datasources/core/vnic.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The following attributes are exported:
2424
* `availability_domain` - The VNIC's Availability Domain.
2525
* `display_name` - A user-friendly name. Does not have to be unique.
2626
* `id` - The OCID of the VNIC.
27+
* `hostname_label` - The hostname for the VNIC that is created during instance launch. Used for DNS. .
2728
* `state` - The current state of the VNIC. [PROVISIONING, AVAILABLE, TERMINATING, TERMINATED]
2829
* `private_ip_address` - The private IP addresses of the VNIC, which is within the VNIC subnet and is accessible within the VCN.
2930
* `public_ip_address` - The public IP address of the VNIC, which Oracle performs NAT for at the gateway.

docs/resources/core/subnet.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ resource "baremetal_core_subnet" "t" {
1313
route_table_id = "routetableid"
1414
vcn_id = "vcnid"
1515
security_list_ids = ["slid1", "slid2"]
16+
prohibit_public_ip_on_vnic = true
1617
}
1718
```
1819

@@ -26,6 +27,7 @@ The following arguments are supported:
2627
* `vcn_id` - (Required) The OCID of the VCN to contain the subnet.
2728
* `dhcp_options_id` - (Optional) The OCID of the set of DHCP options the subnet will use. If you don't provide a value, the subnet will use the VCN's default set of DHCP options.
2829
* `display_name` - (Optional) The maximum number of items to return in a paginated "List" call.
30+
* `prohibit_public_ip_on_vnic` - (Optional) Whether VNICs within this subnet can have public IP. If it is allowed, VNICs created in the subnet will automatically be assigned public IP unless otherwise specified in the VNIC. If it is prohibited, VNICs in the subnet cannot have public IP address assigned. The default value is false if unspecified.
2931
* `route_table_id` - (Optional) The OCID of the route table the subnet will use. If you don't provide a value, the subnet will use the VCN's default route table.
3032
* `security_list_ids` - (Optional) OCIDs for the security lists to associate with the subnet. If you don't provide a value, the VCN's default security list will be associated with the subnet. Remember that security lists are associated at the subnet level, but the rules are applied to the individual VNICs in the subnet.
3133

@@ -41,6 +43,7 @@ The following arguments are supported:
4143
* `security_list_ids` - OCIDs for the security lists to use for VNICs in this subnet.
4244
* `display_name` - A user-friendly name. Does not have to be unique, and it's changeable.
4345
* `id` - The subnet's Oracle ID (OCID).
46+
* `prohibit_public_ip_on_vnic` - Whether VNICs within this subnet can have public IPs. If it is allowed, VNICs created in the subnet will automatically be assigned public IP unless otherwise specified in the VNIC. If it is prohibited, VNICs in the subnet cannot have public IP address assigned. The default value is false if unspecified.
4447
* `vcn_id` - The OCID of the VCN the subnet is in.
4548
* `state` - The VCN's current state. [PROVISIONING, AVAILABLE, TERMINATING, TERMINATED]
4649
* `time_created` - The date and time the VCN was created.

resource_obmcs_core_instance.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,34 @@ func InstanceResource() *schema.Resource {
2828
Update: updateInstance,
2929
Delete: deleteInstance,
3030
Schema: map[string]*schema.Schema{
31+
"create_vnic_details": &schema.Schema{
32+
Type: schema.TypeMap,
33+
Optional: true,
34+
Elem: &schema.Resource{
35+
Schema: map[string]*schema.Schema{
36+
"assign_public_ip": {
37+
Type: schema.TypeBool,
38+
Optional: true,
39+
},
40+
"display_name": {
41+
Type: schema.TypeString,
42+
Optional: true,
43+
},
44+
"hostname_label": {
45+
Type: schema.TypeString,
46+
Optional: true,
47+
},
48+
"private_ip": {
49+
Type: schema.TypeString,
50+
Optional: true,
51+
},
52+
"subnet_id": {
53+
Type: schema.TypeString,
54+
Required: true,
55+
},
56+
},
57+
},
58+
},
3159
"availability_domain": {
3260
Type: schema.TypeString,
3361
Required: true,
@@ -57,6 +85,10 @@ func InstanceResource() *schema.Resource {
5785
Required: true,
5886
ForceNew: true,
5987
},
88+
"ipxe_script": {
89+
Type: schema.TypeString,
90+
Optional: true,
91+
},
6092
"metadata": {
6193
Type: schema.TypeMap,
6294
Required: true,
@@ -181,12 +213,46 @@ func (s *InstanceResourceCrud) Create() (e error) {
181213
if hostnameLabel, ok := s.D.GetOk("hostname_label"); ok {
182214
opts.HostnameLabel = hostnameLabel.(string)
183215
}
216+
if ipxeScript, ok := s.D.GetOk("ipxe_script"); ok {
217+
opts.IpxeScript = ipxeScript.(string)
218+
}
184219

185220
if rawMetadata, ok := s.D.GetOk("metadata"); ok {
186221
metadata := resourceInstanceMapToMetadata(rawMetadata.(map[string]interface{}))
187222
opts.Metadata = metadata
188223
}
189224

225+
if rawVnic, ok := s.D.GetOk("create_vnic_details"); ok {
226+
vnic := rawVnic.(map[string]interface{})
227+
228+
vnicOpts := &baremetal.CreateVnicOptions{}
229+
vnicOpts.SubnetID = vnic["subnet_id"].(string)
230+
231+
displayName := vnic["display_name"]
232+
if displayName != nil {
233+
vnicOpts.DisplayName = displayName.(string)
234+
}
235+
236+
hostnameLabel := vnic["hostname_label"]
237+
if hostnameLabel != nil {
238+
vnicOpts.HostnameLabel = hostnameLabel.(string)
239+
}
240+
241+
privateIp := vnic["private_ip"]
242+
if privateIp != nil {
243+
vnicOpts.PrivateIp = privateIp.(string)
244+
}
245+
246+
//todo: work around for tf bug https://github.com/hashicorp/terraform/issues/13512
247+
assignPublicIp := vnic["assign_public_ip"]
248+
if assignPublicIp != nil {
249+
vnicOpts.AssignPublicIp = new(bool)
250+
*vnicOpts.AssignPublicIp = assignPublicIp.(string) == "1"
251+
}
252+
253+
opts.CreateVnicOptions = vnicOpts
254+
}
255+
190256
s.Resource, e = s.Client.LaunchInstance(
191257
availabilityDomain,
192258
compartmentID,
@@ -284,6 +350,7 @@ func (s *InstanceResourceCrud) SetData() {
284350
s.D.Set("compartment_id", s.Resource.CompartmentID)
285351
s.D.Set("display_name", s.Resource.DisplayName)
286352
s.D.Set("image", s.Resource.ImageID)
353+
s.D.Set("ipxe_script", s.Resource.IpxeScript)
287354
s.D.Set("metadata", s.Resource.Metadata)
288355
s.D.Set("region", s.Resource.Region)
289356
s.D.Set("shape", s.Resource.Shape)

resource_obmcs_core_subnet.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func SubnetResource() *schema.Resource {
4040
},
4141
"route_table_id": {
4242
Type: schema.TypeString,
43-
Required: true,
43+
Optional: true,
4444
ForceNew: true,
4545
},
4646
"vcn_id": {
@@ -50,7 +50,7 @@ func SubnetResource() *schema.Resource {
5050
},
5151
"security_list_ids": {
5252
Type: schema.TypeSet,
53-
Required: true,
53+
Optional: true,
5454
ForceNew: true,
5555
Set: schema.HashString,
5656
Elem: &schema.Schema{
@@ -76,6 +76,10 @@ func SubnetResource() *schema.Resource {
7676
Type: schema.TypeString,
7777
Computed: true,
7878
},
79+
"prohibit_public_ip_on_vnic": {
80+
Type: schema.TypeBool,
81+
Optional: true,
82+
},
7983
"state": {
8084
Type: schema.TypeString,
8185
Computed: true,
@@ -176,6 +180,11 @@ func (s *SubnetResourceCrud) Create() (e error) {
176180
opts.DNSLabel = dnsLabel.(string)
177181
}
178182

183+
prohibitPublicIpOnVnic, ok := s.D.GetOk("prohibit_public_ip_on_vnic")
184+
if ok {
185+
opts.ProhibitPublicIpOnVnic = prohibitPublicIpOnVnic.(bool)
186+
}
187+
179188
if rawSecurityListIDs, ok := s.D.GetOk("security_list_ids"); ok {
180189
securityListIDs := []string{}
181190
for _, val := range rawSecurityListIDs.(*schema.Set).List() {

vendor/github.com/MustWin/baremetal-sdk-go/core_instance.go

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)