Skip to content

Commit f003017

Browse files
authored
Merge pull request #135 from NetApp/update_terraform_fsxn
Refreshed it, and changed it to use AWS's secret manager
2 parents 0f2a8da + da107ae commit f003017

File tree

4 files changed

+152
-110
lines changed

4 files changed

+152
-110
lines changed

Terraform/deploy-fsx-ontap/README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
## Repository Overview
2+
This repostory contians two different ways of leveraging Terraform to deploy an FSx ONTAP instance in AWS.
3+
The first method is a standalone module that can be cloned and run locally.
4+
The second method is a callable module that can be used in a larger Terraform project.
25

3-
- [Callable terraform module for FSxN creation](/Terraform/deploy-fsx-ontap/module)
46
- [Standalone terraform module to clone and run locally](/Terraform/deploy-fsx-ontap/standalone-module)
7+
- [Callable terraform module for FSxN creation](/Terraform/deploy-fsx-ontap/module)
58

69
## Author Information
710

@@ -17,4 +20,4 @@ Unless required by applicable law or agreed to in writing, software distributed
1720

1821
See the License for the specific language governing permissions and limitations under the License.
1922

20-
© 2024 NetApp, Inc. All Rights Reserved.
23+
© 2024 NetApp, Inc. All Rights Reserved.

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

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,23 @@
11
# Deploy an ONTAP FSx file-system using Terraform
2-
This sample demonstrates how to deploy an FSx for NetApp ONTAP file system, including an SVM and a FlexVolume in that file system, using AWS Terraform provider in a standalone Terraform module.
3-
Follow the instructions below to use this sample in your own environment.
4-
52
## Table of Contents
63
* [Introduction](#introduction)
4+
* [Repository Overview](#repository-overview)
5+
* [What to expect](#what-to-expect)
76
* [Prerequisites](#prerequisites)
87
* [Usage](#usage)
9-
* [Repository Overview](#repository-overview-1)
108
* [Author Information](#author-information)
119
* [License](#license)
1210

1311
## Introduction
12+
This sample demonstrates how to deploy an FSx for NetApp ONTAP file system, including an SVM and a FlexVolume in that file system, using AWS Terraform provider in a standalone Terraform module.
13+
Follow the instructions below to use this sample in your own environment.
1414
### Repository Overview
15-
This is a standalone Terraform configutation repository that contains the following files:
15+
This is a standalone Terraform configuration repository that contains the following files:
1616
* **main.tf** - The main set of configuration for this terraform sample
17-
1817
* **variables.tf** - Contains the variable definitions and assignments for this sample. Exported values will override any of the variables in this file.
19-
2018
* **output.tf** - Contains output declarations of the resources created by this Terraform module. Terraform stores output values in the configuration's state file
2119

2220
### What to expect
23-
2421
Running this terraform sample will result the following:
2522
* Create a new AWS Security Group in your VPC with the following rules:
2623
- **Ingress** allow all ICMP traffic
@@ -33,7 +30,7 @@ Running this terraform sample will result the following:
3330
* 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:
3431
* 1024Gb of storage capacity
3532
* Multi AZ deployment type
36-
* 256Mbps of throughput capacity
33+
* 128Mbps of throughput capacity
3734

3835
* Create a Storage Virtual Maching (SVM) in this new file-system named "_first_svm_"
3936
* Create a new FlexVol volume in this SVM named "_vol1_" with the following configuration parameters:
@@ -43,7 +40,7 @@ Running this terraform sample will result the following:
4340
* post-delete backup disabled
4441

4542
> [!NOTE]
46-
> All of the above configuration parameters can be modified for your preference by assigning your own values in the `variables.tf` file!
43+
> Even though this Terraform code is set up to use AWS SecretsManager to retrieve the FSxN password, it will store the password in its `state database`. Therefore, it is assumed you have properly secured that database so that unauthorized personal can't access the password.
4744
4845
## Prerequisites
4946

@@ -54,8 +51,8 @@ Running this terraform sample will result the following:
5451

5552
| Name | Version |
5653
|------|---------|
57-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.6.6 |
58-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.25 |
54+
| terraform | >= 1.6.6 |
55+
| aws provider | >= 5.25 |
5956

6057
### AWS Account Setup
6158

@@ -73,41 +70,41 @@ Running this terraform sample will result the following:
7370
> [!NOTE]
7471
> 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.
7572
76-
#### Configure AWS Credentials using AWS CLI
77-
78-
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.
73+
#### Configure AWS Credentials using AWS CLI
7974

80-
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:
75+
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.
8176

82-
Run the following command to quickly set and view your credentails, region, and output format. The following example shows sample values:
77+
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:
8378

84-
```shell
85-
$ aws configure
86-
AWS Access Key ID [None]: < YOUR-ACCESS-KEY-ID >
87-
AWS Secret Access Key [None]: < YOUR-SECRET-ACCESS-KE >
88-
Default region name [None]: < YOUR-PREFERRED-REGION >
89-
Default output format [None]: json
90-
```
91-
92-
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.
79+
Run the following command to quickly set and view your credentails, region, and output format. The following example shows sample values:
9380

81+
```shell
82+
$ aws configure
83+
AWS Access Key ID [None]: < YOUR-ACCESS-KEY-ID >
84+
AWS Secret Access Key [None]: < YOUR-SECRET-ACCESS-KE >
85+
Default region name [None]: < YOUR-PREFERRED-REGION >
86+
Default output format [None]: json
87+
```
9488

89+
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,
90+
access key, secret key, and region configuration information used for the specified profile. For each configuration item, it shows the value, where the configuration
91+
value was retrieved, and the configuration variable name.
9592

9693
## Usage
9794

98-
#### 1. Clone the repository
95+
### 1. Clone the repository
9996
In your server's terminal, navigate to the location where you wish to store this Terraform repository, and clone the repository using your preferred authentication type. In this example we are using HTTPS clone:
10097

10198
```shell
102-
git clone https://github.com/NetApp/FSxN-Samples.git
99+
git clone https://github.com/NetApp/FSx-ONTAP-samples-scripts.git
103100
```
104101

105-
#### 2. Navigate to the directory
102+
### 2. Navigate to the directory
106103
```shell
107-
cd terraform_deployment
104+
cd Terraform/fsx-ontap-filesystem/standalone-module
108105
```
109106

110-
#### 3. Initialize Terraform
107+
### 3. Initialize Terraform
111108
This directory represents a standalone Terraform module. Run the following command to initialize the module and install all dependencies:
112109
```shell
113110
terraform init
@@ -134,22 +131,23 @@ commands will detect it and remind you to do so if necessary.
134131
```
135132
You can see that Terraform recognizes the modules required by our configuration: `hashicorp/aws`.
136133
137-
#### 4. Update Variables
134+
### 4. Update Variables
138135
139-
a. Open the **`variables.tf`** file in your preferred text editor. Update the values of the variables to match your preferences and save the file. This will ensure that the Terraform code deploys resources according to your specifications.
136+
- Open the **`variables.tf`** file in your preferred text editor. Update the values of the variables to match your
137+
preferences and save the file. This will ensure that the Terraform code deploys resources according to your specifications.
140138
141139
**Make sure to replace the values with ones that match your AWS environment and needs.**
142140
143-
b. modify the remaining optional variables in the **`main.tf`** file and remove commenting where needed according to the explenations in-line.
141+
- Modify the remaining optional variables in the **`main.tf`** file and remove commenting where needed according to the explanations in-line.
144142
145-
#### 5. Create a Terraform plan
143+
### 5. Create a Terraform plan
146144
Run the following command to create an execution plan, which lets you preview the changes that Terraform plans to make to your infrastructure:
147145
```shell
148146
terraform plan
149147
```
150148
Ensure that the proposed changes match what you expected before you apply the changes!
151149
152-
#### 6. Apply the Terraform plan
150+
### 6. Apply the Terraform plan
153151
Run the following command to execute the Terrafom code and apply the changes proposed in the `plan` step:
154152
```shell
155153
terraform apply
@@ -164,20 +162,23 @@ terraform apply
164162
| Name | Version |
165163
|------|---------|
166164
| aws | 5.25.0 |
165+
| aws.secrets | 5.25.0 |
167166
168167
### Inputs
169168
170169
| Name | Description | Type | Default | Required |
171170
|------|-------------|------|---------|:--------:|
172-
| 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` | `"password"` | no |
173-
| fsx_capacity_size_gb | The storage capacity (GiB) of the FSxN file system. Valid values between 1024 and 196608 | `number` | `1024` | no |
171+
| aws_secretsmanager_region | The AWS region where the secret is stored. | `string` | `"us-east-2"` | no |
172+
| fsx_capacity_size_gb | The storage capacity (GiB) of the FSxN file system. Valid values between 1024 and 196608. | `number` | `1024` | no |
174173
| fsx_deploy_type | The filesystem deployment type. Supports MULTI_AZ_1 and SINGLE_AZ_1 | `string` | `"MULTI_AZ_1"` | no |
175174
| fsx_name | The deployed filesystem name | `string` | `"terraform-fsxn"` | no |
176-
| 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 |
177-
| 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 |
175+
| fsx_region | The AWS region where the FSxN file system to be deployed. | `string` | `"us-west-2"` | no |
176+
| fsx_secret_name | The name of the AWS SecretManager secret that holds 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` | `"fsx_secret"` | no |
177+
| 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": "subnet-22222222",<br> "secondarysub": "subnet-22222222"<br>}</pre> | no |
178+
| 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 |
178179
| svm_name | The name of the Storage Virtual Machine | `string` | `"first_svm"` | no |
179180
| vol_info | Details for the volume creation | `map(any)` | <pre>{<br> "cooling_period": 31,<br> "efficiency": true,<br> "junction_path": "/vol1",<br> "size_mg": 1024,<br> "tier_policy_name": "AUTO",<br> "vol_name": "vol1"<br>}</pre> | no |
180-
| vpc_id | The ID of the VPC in which the FSxN fikesystem should be deployed | `string` | `"vpc-111111111"` | no |
181+
| vpc_id | The ID of the VPC in which the FSxN fikesystem should be deployed | `string` | `"vpc-11111111"` | no |
181182
182183
### Outputs
183184
@@ -204,4 +205,4 @@ See the License for the specific language governing permissions and limitations
204205
205206
<!-- END_TF_DOCS -->
206207
207-
© 2024 NetApp, Inc. All Rights Reserved.
208+
© 2024 NetApp, Inc. All Rights Reserved.

Terraform/deploy-fsx-ontap/standalone-module/main.tf

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
1-
21
terraform {
32
required_providers {
43
aws = {
54
source = "hashicorp/aws"
65
version = "5.25.0"
76
}
87
}
9-
108
}
11-
9+
#
10+
# Define a default provider.
11+
provider "aws" {
12+
region = var.fsx_region
13+
}
14+
#
15+
# Since the Secrets Manager might be in a different region, create a separate provider for it.
1216
provider "aws" {
13-
region = "us-west-2"
17+
alias = "secrets"
18+
region = var.aws_secretsmanager_region
1419
}
1520

1621
/*
17-
The following resources are a Security Group followed by ingress and egress rules for FSx ONTAP.
18-
The Security Group is not required for deploying FSx ONTAP, but is included here for completeness.
19-
20-
- If you wish to skip this resource, comment out the resource blocks of the Security Group and the rules.
21-
22-
- If you wish to use the Security Group, choose the relevant source for the ingress rules (can be either cidr block or security group id)
23-
and modify/uncomment the relevant line in the resource block. Make sure you add your specific value as well.
24-
Note that currently all rules are configured for source cidr: 10.0.0.0/8
25-
26-
Note that a source reference for a Security Group is optional, but is considered to be a best practice.
27-
Feel free to add, remove, or change the rules as needed. The rules below are just a suggestion for basic functionality.
28-
*/
29-
22+
* The following resources are a Security Group followed by ingress and egress rules for FSx ONTAP.
23+
* The Security Group is not required for deploying FSx ONTAP, but is included here for completeness.
24+
*
25+
* - If you wish to skip this resource, comment out the resource blocks of the Security Group and the rules.
26+
*
27+
* - If you wish to use the Security Group, choose the relevant source for the ingress rules (can be either cidr block or security group id)
28+
* and modify/uncomment the relevant line in the resource block. Make sure you add your specific value as well.
29+
* Note that currently all rules are configured for source cidr: 10.0.0.0/8
30+
*
31+
* Note that a source reference for a Security Group is optional, but is considered to be a best practice.
32+
* Feel free to add, remove, or change the rules as needed. The rules below are just a suggestion for basic functionality.
33+
*/
3034
resource "aws_security_group" "fsx_sg" {
3135
name = "fsx_sg"
3236
description = "Allow FSx ONTAP required ports"
@@ -129,32 +133,32 @@ resource "aws_vpc_security_group_egress_rule" "allow_all_traffic" {
129133
}
130134

131135
/*
132-
The following resources are for deploying a complete FSx ONTAP file system.
133-
The code below deploys the following resources in this order:
134-
1. A file system
135-
2. A storage virtual machine
136-
3. A volume within the storage virtual machine
137-
138-
Every resource include both optional and required parameters, separated by a comment line.
139-
Feel free to add or remove optional parameters as needed.
140-
The current settings are just a suggestion for basic functionality.
141-
*/
142-
136+
* The following resources are for deploying a complete FSx ONTAP file system.
137+
* The code below deploys the following resources in this order:
138+
* 1. A file system
139+
* 2. A storage virtual machine
140+
* 3. A volume within the storage virtual machine
141+
*
142+
* Every resource include both optional and required parameters, separated by a comment line.
143+
* Feel free to add or remove optional parameters as needed.
144+
* The current settings are just a suggestion for basic functionality.
145+
*/
143146
resource "aws_fsx_ontap_file_system" "terraform-fsxn" {
144147
// REQUIRED PARAMETERS
145-
// for SINGLE_AZ deployment, remove the "secondarysub" from the list of subnet_ids
146-
subnet_ids = [var.fsx_subnets["primarysub"], var.fsx_subnets["secondarysub"]]
148+
// For SINGLE_AZ deployment, only the primary subnet can be specified.
149+
subnet_ids = var.fsx_deploy_type == "MULTI_AZ_1" ? [var.fsx_subnets["primarysub"], var.fsx_subnets["secondarysub"]] : [var.fsx_subnets["primarysub"]]
147150
preferred_subnet_id = var.fsx_subnets["primarysub"]
148151

149152
// OPTIONAL PARAMETERS
150153
storage_capacity = var.fsx_capacity_size_gb
151154
security_group_ids = [aws_security_group.fsx_sg.id]
152155
deployment_type = var.fsx_deploy_type
153156
throughput_capacity = var.fsx_tput_in_MBps
154-
fsx_admin_password = var.fsx_admin_password
157+
fsx_admin_password = data.aws_secretsmanager_secret_version.fsx_password.secret_string
155158
tags = {
156159
Name = var.fsx_name
157160
}
161+
// Additional optional parameters that you may want to specify:
158162
# weekly_maintenance_start_time = "00:00:00"
159163
# kms_key_id = ""
160164
# automatic_backup_retention_days = 0
@@ -166,7 +170,8 @@ resource "aws_fsx_ontap_file_system" "terraform-fsxn" {
166170
# route_table_ids = []
167171
# throughput_capacity_per_ha_pair = 0
168172
}
169-
173+
#
174+
# Define a storage virtual machine.
170175
resource "aws_fsx_ontap_storage_virtual_machine" "mysvm" {
171176
// REQUIRED PARAMETERS
172177
file_system_id = aws_fsx_ontap_file_system.terraform-fsxn.id
@@ -175,9 +180,10 @@ resource "aws_fsx_ontap_storage_virtual_machine" "mysvm" {
175180
// OPTIONAL PARAMETERS
176181
# root_volume_security_style = "
177182
# tags = {}
178-
# # active_directory_configuration {}
183+
# active_directory_configuration {}
179184
}
180-
185+
#
186+
# Define a volume within the storage virtual machine.
181187
resource "aws_fsx_ontap_volume" "myvol" {
182188
// REQUIRED PARAMETERS
183189
name = var.vol_info["vol_name"]
@@ -201,5 +207,13 @@ resource "aws_fsx_ontap_volume" "myvol" {
201207
# snapshot_policy {}
202208
# tags = {}
203209
}
204-
205-
210+
#
211+
# The next two data blocks retrieve the secret from Secrets Manager.
212+
data "aws_secretsmanager_secret" "fsx_secret" {
213+
provider = aws.secrets
214+
name = var.fsx_secret_name
215+
}
216+
data "aws_secretsmanager_secret_version" "fsx_password" {
217+
provider = aws.secrets
218+
secret_id = data.aws_secretsmanager_secret.fsx_secret.id
219+
}

0 commit comments

Comments
 (0)