Skip to content

Commit 141d4b6

Browse files
authored
Merge pull request #143 from NetApp/update_terraform_fsxn
Updated to use Secrets Manager, and some other updates.
2 parents 70d1fb9 + 8aeb80f commit 141d4b6

File tree

8 files changed

+430
-238
lines changed

8 files changed

+430
-238
lines changed

Terraform/deploy-fsx-ontap/module/README.md

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,23 @@ Calling this terraform module will result the following:
2121
* Create a new AWS Security Group in your VPC with the following rules:
2222
- **Ingress** allow all ICMP traffic
2323
- **Ingress** allow nfs port 111 (both TCP and UDP)
24-
- **Ingress** allow cifc TCP port 139
24+
- **Ingress** allow cifs TCP port 139
2525
- **Ingress** allow snmp ports 161-162 (both TCP and UDP)
2626
- **Ingress** allow smb cifs TCP port 445
27-
- **Ingress** alloe bfs mount port 635 (both TCP and UDP)
27+
- **Ingress** allow nfs mount port 635 (both TCP and UDP)
28+
- **Ingress** allow kerberos TCP port 749
29+
- **Ingress** allow nfs port 2049 (both TCP and UDP)
30+
- **Ingress** allow nfs lock and monitoring 4045-4046 (both TCP and UDP)
31+
- **Ingress** allow nfs quota TCP 4049
32+
- **Ingress** allow Snapmirror Intercluster communication TCP port 11104
33+
- **Ingress** allow Snapmirror data transfer TCP port 11105
34+
- **Ingress** allow ssh port 22
35+
- **Ingress** allow https port 443
2836
- **Egress** allow all traffic
2937
* Create a new FSx for Netapp ONTAP file-system in your AWS account named "_terraform-fsxn_". The file-system will be created with the following configuration parameters:
3038
* 1024Gb of storage capacity
3139
* Multi AZ deployment type
32-
* 256Mbps of throughput capacity
40+
* 128Mbps of throughput capacity
3341

3442
* Create a Storage Virtual Maching (SVM) in this new file-system named "_first_svm_"
3543
* Create a new FlexVol volume in this SVM named "_vol1_" with the following configuration parameters:
@@ -49,8 +57,8 @@ Calling this terraform module will result the following:
4957

5058
| Name | Version |
5159
|------|---------|
52-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.6 |
53-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.25 |
60+
| terraform | >= 1.6.6 |
61+
| aws provider | >= 5.25 |
5462

5563
### AWS Account Setup
5664

@@ -68,24 +76,23 @@ Calling this terraform module will result the following:
6876
> [!NOTE]
6977
> In this sample, the AWS Credentials were configured through [AWS CLI](https://aws.amazon.com/cli/), which adds them to a shared configuration file (option 4 above). Therefore, this documentation only provides guidance on setting-up the AWS credentials with shared configuration file using AWS CLI.
7078
71-
#### Configure AWS Credentials using AWS CLI
79+
#### Configure AWS Credentials using AWS CLI
7280

73-
The AWS Provider can source credentials and other settings from the shared configuration and credentials files. By default, these files are located at `$HOME/.aws/config` and `$HOME/.aws/credentials` on Linux and macOS, and `"%USERPROFILE%\.aws\credentials"` on Windows.
81+
The AWS Provider can source credentials and other settings from the shared configuration and credentials files. By default, these files are located at `$HOME/.aws/config` and `$HOME/.aws/credentials` on Linux and macOS, and `"%USERPROFILE%\.aws\credentials"` on Windows.
7482

75-
There are several ways to set your credentials and configuration setting using AWS CLI. We will use [`aws configure`](https://docs.aws.amazon.com/cli/latest/reference/configure/index.html) command:
83+
There are several ways to set your credentials and configuration setting using AWS CLI. We will use [`aws configure`](https://docs.aws.amazon.com/cli/latest/reference/configure/index.html) command:
7684

77-
Run the following command to quickly set and view your credentails, region, and output format. The following example shows sample values:
85+
Run the following command to quickly set and view your credentails, region, and output format. The following example shows sample values:
7886

79-
```shell
80-
$ aws configure
81-
AWS Access Key ID [None]: < YOUR-ACCESS-KEY-ID >
82-
AWS Secret Access Key [None]: < YOUR-SECRET-ACCESS-KE >
83-
Default region name [None]: < YOUR-PREFERRED-REGION >
84-
Default output format [None]: json
85-
```
86-
87-
To list configuration data, use the [`aws configire list`](https://docs.aws.amazon.com/cli/latest/reference/configure/list.html) command. This command lists the profile, access key, secret key, and region configuration information used for the specified profile. For each configuration item, it shows the value, where the configuration value was retrieved, and the configuration variable name.
87+
```shell
88+
$ aws configure
89+
AWS Access Key ID [None]: < YOUR-ACCESS-KEY-ID >
90+
AWS Secret Access Key [None]: < YOUR-SECRET-ACCESS-KE >
91+
Default region name [None]: < YOUR-PREFERRED-REGION >
92+
Default output format [None]: json
93+
```
8894

95+
To list configuration data, use the [`aws configire list`](https://docs.aws.amazon.com/cli/latest/reference/configure/list.html) command. This command lists the profile, access key, secret key, and region configuration information used for the specified profile. For each configuration item, it shows the value, where the configuration value was retrieved, and the configuration variable name.
8996

9097
## Usage
9198

@@ -250,27 +257,27 @@ terraform apply -y
250257
251258
| Name | Description | Type | Default | Required |
252259
|------|-------------|------|---------|:--------:|
253-
| fsx_admin_password | The ONTAP administrative password for the fsxadmin user that you can use to administer your file system using the ONTAP CLI and REST API | `string` | n/a | yes |
254260
| backup_retention_days | The number of days to retain automatic backups. Setting this to 0 disables automatic backups. You can retain automatic backups for a maximum of 90 days. | `number` | `0` | no |
255-
| cidr_for_sg | cide block to be used for the ingress rules | `string` | `"0.0.0.0/0"` | no |
256-
| create_sg | Determines whether the SG should be deployed as part of this execution or not | `bool` | `false` | no |
261+
| cidr_for_sg | cidr block to be used for the created security ingress rules. | `string` | `"10.0.0.0/8"` | no |
262+
| create_sg | Determines whether the SG should be deployed as part of this execution or not | `bool` | `true` | no |
257263
| daily_backup_start_time | A recurring daily time, in the format HH:MM. HH is the zero-padded hour of the day (0-23), and MM is the zero-padded minute of the hour. Requires automatic_backup_retention_days to be set. | `string` | `"00:00"` | no |
258-
| disk_iops_configuration | The SSD IOPS configuration for the Amazon FSx for NetApp ONTAP file system | `map(any)` | `null` | no |
264+
| disk_iops_configuration | The SSD IOPS configuration for the Amazon FSx for NetApp ONTAP file system | `map(any)` | <pre>{<br> "mode": "AUTOMATIC"<br>}</pre> | no |
259265
| fsx_capacity_size_gb | The storage capacity (GiB) of the FSxN file system. Valid values between 1024 and 196608 | `number` | `1024` | no |
260266
| fsx_deploy_type | The filesystem deployment type. Supports MULTI_AZ_1 and SINGLE_AZ_1 | `string` | `"MULTI_AZ_1"` | no |
261267
| fsx_maintenance_start_time | The preferred start time (in d:HH:MM format) to perform weekly maintenance, in the UTC time zone. | `string` | `"1:00:00"` | no |
262-
| fsx_name | The deployed filesystem name | `string` | `"terraform-fsxn"` | no |
263-
| fsx_subnets | A list of IDs for the subnets that the file system will be accessible from. Up to 2 subnets can be provided. | `map(any)` | <pre>{<br> "primarysub": "",<br> "secondarysub": ""<br>}</pre> | no |
264-
| fsx_tput_in_MBps | The throughput capacity (in MBps) for the file system. Valid values are 128, 256, 512, 1024, 2048, and 4096. | `number` | `256` | no |
268+
| fsx_secret_name | The name of the secure where the FSxN passwood is stored | `string` | `""` | no |
269+
| fsx_subnets | The subnets from where the file system will be accessible from. For MULTI_AZ_1 deployment type, provide both primvary and secondary subnets. For SINGLE_AZ_1 deployment type, only the primary subnet is used. | `map(string)` | <pre>{<br> "primarysub": "subnet-111111111",<br> "secondarysub": "subnet-222222222"<br>}</pre> | no |
270+
| fsx_tput_in_MBps | The throughput capacity (in MBps) for the file system. Valid values are 128, 256, 512, 1024, 2048, and 4096. | `number` | `128` | no |
265271
| kms_key_id | ARN for the KMS Key to encrypt the file system at rest, Defaults to an AWS managed KMS Key. | `string` | `null` | no |
266-
| root_vol_sec_style | Specifies the root volume security style, Valid values are UNIX, NTFS, and MIXED. All volumes created under this SVM will inherit the root security style unless the security style is specified on the volume. | `string` | `"UNIX"` | no |
272+
| root_vol_sec_style | Specifies the root volume security style, Valid values are UNIX, NTFS, and MIXED (although MIXED is not recommended). All volumes created under this SVM will inherit the root security style unless the security style is specified on the volume. | `string` | `"UNIX"` | no |
267273
| route_table_ids | Specifies the VPC route tables in which your file system's endpoints will be created. You should specify all VPC route tables associated with the subnets in which your clients are located. By default, Amazon FSx selects your VPC's default route table. | `list(any)` | `null` | no |
268-
| storage_type | The filesystem storage type | `string` | `"SSD"` | no |
274+
| security_group_id | If you are not creating the SG, provide the ID of the SG to be used | `string` | `""` | no |
275+
| source_security_group_id | The ID of the security group to allow access to the FSxN file system. | `string` | `""` | no |
269276
| svm_name | The name of the Storage Virtual Machine | `string` | `"first_svm"` | no |
270277
| tags | Tags to be applied to the resources | `map(any)` | <pre>{<br> "Name": "terraform-fsxn"<br>}</pre> | no |
271278
| vol_info | Details for the volume creation | `map(any)` | <pre>{<br> "bypass_sl_retention": false,<br> "cooling_period": 31,<br> "copy_tags_to_backups": false,<br> "efficiency": true,<br> "junction_path": "/vol1",<br> "sec_style": "UNIX",<br> "size_mg": 1024,<br> "skip_final_backup": false,<br> "tier_policy_name": "AUTO",<br> "vol_name": "vol1",<br> "vol_type": "RW"<br>}</pre> | no |
272279
| vol_snapshot_policy | Specifies the snapshot policy for the volume | `map(any)` | `null` | no |
273-
| vpc_id | The ID of the VPC in which the FSxN fikesystem should be deployed | `string` | `"vpc-111111111"` | no |
280+
| vpc_id | The ID of the VPC in which the FSxN fikesystem should be deployed | `string` | `""` | no |
274281
275282
### Outputs
276283
@@ -297,4 +304,4 @@ See the License for the specific language governing permissions and limitations
297304
298305
<!-- END_TF_DOCS -->
299306
300-
© 2024 NetApp, Inc. All Rights Reserved.
307+
© 2024 NetApp, Inc. All Rights Reserved.
Lines changed: 33 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,162 +1,52 @@
1-
// TODO add SG rule for SnapMirror
2-
31
# Copyright (c) NetApp, Inc.
42
# SPDX-License-Identifier: Apache-2.0
53

6-
/*
7-
The following resources are a Security Group followed by ingress and egress rules for FSx ONTAP.
8-
The Security Group is not required for deploying FSx ONTAP, but is included here for completeness.
9-
10-
- If you wish to skip this resource, pass the variable "create_sg" as false to the module block. Otherwise, pass true.
11-
12-
- If you wish to use the Security Group, choose the relevant source for the ingress rules as cidr block and pass the variable "cidr_for_sg" to the module block.
13-
14-
Note that a source reference for a Security Group is optional, but is considered to be a best practice.
15-
The rules below are just a suggestion for basic functionality.
16-
*/
17-
18-
resource "aws_security_group" "fsx_sg" {
19-
count = var.create_sg ? 1 : 0
20-
name = "fsx_sg"
21-
description = "Allow FSx ONTAP required ports"
22-
vpc_id = var.vpc_id
23-
}
24-
25-
resource "aws_vpc_security_group_ingress_rule" "all_icmp" {
26-
count = var.create_sg ? 1 : 0
27-
security_group_id = aws_security_group.fsx_sg[count.index].id
28-
description = "Allow all ICMP traffic"
29-
cidr_ipv4 = "0.0.0.0/0"
30-
from_port = -1
31-
to_port = -1
32-
ip_protocol = "icmp"
33-
}
34-
35-
resource "aws_vpc_security_group_ingress_rule" "nfs_tcp" {
36-
count = var.create_sg ? 1 : 0
37-
security_group_id = aws_security_group.fsx_sg[count.index].id
38-
description = "Remote procedure call for NFS"
39-
cidr_ipv4 = var.cidr_for_sg
40-
from_port = 111
41-
to_port = 111
42-
ip_protocol = "tcp"
43-
}
44-
45-
resource "aws_vpc_security_group_ingress_rule" "nfs_udp" {
46-
count = var.create_sg ? 1 : 0
47-
security_group_id = aws_security_group.fsx_sg[count.index].id
48-
description = "Remote procedure call for NFS"
49-
cidr_ipv4 = var.cidr_for_sg
50-
from_port = 111
51-
to_port = 111
52-
ip_protocol = "udp"
53-
}
54-
55-
resource "aws_vpc_security_group_ingress_rule" "cifs" {
56-
count = var.create_sg ? 1 : 0
57-
security_group_id = aws_security_group.fsx_sg[count.index].id
58-
description = "NetBIOS service session for CIFS"
59-
cidr_ipv4 = var.cidr_for_sg
60-
from_port = 139
61-
to_port = 139
62-
ip_protocol = "tcp"
63-
}
64-
65-
resource "aws_vpc_security_group_ingress_rule" "snmp_tcp" {
66-
count = var.create_sg ? 1 : 0
67-
security_group_id = aws_security_group.fsx_sg[count.index].id
68-
description = "Simple network management protocol for log collection"
69-
cidr_ipv4 = var.cidr_for_sg
70-
from_port = 161
71-
to_port = 162
72-
ip_protocol = "tcp"
73-
}
74-
75-
resource "aws_vpc_security_group_ingress_rule" "snmp_udp" {
76-
count = var.create_sg ? 1 : 0
77-
security_group_id = aws_security_group.fsx_sg[count.index].id
78-
description = "Simple network management protocol for log collection"
79-
cidr_ipv4 = var.cidr_for_sg
80-
from_port = 161
81-
to_port = 162
82-
ip_protocol = "udp"
83-
}
84-
85-
resource "aws_vpc_security_group_ingress_rule" "smb_cifs" {
86-
count = var.create_sg ? 1 : 0
87-
security_group_id = aws_security_group.fsx_sg[count.index].id
88-
description = "Microsoft SMB/CIFS over TCP with NetBIOS framing"
89-
cidr_ipv4 = var.cidr_for_sg
90-
from_port = 445
91-
to_port = 445
92-
ip_protocol = "tcp"
93-
}
94-
95-
resource "aws_vpc_security_group_ingress_rule" "nfs_mount_tcp" {
96-
count = var.create_sg ? 1 : 0
97-
security_group_id = aws_security_group.fsx_sg[count.index].id
98-
description = "NFS mount"
99-
cidr_ipv4 = var.cidr_for_sg
100-
from_port = 635
101-
to_port = 635
102-
ip_protocol = "tcp"
103-
}
104-
105-
resource "aws_vpc_security_group_ingress_rule" "nfs_mount_udp" {
106-
count = var.create_sg ? 1 : 0
107-
security_group_id = aws_security_group.fsx_sg[count.index].id
108-
description = "NFS mount"
109-
cidr_ipv4 = var.cidr_for_sg
110-
from_port = 635
111-
to_port = 635
112-
ip_protocol = "udp"
113-
}
114-
115-
resource "aws_vpc_security_group_egress_rule" "allow_all_traffic" {
116-
count = var.create_sg ? 1 : 0
117-
security_group_id = aws_security_group.fsx_sg[count.index].id
118-
cidr_ipv4 = "0.0.0.0/0"
119-
ip_protocol = "-1"
120-
}
121-
1224
/*
123-
The following resources are for deploying a complete FSx ONTAP file system.
124-
The code below deploys the following resources in this order:
125-
1. A file system
126-
2. A storage virtual machine
127-
3. A volume within the storage virtual machine
128-
129-
Every resource include both optional and required parameters, separated by a comment line.
130-
Feel free to add or remove optional parameters as needed.
131-
The current settings are just a suggestion for basic functionality.
132-
*/
5+
The following resources are for deploying a complete FSx ONTAP file system.
6+
The code below deploys the following resources in this order:
7+
1. A file system
8+
2. A storage virtual machine
9+
3. A volume within the storage virtual machine
10+
11+
Every resource include both optional and required parameters, separated by a comment line.
12+
Feel free to add or remove optional parameters as needed.
13+
*/
13314

13415
resource "aws_fsx_ontap_file_system" "terraform-fsxn" {
13516
// REQUIRED PARAMETERS
136-
subnet_ids = [var.fsx_subnets["primarysub"], var.fsx_subnets["secondarysub"]]
17+
subnet_ids = (var.fsx_deploy_type == "MULTI_AZ_1" ? [var.fsx_subnets["primarysub"], var.fsx_subnets["secondarysub"]] : [var.fsx_subnets["primarysub"]])
13718
preferred_subnet_id = var.fsx_subnets["primarysub"]
13819

13920
// OPTIONAL PARAMETERS
14021
storage_capacity = var.fsx_capacity_size_gb
141-
security_group_ids = var.create_sg ? [element(aws_security_group.fsx_sg.*.id, 0)] : []
22+
security_group_ids = var.create_sg ? [element(aws_security_group.fsx_sg.*.id, 0)] : [var.security_group_id]
14223
deployment_type = var.fsx_deploy_type
14324
throughput_capacity = var.fsx_tput_in_MBps
14425
weekly_maintenance_start_time = var.fsx_maintenance_start_time
14526
kms_key_id = var.kms_key_id
14627
automatic_backup_retention_days = var.backup_retention_days
14728
daily_automatic_backup_start_time = var.daily_backup_start_time
148-
storage_type = var.storage_type
149-
fsx_admin_password = var.fsx_admin_password
150-
route_table_ids = var.route_table_ids
151-
tags = var.tags
29+
fsx_admin_password = data.aws_secretsmanager_secret_version.fsx_password.secret_string
30+
route_table_ids = var.route_table_ids
31+
tags = var.tags
15232
dynamic "disk_iops_configuration" {
15333
for_each = var.disk_iops_configuration != null ? [var.disk_iops_configuration] : []
15434
content {
15535
iops = disk_iops_configuration.value["iops"]
15636
mode = disk_iops_configuration.value["mode"]
15737
}
15838
}
159-
# endpoint_ip_address_range = ""
39+
40+
lifecycle {
41+
precondition {
42+
condition = !var.create_sg || (var.cidr_for_sg != "" && var.source_security_group_id == "" || var.cidr_for_sg == "" && var.source_security_group_id != "")
43+
error_message = "You must specify EITHER cidr_block OR source_security_group_id when creating a security group, not both."
44+
}
45+
precondition {
46+
condition = var.create_sg || var.security_group_id != ""
47+
error_message = "You must specify a security group ID when not creating a security group."
48+
}
49+
}
16050
}
16151

16252
resource "aws_fsx_ontap_storage_virtual_machine" "mysvm" {
@@ -166,7 +56,6 @@ resource "aws_fsx_ontap_storage_virtual_machine" "mysvm" {
16656

16757
// OPTIONAL PARAMETERS
16858
root_volume_security_style = var.root_vol_sec_style
169-
tags = var.tags
17059
# active_directory_configuration {}
17160
}
17261

@@ -190,5 +79,12 @@ resource "aws_fsx_ontap_volume" "myvol" {
19079
skip_final_backup = var.vol_info["skip_final_backup"]
19180
# snaplock_configuration {}
19281
# snapshot_policy {}
193-
tags = var.tags
82+
}
83+
#
84+
# The next two data blocks retrieve the secret from Secrets Manager.
85+
data "aws_secretsmanager_secret" "fsx_secret" {
86+
name = var.fsx_secret_name
87+
}
88+
data "aws_secretsmanager_secret_version" "fsx_password" {
89+
secret_id = data.aws_secretsmanager_secret.fsx_secret.id
19490
}

0 commit comments

Comments
 (0)