Skip to content

Commit 814b21b

Browse files
author
ccushing
committed
Support regional Subnets by making Availability Domain parameter optional
1 parent 5b30147 commit 814b21b

File tree

5 files changed

+33
-25
lines changed

5 files changed

+33
-25
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## 3.15.1 (Unreleased)
2+
Enable regional Subnets by making Availability Domain optional when creating a Subnet
23

34
### Added
45
- Adding description property to rules in Steering Policies in DNS

docs/examples/networking/subnet/subnet.tf

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,36 @@ variable "availability_domain" {
1919
default = 3
2020
}
2121

22-
resource "oci_core_virtual_network" "ExampleVCN" {
23-
cidr_block = "10.1.0.0/16"
22+
resource "oci_core_virtual_network" "vcn1" {
23+
cidr_block = "10.0.0.0/16"
2424
compartment_id = "${var.compartment_ocid}"
2525
display_name = "TFExampleVCN"
2626
dns_label = "tfexamplevcn"
2727
}
2828

29-
/*
30-
Because you can specify multiple security lists/subnet the security_list_ids value must be specified as a list in []'s.
31-
See https://www.terraform.io/docs/configuration/syntax.html
32-
33-
Generally you wouldn't specify a subnet without first specifying a VCN. Once the VCN has been created you would get the vcn_id, route_table_id, and security_list_id(s) from that resource and use Terraform attributes below to populate those values.
34-
See https://www.terraform.io/docs/configuration/interpolation.html*/
35-
resource "oci_core_subnet" "ExampleSubnet" {
29+
// A regional subnet will not specify an Availability Domain
30+
resource "oci_core_subnet" "subnet1" {
31+
cidr_block = "10.0.1.0/24"
32+
display_name = "TFRegionalSubnet"
33+
dns_label = "regionalsubnet"
34+
compartment_id = "${var.compartment_ocid}"
35+
vcn_id = "${oci_core_virtual_network.vcn1.id}"
36+
security_list_ids = ["${oci_core_virtual_network.vcn1.default_security_list_id}"]
37+
route_table_id = "${oci_core_virtual_network.vcn1.default_route_table_id}"
38+
dhcp_options_id = "${oci_core_virtual_network.vcn1.default_dhcp_options_id}"
39+
}
40+
41+
// An AD based subnet will supply an Availability Domain
42+
resource "oci_core_subnet" "subnet2" {
3643
availability_domain = "${lookup(data.oci_identity_availability_domains.ADs.availability_domains[var.availability_domain - 1],"name")}"
37-
cidr_block = "10.1.1.0/24"
38-
display_name = "TFExampleSubnet"
39-
dns_label = "tfexamplesubnet"
44+
cidr_block = "10.0.2.0/24"
45+
display_name = "TFADSubnet"
46+
dns_label = "adsubnet"
4047
compartment_id = "${var.compartment_ocid}"
41-
vcn_id = "${oci_core_virtual_network.ExampleVCN.id}"
42-
security_list_ids = ["${oci_core_virtual_network.ExampleVCN.default_security_list_id}"]
43-
route_table_id = "${oci_core_virtual_network.ExampleVCN.default_route_table_id}"
44-
dhcp_options_id = "${oci_core_virtual_network.ExampleVCN.default_dhcp_options_id}"
48+
vcn_id = "${oci_core_virtual_network.vcn1.id}"
49+
security_list_ids = ["${oci_core_virtual_network.vcn1.default_security_list_id}"]
50+
route_table_id = "${oci_core_virtual_network.vcn1.default_route_table_id}"
51+
dhcp_options_id = "${oci_core_virtual_network.vcn1.default_dhcp_options_id}"
4552
}
4653

4754
data "oci_identity_availability_domains" "ADs" {

oci/core_subnet_resource.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ func CoreSubnetResource() *schema.Resource {
2222
Delete: deleteCoreSubnet,
2323
Schema: map[string]*schema.Schema{
2424
// Required
25-
"availability_domain": {
26-
Type: schema.TypeString,
27-
Required: true,
28-
ForceNew: true,
29-
},
3025
"cidr_block": {
3126
Type: schema.TypeString,
3227
Required: true,
@@ -44,6 +39,12 @@ func CoreSubnetResource() *schema.Resource {
4439
},
4540

4641
// Optional
42+
"availability_domain": {
43+
Type: schema.TypeString,
44+
Optional: true,
45+
Computed: true,
46+
ForceNew: true,
47+
},
4748
"defined_tags": {
4849
Type: schema.TypeMap,
4950
Optional: true,

oci/core_subnet_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ var (
3838
}
3939

4040
subnetRepresentation = map[string]interface{}{
41-
"availability_domain": Representation{repType: Required, create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
4241
"cidr_block": Representation{repType: Required, create: `10.0.0.0/16`},
4342
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
4443
"vcn_id": Representation{repType: Required, create: `${oci_core_vcn.test_vcn.id}`},
44+
"availability_domain": Representation{repType: Optional, create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
4545
"defined_tags": Representation{repType: Optional, create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
4646
"dhcp_options_id": Representation{repType: Optional, create: `${oci_core_vcn.test_vcn.default_dhcp_options_id}`, update: `${oci_core_dhcp_options.test_dhcp_options.id}`},
4747
"display_name": Representation{repType: Optional, create: `MySubnet`, update: `displayName2`},
@@ -82,7 +82,6 @@ func TestCoreSubnetResource_basic(t *testing.T) {
8282
Config: config + compartmentIdVariableStr + SubnetResourceDependencies +
8383
generateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", Required, Create, subnetRepresentation),
8484
Check: resource.ComposeAggregateTestCheckFunc(
85-
resource.TestCheckResourceAttrSet(resourceName, "availability_domain"),
8685
resource.TestCheckResourceAttr(resourceName, "cidr_block", "10.0.0.0/16"),
8786
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
8887
resource.TestCheckResourceAttrSet(resourceName, "dhcp_options_id"),

website/docs/r/core_subnet.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ VCN Resolver to resolve hostnames for instances in the subnet. For more informat
4747
```hcl
4848
resource "oci_core_subnet" "test_subnet" {
4949
#Required
50-
availability_domain = "${var.subnet_availability_domain}"
5150
cidr_block = "${var.subnet_cidr_block}"
5251
compartment_id = "${var.compartment_id}"
5352
security_list_ids = "${var.subnet_security_list_ids}"
5453
vcn_id = "${oci_core_vcn.test_vcn.id}"
5554
5655
#Optional
56+
availability_domain = "${var.subnet_availability_domain}"
5757
defined_tags = {"Operations.CostCenter"= "42"}
5858
dhcp_options_id = "${oci_core_dhcp_options.test_dhcp_options.id}"
5959
display_name = "${var.subnet_display_name}"
@@ -68,7 +68,7 @@ resource "oci_core_subnet" "test_subnet" {
6868

6969
The following arguments are supported:
7070

71-
* `availability_domain` - (Required) The availability domain to contain the subnet. Example: `Uocm:PHX-AD-1`
71+
* `availability_domain` - (Optional) The availability domain to contain the subnet. Example: `Uocm:PHX-AD-1`
7272
* `cidr_block` - (Required) The CIDR IP address range of the subnet. Example: `172.16.1.0/24`
7373
* `compartment_id` - (Required) The OCID of the compartment to contain the subnet.
7474
* `defined_tags` - (Optional) (Updatable) Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Operations.CostCenter": "42"}`

0 commit comments

Comments
 (0)