Skip to content

Commit d40844e

Browse files
author
nichollri
committed
first working version that includes snapmirror creation.
1 parent 304f7a6 commit d40844e

File tree

3 files changed

+104
-85
lines changed

3 files changed

+104
-85
lines changed

Terraform/fsxn-replicate/main.tf

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ provider "netapp-ontap" {
3636
# At least one is required.
3737
connection_profiles = [
3838
{
39-
name = "primary_clus"
39+
name = var.prime_clus_name
4040
hostname = var.prime_hostname
4141
username = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["username"]
4242
password = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["password"]
4343
validate_certs = var.validate_certs
4444
},
4545
{
46-
name = "dr_clus"
46+
name = var.dr_clus_name
4747
hostname = join("", aws_fsx_ontap_file_system.terraform-fsxn.endpoints[0].management[0].ip_addresses)
4848
username = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["username"]
4949
password = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["password"]
@@ -88,65 +88,53 @@ resource "aws_fsx_ontap_storage_virtual_machine" "mysvm" {
8888
root_volume_security_style = var.dr_root_vol_sec_style
8989
}
9090

91-
data "netapp-ontap_storage_volume_data_source" "my_vol" {
91+
data "netapp-ontap_storage_volume_data_source" "src_vols" {
9292
for_each = toset(var.list_of_volumes_to_replicate)
93-
cx_profile_name = "primary_clus"
93+
cx_profile_name = var.prime_clus_name
9494
svm_name = var.prime_svm
9595
name = each.value
9696
}
9797

98-
resource "netapp-ontap_storage_volume_resource" "volloop" {
99-
for_each = data.netapp-ontap_storage_volume_data_source.my_vol
100-
cx_profile_name = "dr_clus"
101-
name = "${each.value.name}_dp"
102-
type = "dp"
103-
svm_name = aws_fsx_ontap_storage_virtual_machine.mysvm.name
104-
aggregates = [
105-
{
106-
name = "aggr1"
107-
},
108-
]
109-
space_guarantee = "none"
110-
space = {
111-
size = each.value.space.size
112-
size_unit = each.value.space.size_unit
113-
logical_space = {
114-
enforcement = true
115-
reporting = true
116-
}
117-
}
118-
tiering = {
119-
policy_name = "all"
120-
}
121-
nas = {
122-
export_policy_name = "default"
123-
# security_style = "unix"
124-
# junction_path = join("", ["/",each.value.name])
98+
variable "size_in_mb" {
99+
type = map(string)
100+
101+
# Conversion to MBs
102+
default = {
103+
"mb" = 1
104+
"MB" = 1
105+
"gb" = 1024
106+
"GB" = 1024
107+
"tb" = 1024*1024
108+
"TB" = 1024*1024
125109
}
126110
}
127111

128-
# Now that we have the DP volumes created on the newly deployed destination cluster,
129-
# let's get the intercluster LIFs so we can peer the clusters.
130112

131-
# For existing FSx ONTAP cluster
132-
data "netapp-ontap_networking_ip_interfaces_data_source" "primary_intercluster_lifs" {
133-
cx_profile_name = "primary_clus"
134-
filter = {
135-
svm_name = var.prime_svm
136-
# svm_name = "FsxId020de2687bd98ccf7"
137-
name = "iscsi_*" # Filter to only get intercluster LIFs
113+
resource "aws_fsx_ontap_volume" "dp_volumes" {
114+
for_each = data.netapp-ontap_storage_volume_data_source.src_vols
115+
storage_virtual_machine_id = aws_fsx_ontap_storage_virtual_machine.mysvm.id
116+
name = "${each.value.name}_dp"
117+
ontap_volume_type = "DP"
118+
size_in_megabytes = each.value.space.size * lookup(var.size_in_mb, each.value.space.size_unit, 0)
119+
tiering_policy {
120+
name = "ALL"
138121
}
122+
skip_final_backup = true
139123
}
140124

141-
# For newly created FSx ONTAP cluster
142-
data "netapp-ontap_networking_ip_interfaces_data_source" "dr_intercluster_lifs" {
143-
cx_profile_name = "dr_clus"
144-
filter = {
145-
svm_name = aws_fsx_ontap_storage_virtual_machine.mysvm.name
146-
name = "inter*" # Filter to only get intercluster LIFs
147-
}
125+
resource "aws_fsx_ontap_volume" "test_src" {
126+
storage_virtual_machine_id = aws_fsx_ontap_storage_virtual_machine.mysvm.id
127+
name = "volx_src"
128+
ontap_volume_type = "RW"
129+
size_in_megabytes = 1024
130+
junction_path = "/volx_src"
131+
storage_efficiency_enabled = true
148132
}
149133

134+
# Now that we have the DP volumes created on the newly deployed destination cluster,
135+
# let's get the intercluster LIFs so we can peer the clusters.
136+
137+
150138
# For now let's try to get the source and destination IC LIFs via AWS TF provider.
151139
data "aws_fsx_ontap_file_system" "source_fsxn" {
152140
id = var.prime_fsxid
@@ -155,8 +143,8 @@ data "aws_fsx_ontap_file_system" "source_fsxn" {
155143
# Now udse the LIF names and IP addresses to peer the clusters
156144

157145
resource "netapp-ontap_cluster_peers_resource" "cluster_peer" {
158-
cx_profile_name = "primary_clus" # Source cluster profile
159-
peer_cx_profile_name = "dr_clus" # Destination (peer) cluster profile
146+
cx_profile_name = var.prime_clus_name # Source cluster profile
147+
peer_cx_profile_name = var.dr_clus_name # Destination (peer) cluster profile
160148

161149
remote = {
162150
# Destination cluster (DR) intercluster LIF IPs
@@ -172,3 +160,37 @@ resource "netapp-ontap_cluster_peers_resource" "cluster_peer" {
172160
# passphrase = var.cluster_peer_passphrase # Optional, if you use passphrase for peering
173161
peer_applications = ["snapmirror"]
174162
}
163+
164+
resource "netapp-ontap_svm_peers_resource" "peer_svms" {
165+
cx_profile_name = var.dr_clus_name
166+
svm = {
167+
name = aws_fsx_ontap_storage_virtual_machine.mysvm.name
168+
}
169+
peer = {
170+
svm = {
171+
name = var.prime_svm
172+
}
173+
cluster = {
174+
name = var.prime_cluster_vserver
175+
}
176+
peer_cx_profile_name = var.prime_clus_name
177+
}
178+
applications = ["snapmirror", "flexcache"]
179+
depends_on = [
180+
netapp-ontap_cluster_peers_resource.cluster_peer
181+
]
182+
}
183+
184+
resource "netapp-ontap_snapmirror_resource" "snapmirror" {
185+
for_each = data.netapp-ontap_storage_volume_data_source.src_vols
186+
cx_profile_name = var.dr_clus_name
187+
source_endpoint = {
188+
path = join(":",[var.prime_svm,each.value.name])
189+
}
190+
destination_endpoint = {
191+
path = join(":",[aws_fsx_ontap_storage_virtual_machine.mysvm.name, "${each.value.name}_dp"])
192+
}
193+
depends_on = [
194+
netapp-ontap_svm_peers_resource.peer_svms
195+
]
196+
}

Terraform/fsxn-replicate/output.tf

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
1-
output "volume_details" {
2-
value = {
3-
for key, volume in data.netapp-ontap_storage_volume_data_source.my_vol : key => {
4-
name = volume.name
5-
type = volume.type
6-
size = "${volume.space.size}${volume.space.size_unit}"
7-
}
8-
}
9-
description = "Details of the volumes including name, type, size, and size unit"
10-
}
11-
12-
#output "lifs" {
1+
#output "volume_details" {
132
# value = {
14-
# for key, lif in data.netapp-ontap_networking_ip_interfaces_data_source.primary_intercluster_lifs : key => {
15-
# name = lif.ip_interfaces.name
16-
# ip_address = lif.ip_interfaces.ip.ip_address
3+
# for key, volume in data.netapp-ontap_storage_volume_data_source.src_vols : key => {
4+
# name = volume.name
5+
# type = volume.type
6+
# size = "${volume.space.size}${volume.space.size_unit}"
177
# }
188
# }
19-
# description = "Details of source intercluster LIFs"
9+
# description = "Details of the volumes including name, type, size, and size unit"
2010
#}
2111

22-
output "primary_intercluster_lifs_details" {
23-
value = {
24-
for lif in data.netapp-ontap_networking_ip_interfaces_data_source.primary_intercluster_lifs.ip_interfaces : lif.name => lif.ip.address
25-
}
26-
description = "Intercluster LIF names and IP addresses for the primary existing cluster"
27-
}
28-
29-
output "data_from_aws_fsxn" {
30-
value = {
31-
intercluster = {
32-
# dns_name = data.aws_fsx_ontap_file_system.source_fsxn.endpoints[0].intercluster[0].dns_name
33-
# ip_addresses = data.aws_fsx_ontap_file_system.source_fsxn.endpoints[0].intercluster[0].ip_addresses
34-
all_of_it = data.aws_fsx_ontap_file_system.source_fsxn
35-
}
36-
}
37-
description = "All data from aws fsxn provider"
38-
}
12+
#output "data_from_aws_fsxn" {
13+
# value = {
14+
# all_of_it = data.aws_fsx_ontap_file_system.source_fsxn
15+
# }
16+
# description = "All data from aws fsxn provider"
17+
#}
3918

Terraform/fsxn-replicate/variables.tf

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@ variable "prime_fsxid" {
1212
default = "fs-020de2687bd98ccf7"
1313
}
1414

15+
variable "prime_clus_name" {
16+
description = "This is the name of the cluster given for ONTAP TF connection profile. This is a user creatred value, that can be any string. It is referenced in many ONTAP TF resources."
17+
type = string
18+
default = "primary_clus"
19+
}
20+
1521
variable "prime_svm" {
1622
description = "Name of svm for replication in the primary cluster."
1723
type = string
1824
default = "vs1cli"
1925
}
2026

27+
variable "prime_cluster_vserver" {
28+
description = "Name of cluster vserver for inter cluster lifs in the primary cluster. This can be found by running network interface show on the source cluster"
29+
type = string
30+
default = "FsxId020de2687bd98ccf7"
31+
}
32+
2133
variable "prime_aws_region" {
2234
description = "AWS regionfor the Primary ONTAP FSxN"
2335
type = string
@@ -39,7 +51,7 @@ variable "username_pass_secrets_id" {
3951
variable "list_of_volumes_to_replicate" {
4052
description = "list of volumes to replicate to dr fsxn"
4153
type = list(string)
42-
default = ["cifs_share", "rvwn_from_bxp", "unix"]
54+
default = ["cifs_share", "rvwn_from_bxp", "rvwn_voltb", "rvwn_volmb"]
4355
}
4456

4557
variable "dr_fsx_name" {
@@ -48,6 +60,12 @@ variable "dr_fsx_name" {
4860
default = "terraform-dr-fsxn"
4961
}
5062

63+
variable "dr_clus_name" {
64+
description = "This is the name of the cluster given for ONTAP TF connection profile. This is a user creatred value, that can be any string. It is referenced in many ONTAP TF resources."
65+
type = string
66+
default = "dr_clus"
67+
}
68+
5169
variable "dr_fsx_deploy_type" {
5270
description = "The file system deployment type. Supported values are 'MULTI_AZ_1', 'SINGLE_AZ_1', 'MULTI_AZ_2', and 'SINGLE_AZ_2'. MULTI_AZ_1 and SINGLE_AZ_1 are Gen 1. MULTI_AZ_2 and SINGLE_AZ_2 are Gen 2."
5371
type = string
@@ -70,7 +88,7 @@ variable "dr_fsx_subnets" {
7088
variable "dr_fsx_capacity_size_gb" {
7189
description = "The storage capacity in GiBs of the FSxN file system. Valid values between 1024 (1 TiB) and 1048576 (1 PiB). Gen 1 deployment types are limited to 192 TiB. Gen 2 Multi AZ is limited to 512 TiB. Gen 2 Single AZ is limited to 1 PiB."
7290
type = number
73-
default = 1024
91+
default = 2048
7492
validation {
7593
condition = var.dr_fsx_capacity_size_gb >= 1024 && var.dr_fsx_capacity_size_gb <= 1048576
7694
error_message = "Invalid capacity size. Valid values are between 1024 (1TiB) and 1045876 (1 PiB)."
@@ -214,7 +232,7 @@ variable "dr_vpc_id" {
214232
variable "dr_username_pass_secrets_id" {
215233
description = "Name of secret ID in AWS secrets"
216234
type = string
217-
default = "rvwn_replicate_ontap_creds"
235+
default = "rvwn_replicate_ontap_creds_dr"
218236
}
219237

220238
variable "validate_certs" {

0 commit comments

Comments
 (0)