Skip to content

Commit 473d430

Browse files
authored
Merge pull request #158 from NetApp/add_secret_rotate
Add an AWS Secret Manager FSxN rotate function
2 parents a2a4bbe + 717f8f2 commit 473d430

File tree

18 files changed

+793
-99
lines changed

18 files changed

+793
-99
lines changed

EKS/FSxN-as-PVC-for-EKS/terraform/eks-cluster.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ resource "aws_iam_policy" "trident_policy" {
8181
{
8282
"Action": "secretsmanager:GetSecretValue",
8383
"Effect": "Allow",
84-
"Resource": aws_secretsmanager_secret_version.fsx_secret_password.arn
84+
"Resource": module.svm_rotate_secret.secret_arn
8585
}
8686
],
8787
})
Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,40 @@
11
#
2-
# Generate a random password for FSx
3-
resource "random_string" "fsx_password" {
4-
length = 8
5-
min_lower = 1
6-
min_numeric = 1
7-
min_special = 0
8-
min_upper = 1
9-
numeric = true
10-
special = true
11-
override_special = "@$%^&*()_+="
12-
}
13-
14-
provider "aws" {
15-
alias = "secrets_provider"
16-
region = var.aws_secrets_region
17-
}
18-
#
19-
# Store the password in AWS Secrets Manager
20-
resource "aws_secretsmanager_secret" "fsx_secret_password" {
21-
provider = aws.secrets_provider
22-
name = "${var.fsx_password_secret_name}-${random_id.id.hex}"
23-
}
24-
resource "aws_secretsmanager_secret_version" "fsx_secret_password" {
25-
provider = aws.secrets_provider
26-
secret_id = aws_secretsmanager_secret.fsx_secret_password.id
27-
secret_string = jsonencode({username = "vsadmin", password = random_string.fsx_password.result})
2+
# Instantiate an AWS secret for the FSx ONTAP file system. It will set the initial password for the file system.
3+
module "fsxn_rotate_secret" {
4+
source = "github.com/Netapp/FSx-ONTAP-samples-scripts/Management-Utilities/fsxn-rotate-secret/terraform"
5+
fsx_region = var.aws_region
6+
secret_region = var.aws_secrets_region
7+
aws_account_id = var.aws_account_id
8+
secret_name_prefix = var.secret_name_prefix
9+
fsx_id = aws_fsx_ontap_file_system.eksfs.id
2810
}
2911
#
30-
# Note that this allows traffic from both the private and public subnets. However
31-
# the security groups only allow traffic from the public subnet over port 22 when
32-
# the source has the jump server SG assigned to it. So, basically, it only allows traffic
33-
# from the jump server from the public subnet.
12+
# Create a FSxN file system.
3413
resource "aws_fsx_ontap_file_system" "eksfs" {
3514
storage_capacity = var.fsxn_storage_capacity
3615
subnet_ids = module.vpc.private_subnets
3716
deployment_type = "MULTI_AZ_1"
3817
throughput_capacity = var.fsxn_throughput_capacity
3918
preferred_subnet_id = module.vpc.private_subnets[0]
4019
security_group_ids = [aws_security_group.fsx_sg.id]
41-
fsx_admin_password = random_string.fsx_password.result
42-
route_table_ids = concat(module.vpc.private_route_table_ids, module.vpc.public_route_table_ids)
20+
route_table_ids = concat(module.vpc.private_route_table_ids, module.vpc.public_route_table_ids)
4321
tags = {
4422
Name = var.fsx_name
4523
}
4624
}
4725
#
26+
# Instantiate an AWS secret for the storage virtual machine. It will set the initial password for the SVM.
27+
module "svm_rotate_secret" {
28+
source = "github.com/Netapp/FSx-ONTAP-samples-scripts/Management-Utilities/fsxn-rotate-secret/terraform"
29+
fsx_region = var.aws_region
30+
secret_region = var.aws_secrets_region
31+
aws_account_id = var.aws_account_id
32+
secret_name_prefix = var.secret_name_prefix
33+
svm_id = aws_fsx_ontap_storage_virtual_machine.ekssvm.id
34+
}
35+
#
4836
# Create a vserver and assign the 'vsadmin' the same password as fsxadmin.
4937
resource "aws_fsx_ontap_storage_virtual_machine" "ekssvm" {
5038
file_system_id = aws_fsx_ontap_file_system.eksfs.id
5139
name = "ekssvm"
52-
svm_admin_password = random_string.fsx_password.result
5340
}

EKS/FSxN-as-PVC-for-EKS/terraform/outputs.tf

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
output "region" {
2-
description = "AWS region"
32
value = var.aws_region
43
}
54

65
output "fsx-password-secret-name" {
7-
value = aws_secretsmanager_secret.fsx_secret_password.name
6+
value = module.fsxn_rotate_secret.secret_name
87
}
98

109
output "fsx-password-secret-arn" {
11-
value = aws_secretsmanager_secret_version.fsx_secret_password.arn
10+
value = module.fsxn_rotate_secret.secret_arn
11+
}
12+
13+
output "svm-password-secret-name" {
14+
value = module.svm_rotate_secret.secret_name
15+
}
16+
17+
output "svm-password-secret-arn" {
18+
value = module.svm_rotate_secret.secret_arn
1219
}
1320

1421
output "fsx-svm-name" {
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
11
variable "aws_region" {
2-
default = "us-west-2"
3-
description = "aws region where you want the resources deployed."
2+
description = "The AWS region where you want the resources deployed."
3+
type = string
44
}
55

66
variable "aws_secrets_region" {
7-
default = "us-west-2"
8-
description = "The region where you want the FSxN secret stored within AWS Secrets Manager."
7+
description = "The AWS region where you want the FSxN and SVM secrets stored within AWS Secrets Manager."
8+
type = string
9+
}
10+
11+
variable "aws_account_id" {
12+
description = "The AWS account ID. Used to create very specific permissions in the IAM role for the EKS cluster."
13+
type = string
914
}
1015

1116
variable "fsx_name" {
12-
default = "eksfs"
1317
description = "The name you want assigned to the FSxN file system."
18+
default = "eksfs"
1419
}
1520

16-
variable "fsx_password_secret_name" {
21+
variable "secret_name_prefix" {
22+
description = "The base name of the secrets (FSxN and SVM) to create within the AWS Secrets Manager. A random string will be appended to the end of the secreate name to ensure no name conflict."
1723
default = "fsx-eks-secret"
18-
description = "The base name of the secret to create within the AWS Secrets Manager that will contain the FSxN password. A random string will be appended to the end of the secreate name to ensure no name conflict."
1924
}
2025

2126
variable "fsxn_storage_capacity" {
22-
default = 1024
2327
description = "The storage capacity, in GiBs, to be allocated to the FSxN clsuter. Must be at least 1024, and less than 196608."
28+
type = number
29+
default = 1024
2430
validation {
2531
condition = var.fsxn_storage_capacity >= 1024 && var.fsxn_storage_capacity < 196608
2632
error_message = "The storage capacity must be at least 1024, and less than 196608."
2733
}
2834
}
2935

3036
variable "fsxn_throughput_capacity" {
31-
default = 128
3237
description = "The throughput capacity to be allocated to the FSxN cluster. Must be 128, 256, 512, 1024, 2048, 4096."
38+
type = string # Set to a string so it can be used in a "contains()" function.
39+
default = 128
3340
validation {
3441
condition = contains([128, 256, 512, 1024, 2048, 4096], var.fsxn_throughput_capacity)
3542
error_message = "The throughput capacity must be 128, 256, 512, 1024, 2048, or 4096."
@@ -38,34 +45,38 @@ variable "fsxn_throughput_capacity" {
3845
#
3946
# Keep in mind that key pairs are regional, so pick one that is in the region specified above.
4047
variable "key_pair_name" {
41-
default = "MUST REPLACE WITH YOUR KEY PAIR NAME"
4248
description = "The key pair to associate with the jump server."
49+
default = "MUST REPLACE WITH YOUR KEY PAIR NAME"
50+
type = string
4351
validation {
4452
condition = var.key_pair_name != "MUST REPLACE WITH YOUR KEY PAIR NAME"
4553
error_message = "You must specify a key pair name."
4654
}
4755
}
4856

4957
variable "secure_ips" {
50-
default = ["0.0.0.0/0"]
5158
description = "List of CIDRs that are allowed to ssh into the jump server."
59+
default = ["0.0.0.0/0"]
5260
}
5361

5462
################################################################################
5563
# Don't change any variables below this line.
5664
################################################################################
5765

5866
variable "trident_version" {
59-
default = "v24.2.0-eksbuild.1"
6067
description = "The version of Astra Trident to 'add-on' to the EKS cluster."
68+
default = "v24.2.0-eksbuild.1"
69+
type = string
6170
}
6271

6372
variable "kubernetes_version" {
64-
default = 1.29
6573
description = "kubernetes version"
74+
default = 1.29
75+
type = string
6676
}
6777

6878
variable "vpc_cidr" {
69-
default = "10.0.0.0/16"
7079
description = "default CIDR range of the VPC"
80+
default = "10.0.0.0/16"
81+
type = string
7182
}

0 commit comments

Comments
 (0)