Skip to content

Commit cbd19f1

Browse files
author
jiangong
committed
Updating Subnet Associations
1 parent 1610942 commit cbd19f1

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
- Support for public IP prefixes (CIDRs) up to 31
66
- Support for tagging in `oci_file_storage_file_system`, `oci_file_storage_mount_target`, and `oci_file_storage_snapshot`
77

8+
### Changed
9+
- Make `route_table_id`, `dhcp_options_id` in `oci_core_subnet` updatable
10+
- Make `security_list_ids` in `oci_core_subnet` optional and updatable
11+
812
### Deprecated
913
- Volumes: The “backup_policy_id” attribute is now deprecated. Backup policy should be assigned through “volume_backup_policy_assignments” resource instead.
1014
- BootVolumes: The “backup_policy_id” attribute is now deprecated. Backup policy should be assigned through “volume_backup_policy_assignments” resource instead.

oci/core_subnet_resource.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func SubnetResource() *schema.Resource {
5555
Type: schema.TypeString,
5656
Optional: true,
5757
Computed: true,
58-
ForceNew: true,
5958
},
6059
"display_name": {
6160
Type: schema.TypeString,
@@ -85,13 +84,11 @@ func SubnetResource() *schema.Resource {
8584
Type: schema.TypeString,
8685
Optional: true,
8786
Computed: true,
88-
ForceNew: true,
8987
},
9088
"security_list_ids": {
9189
Type: schema.TypeSet,
9290
Optional: true,
9391
Computed: true,
94-
ForceNew: true,
9592
MaxItems: 5,
9693
MinItems: 0,
9794
Set: literalTypeHashCodeForSets,
@@ -305,6 +302,11 @@ func (s *SubnetResourceCrud) Update() error {
305302
request.DefinedTags = convertedDefinedTags
306303
}
307304

305+
if dhcpOptionsId, ok := s.D.GetOkExists("dhcp_options_id"); ok {
306+
tmp := dhcpOptionsId.(string)
307+
request.DhcpOptionsId = &tmp
308+
}
309+
308310
if displayName, ok := s.D.GetOkExists("display_name"); ok {
309311
tmp := displayName.(string)
310312
request.DisplayName = &tmp
@@ -314,6 +316,24 @@ func (s *SubnetResourceCrud) Update() error {
314316
request.FreeformTags = objectMapToStringMap(freeformTags.(map[string]interface{}))
315317
}
316318

319+
if routeTableId, ok := s.D.GetOkExists("route_table_id"); ok {
320+
tmp := routeTableId.(string)
321+
request.RouteTableId = &tmp
322+
}
323+
324+
request.SecurityListIds = []string{}
325+
if securityListIds, ok := s.D.GetOkExists("security_list_ids"); ok {
326+
set := securityListIds.(*schema.Set)
327+
interfaces := set.List()
328+
tmp := make([]string, len(interfaces))
329+
for i := range interfaces {
330+
if interfaces[i] != nil {
331+
tmp[i] = interfaces[i].(string)
332+
}
333+
}
334+
request.SecurityListIds = tmp
335+
}
336+
317337
tmp := s.D.Id()
318338
request.SubnetId = &tmp
319339

oci/core_subnet_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,18 @@ var (
4141
"compartment_id": Representation{repType: Required, create: `${var.compartment_id}`},
4242
"vcn_id": Representation{repType: Required, create: `${oci_core_vcn.test_vcn.id}`},
4343
"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")}`},
44-
"dhcp_options_id": Representation{repType: Optional, create: `${oci_core_dhcp_options.test_dhcp_options.id}`},
44+
"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}`},
4545
"display_name": Representation{repType: Optional, create: `MySubnet`, update: `displayName2`},
4646
"dns_label": Representation{repType: Optional, create: `dnslabel`},
4747
"freeform_tags": Representation{repType: Optional, create: map[string]string{"Department": "Finance"}, update: map[string]string{"Department": "Accounting"}},
4848
"prohibit_public_ip_on_vnic": Representation{repType: Optional, create: `false`},
49-
"route_table_id": Representation{repType: Optional, create: `${oci_core_route_table.test_route_table.id}`},
50-
"security_list_ids": Representation{repType: Optional, create: []string{`${oci_core_vcn.test_vcn.default_security_list_id}`}},
49+
"route_table_id": Representation{repType: Optional, create: `${oci_core_vcn.test_vcn.default_route_table_id}`, update: `${oci_core_route_table.test_route_table.id}`},
50+
"security_list_ids": Representation{repType: Optional, create: []string{`${oci_core_vcn.test_vcn.default_security_list_id}`}, update: []string{`${oci_core_security_list.test_security_list.id}`}},
5151
}
5252

53-
SubnetRequiredOnlyResourceDependencies = AvailabilityDomainConfig + VcnResourceConfig
54-
SubnetResourceDependencies = AvailabilityDomainConfig + DhcpOptionsRequiredOnlyResource + RouteTableRequiredOnlyResource
53+
AnotherSecurityListRequiredOnlyResource = generateResourceFromRepresentationMap("oci_core_security_list", "test_security_list", Required, Create, securityListRepresentation)
54+
SubnetRequiredOnlyResourceDependencies = AvailabilityDomainConfig + VcnResourceConfig
55+
SubnetResourceDependencies = AvailabilityDomainConfig + DhcpOptionsRequiredOnlyResource + RouteTableRequiredOnlyResource + AnotherSecurityListRequiredOnlyResource
5556
)
5657

5758
func TestCoreSubnetResource_basic(t *testing.T) {

website/docs/r/core_subnet.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ The following arguments are supported:
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"}`
75-
* `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 uses the VCN's default set of DHCP options.
75+
* `dhcp_options_id` - (Optional) (Updatable) The OCID of the set of DHCP options the subnet will use. If you don't provide a value, the subnet uses the VCN's default set of DHCP options.
7676
* `display_name` - (Optional) (Updatable) A user-friendly name. Does not have to be unique, and it's changeable. Avoid entering confidential information.
7777
* `dns_label` - (Optional) A DNS label for the subnet, used in conjunction with the VNIC's hostname and VCN's DNS label to form a fully qualified domain name (FQDN) for each VNIC within this subnet (for example, `bminstance-1.subnet123.vcn1.oraclevcn.com`). Must be an alphanumeric string that begins with a letter and is unique within the VCN. The value cannot be changed.
7878

@@ -83,8 +83,8 @@ The following arguments are supported:
8383
Example: `subnet123`
8484
* `freeform_tags` - (Optional) (Updatable) Free-form tags for this resource. Each tag is a simple key-value pair with no predefined name, type, or namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm). Example: `{"Department": "Finance"}`
8585
* `prohibit_public_ip_on_vnic` - (Optional) Whether VNICs within this subnet can have public IP addresses. Defaults to false, which means VNICs created in this subnet will automatically be assigned public IP addresses unless specified otherwise during instance launch or VNIC creation (with the `assignPublicIp` flag in [CreateVnicDetails](https://docs.cloud.oracle.com/iaas/api/#/en/iaas/20160918/CreateVnicDetails/)). If `prohibitPublicIpOnVnic` is set to true, VNICs created in this subnet cannot have public IP addresses (that is, it's a private subnet). Example: `true`
86-
* `route_table_id` - (Optional) The OCID of the route table the subnet will use. If you don't provide a value, the subnet uses the VCN's default route table.
87-
* `security_list_ids` - (Required) The OCIDs of the security list or lists the subnet will use. If you don't provide a value, the subnet uses the VCN's default security list. Remember that security lists are associated *with the subnet*, but the rules are applied to the individual VNICs in the subnet.
86+
* `route_table_id` - (Optional) (Updatable) The OCID of the route table the subnet will use. If you don't provide a value, the subnet uses the VCN's default route table.
87+
* `security_list_ids` - (Optional) (Updatable) The OCIDs of the security list or lists the subnet will use. If you don't provide a value, the subnet uses the VCN's default security list. Remember that security lists are associated *with the subnet*, but the rules are applied to the individual VNICs in the subnet.
8888
* `vcn_id` - (Required) The OCID of the VCN to contain the subnet.
8989

9090

0 commit comments

Comments
 (0)