Skip to content

Commit d8024b2

Browse files
author
jiangong
committed
add nsg_ids in ffs mount target
1 parent 1512fc6 commit d8024b2

9 files changed

+75
-5
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
## 3.54.1 (Unreleased)
1+
## 3.55.0 (Unreleased)
22

33
### Added
44
- Support Etag for ListObjects
5+
- Support for Network Security Groups in `oci_file_storage_mount_target` resource
56

67
## 3.54.0 (November 27, 2019)
78

examples/storage/fss/mount_target.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ resource "oci_file_storage_mount_target" "my_mount_target_1" {
1313
freeform_tags = {
1414
"Department" = "Finance"
1515
}
16+
17+
nsg_ids = ["${oci_core_network_security_group.test_network_security_group.id}"]
1618
}
1719

1820
resource "oci_file_storage_mount_target" "my_mount_target_2" {
@@ -28,6 +30,8 @@ resource "oci_file_storage_mount_target" "my_mount_target_2" {
2830
freeform_tags = {
2931
"Department" = "Accounting"
3032
}
33+
34+
nsg_ids = ["${oci_core_network_security_group.test_network_security_group.id}"]
3135
}
3236

3337
# Use export_set.tf config to update the size for a mount target

examples/storage/fss/network.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ resource "oci_core_route_table" "my_route_table" {
2626
}
2727

2828
resource "oci_core_subnet" "my_subnet" {
29+
depends_on = ["oci_core_network_security_group.test_network_security_group"]
2930
availability_domain = "${data.oci_identity_availability_domain.ad.name}"
3031
cidr_block = "${var.my_subnet_cidr}"
3132
display_name = "mysubnet"
@@ -35,3 +36,9 @@ resource "oci_core_subnet" "my_subnet" {
3536
security_list_ids = ["${oci_core_security_list.my_security_list.id}"]
3637
route_table_id = "${oci_core_route_table.my_route_table.id}"
3738
}
39+
40+
resource "oci_core_network_security_group" "test_network_security_group" {
41+
#Required
42+
compartment_id = "${var.compartment_ocid}"
43+
vcn_id = "${oci_core_vcn.my_vcn.id}"
44+
}

oci/file_storage_mount_target_resource.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ func FileStorageMountTargetResource() *schema.Resource {
6969
Computed: true,
7070
ForceNew: true,
7171
},
72+
"nsg_ids": {
73+
Type: schema.TypeSet,
74+
Optional: true,
75+
Computed: true,
76+
Set: literalTypeHashCodeForSets,
77+
Elem: &schema.Schema{
78+
Type: schema.TypeString,
79+
},
80+
},
7281

7382
// Computed
7483
"export_set_id": {
@@ -208,6 +217,20 @@ func (s *FileStorageMountTargetResourceCrud) Create() error {
208217
request.IpAddress = &tmp
209218
}
210219

220+
if nsgIds, ok := s.D.GetOkExists("nsg_ids"); ok {
221+
set := nsgIds.(*schema.Set)
222+
interfaces := set.List()
223+
tmp := make([]string, len(interfaces))
224+
for i := range interfaces {
225+
if interfaces[i] != nil {
226+
tmp[i] = interfaces[i].(string)
227+
}
228+
}
229+
if len(tmp) != 0 || s.D.HasChange("nsg_ids") {
230+
request.NsgIds = tmp
231+
}
232+
}
233+
211234
if subnetId, ok := s.D.GetOkExists("subnet_id"); ok {
212235
tmp := subnetId.(string)
213236
request.SubnetId = &tmp
@@ -273,6 +296,20 @@ func (s *FileStorageMountTargetResourceCrud) Update() error {
273296
tmp := s.D.Id()
274297
request.MountTargetId = &tmp
275298

299+
if nsgIds, ok := s.D.GetOkExists("nsg_ids"); ok {
300+
set := nsgIds.(*schema.Set)
301+
interfaces := set.List()
302+
tmp := make([]string, len(interfaces))
303+
for i := range interfaces {
304+
if interfaces[i] != nil {
305+
tmp[i] = interfaces[i].(string)
306+
}
307+
}
308+
if len(tmp) != 0 || s.D.HasChange("nsg_ids") {
309+
request.NsgIds = tmp
310+
}
311+
}
312+
276313
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "file_storage")
277314

278315
response, err := s.Client.UpdateMountTarget(context.Background(), request)
@@ -323,6 +360,12 @@ func (s *FileStorageMountTargetResourceCrud) SetData() error {
323360
s.D.Set("lifecycle_details", *s.Res.LifecycleDetails)
324361
}
325362

363+
nsgIds := []interface{}{}
364+
for _, item := range s.Res.NsgIds {
365+
nsgIds = append(nsgIds, item)
366+
}
367+
s.D.Set("nsg_ids", schema.NewSet(literalTypeHashCodeForSets, nsgIds))
368+
326369
s.D.Set("private_ip_ids", s.Res.PrivateIpIds)
327370

328371
s.D.Set("state", s.Res.LifecycleState)

oci/file_storage_mount_target_test.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ var (
4444
"freeform_tags": Representation{repType: Optional, create: map[string]string{"Department": "Finance"}, update: map[string]string{"Department": "Accounting"}},
4545
"hostname_label": Representation{repType: Optional, create: `hostnameLabel`},
4646
"ip_address": Representation{repType: Optional, create: `10.0.0.5`},
47+
"nsg_ids": Representation{repType: Optional, create: []string{`${oci_core_network_security_group.test_network_security_group.id}`}, update: []string{}},
4748
}
4849

49-
MountTargetResourceDependencies = generateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", Required, Create, representationCopyWithNewProperties(subnetRepresentation, map[string]interface{}{
50-
"availability_domain": Representation{repType: Required, create: `${lower("${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}")}`},
51-
"dns_label": Representation{repType: Required, create: `dnslabel`},
52-
})) +
50+
MountTargetResourceDependencies = generateResourceFromRepresentationMap("oci_core_network_security_group", "test_network_security_group", Required, Create, networkSecurityGroupRepresentation) +
51+
generateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", Required, Create, representationCopyWithNewProperties(subnetRepresentation, map[string]interface{}{
52+
"availability_domain": Representation{repType: Required, create: `${lower("${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}")}`},
53+
"dns_label": Representation{repType: Required, create: `dnslabel`},
54+
})) +
5355
generateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", Required, Create, representationCopyWithNewProperties(vcnRepresentation, map[string]interface{}{
5456
"dns_label": Representation{repType: Required, create: `dnslabel`},
5557
})) +
@@ -117,6 +119,7 @@ func TestFileStorageMountTargetResource_basic(t *testing.T) {
117119
resource.TestCheckResourceAttr(resourceName, "hostname_label", "hostnameLabel"),
118120
resource.TestCheckResourceAttrSet(resourceName, "id"),
119121
resource.TestCheckResourceAttr(resourceName, "ip_address", "10.0.0.5"),
122+
resource.TestCheckResourceAttr(resourceName, "nsg_ids.#", "1"),
120123
resource.TestCheckResourceAttr(resourceName, "private_ip_ids.#", "1"),
121124
resource.TestCheckResourceAttrSet(resourceName, "private_ip_ids.0"),
122125
resource.TestCheckResourceAttr(resourceName, "state", string(oci_file_storage.MountTargetLifecycleStateActive)),
@@ -151,6 +154,7 @@ func TestFileStorageMountTargetResource_basic(t *testing.T) {
151154
resource.TestCheckResourceAttr(resourceName, "hostname_label", "hostnameLabel"),
152155
resource.TestCheckResourceAttrSet(resourceName, "id"),
153156
resource.TestCheckResourceAttr(resourceName, "ip_address", "10.0.0.5"),
157+
resource.TestCheckResourceAttr(resourceName, "nsg_ids.#", "1"),
154158
resource.TestCheckResourceAttr(resourceName, "private_ip_ids.#", "1"),
155159
resource.TestCheckResourceAttr(resourceName, "state", string(oci_file_storage.MountTargetLifecycleStateActive)),
156160
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
@@ -180,6 +184,7 @@ func TestFileStorageMountTargetResource_basic(t *testing.T) {
180184
resource.TestCheckResourceAttr(resourceName, "hostname_label", "hostnameLabel"),
181185
resource.TestCheckResourceAttrSet(resourceName, "id"),
182186
resource.TestCheckResourceAttr(resourceName, "ip_address", "10.0.0.5"),
187+
resource.TestCheckResourceAttr(resourceName, "nsg_ids.#", "0"),
183188
resource.TestCheckResourceAttr(resourceName, "private_ip_ids.#", "1"),
184189
resource.TestCheckResourceAttr(resourceName, "state", string(oci_file_storage.MountTargetLifecycleStateActive)),
185190
resource.TestCheckResourceAttrSet(resourceName, "subnet_id"),
@@ -210,6 +215,7 @@ func TestFileStorageMountTargetResource_basic(t *testing.T) {
210215
resource.TestCheckResourceAttrSet(datasourceName, "mount_targets.0.export_set_id"),
211216
resource.TestCheckResourceAttr(datasourceName, "mount_targets.0.freeform_tags.%", "1"),
212217
resource.TestCheckResourceAttrSet(datasourceName, "mount_targets.0.id"),
218+
resource.TestCheckResourceAttr(datasourceName, "mount_targets.nsg_ids.#", "0"),
213219
resource.TestCheckResourceAttrSet(datasourceName, "mount_targets.0.private_ip_ids.#"),
214220
resource.TestCheckResourceAttr(datasourceName, "mount_targets.0.state", string(oci_file_storage.MountTargetLifecycleStateActive)),
215221
resource.TestCheckResourceAttrSet(datasourceName, "mount_targets.0.subnet_id"),

oci/file_storage_mount_targets_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ func (s *FileStorageMountTargetsDataSourceCrud) SetData() error {
152152
mountTarget["id"] = *r.Id
153153
}
154154

155+
mountTarget["nsg_ids"] = r.NsgIds
156+
155157
mountTarget["private_ip_ids"] = r.PrivateIpIds
156158

157159
mountTarget["state"] = r.LifecycleState

website/docs/d/file_storage_mount_targets.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ The following attributes are exported:
5959
* `freeform_tags` - 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"}`
6060
* `id` - The OCID of the mount target.
6161
* `lifecycle_details` - Additional information about the current 'lifecycleState'.
62+
* `nsg_ids` - A list of Network Security Group [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) associated with this mount target. A maximum of 5 is allowed. Setting this to an empty array after the list is created removes the mount target from all NSGs. For more information about NSGs, see [Security Rules](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securityrules.htm).
6263
* `private_ip_ids` - The OCIDs of the private IP addresses associated with this mount target.
6364
* `state` - The current state of the mount target.
6465
* `subnet_id` - The OCID of the subnet the mount target is in.

website/docs/r/file_storage_file_system.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ more than one mount target at a time.
2424
For information about access control and compartments, see
2525
[Overview of the IAM Service](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/overview.htm).
2626

27+
For information about Network Security Groups access control, see
28+
[Network Security Groups](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/networksecuritygroups.htm).
29+
2730
For information about availability domains, see [Regions and
2831
Availability Domains](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/regions.htm).
2932
To get a list of availability domains, use the

website/docs/r/file_storage_mount_target.html.markdown

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ resource "oci_file_storage_mount_target" "test_mount_target" {
5959
freeform_tags = {"Department"= "Finance"}
6060
hostname_label = "${var.mount_target_hostname_label}"
6161
ip_address = "${var.mount_target_ip_address}"
62+
nsg_ids = "${var.mount_target_nsg_ids}"
6263
}
6364
```
6465

@@ -77,6 +78,7 @@ The following arguments are supported:
7778

7879
Example: `files-1`
7980
* `ip_address` - (Optional) A private IP address of your choice. Must be an available IP address within the subnet's CIDR. If you don't specify a value, Oracle automatically assigns a private IP address from the subnet. Example: `10.0.3.3`
81+
* `nsg_ids` - (Optional) (Updatable) A list of Network Security Group [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) associated with this mount target. A maximum of 5 is allowed. Setting this to an empty array after the list is created removes the mount target from all NSGs. For more information about NSGs, see [Security Rules](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securityrules.htm).
8082
* `subnet_id` - (Required) The OCID of the subnet in which to create the mount target.
8183

8284

@@ -95,6 +97,7 @@ The following attributes are exported:
9597
* `freeform_tags` - 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"}`
9698
* `id` - The OCID of the mount target.
9799
* `lifecycle_details` - Additional information about the current 'lifecycleState'.
100+
* `nsg_ids` - A list of Network Security Group [OCIDs](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) associated with this mount target. A maximum of 5 is allowed. Setting this to an empty array after the list is created removes the mount target from all NSGs. For more information about NSGs, see [Security Rules](https://docs.cloud.oracle.com/iaas/Content/Network/Concepts/securityrules.htm).
98101
* `private_ip_ids` - The OCIDs of the private IP addresses associated with this mount target.
99102
* `state` - The current state of the mount target.
100103
* `subnet_id` - The OCID of the subnet the mount target is in.

0 commit comments

Comments
 (0)