Skip to content

Commit

Permalink
first working version that includes snapmirror creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nichollri committed Oct 26, 2024
1 parent 304f7a6 commit d40844e
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 85 deletions.
120 changes: 71 additions & 49 deletions Terraform/fsxn-replicate/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ provider "netapp-ontap" {
# At least one is required.
connection_profiles = [
{
name = "primary_clus"
name = var.prime_clus_name
hostname = var.prime_hostname
username = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["username"]
password = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["password"]
validate_certs = var.validate_certs
},
{
name = "dr_clus"
name = var.dr_clus_name
hostname = join("", aws_fsx_ontap_file_system.terraform-fsxn.endpoints[0].management[0].ip_addresses)
username = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["username"]
password = jsondecode(data.aws_secretsmanager_secret_version.ontap_prime_username_pass.secret_string)["password"]
Expand Down Expand Up @@ -88,65 +88,53 @@ resource "aws_fsx_ontap_storage_virtual_machine" "mysvm" {
root_volume_security_style = var.dr_root_vol_sec_style
}

data "netapp-ontap_storage_volume_data_source" "my_vol" {
data "netapp-ontap_storage_volume_data_source" "src_vols" {
for_each = toset(var.list_of_volumes_to_replicate)
cx_profile_name = "primary_clus"
cx_profile_name = var.prime_clus_name
svm_name = var.prime_svm
name = each.value
}

resource "netapp-ontap_storage_volume_resource" "volloop" {
for_each = data.netapp-ontap_storage_volume_data_source.my_vol
cx_profile_name = "dr_clus"
name = "${each.value.name}_dp"
type = "dp"
svm_name = aws_fsx_ontap_storage_virtual_machine.mysvm.name
aggregates = [
{
name = "aggr1"
},
]
space_guarantee = "none"
space = {
size = each.value.space.size
size_unit = each.value.space.size_unit
logical_space = {
enforcement = true
reporting = true
}
}
tiering = {
policy_name = "all"
}
nas = {
export_policy_name = "default"
# security_style = "unix"
# junction_path = join("", ["/",each.value.name])
variable "size_in_mb" {
type = map(string)

# Conversion to MBs
default = {
"mb" = 1
"MB" = 1
"gb" = 1024
"GB" = 1024
"tb" = 1024*1024
"TB" = 1024*1024
}
}

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

# For existing FSx ONTAP cluster
data "netapp-ontap_networking_ip_interfaces_data_source" "primary_intercluster_lifs" {
cx_profile_name = "primary_clus"
filter = {
svm_name = var.prime_svm
# svm_name = "FsxId020de2687bd98ccf7"
name = "iscsi_*" # Filter to only get intercluster LIFs
resource "aws_fsx_ontap_volume" "dp_volumes" {
for_each = data.netapp-ontap_storage_volume_data_source.src_vols
storage_virtual_machine_id = aws_fsx_ontap_storage_virtual_machine.mysvm.id
name = "${each.value.name}_dp"
ontap_volume_type = "DP"
size_in_megabytes = each.value.space.size * lookup(var.size_in_mb, each.value.space.size_unit, 0)
tiering_policy {
name = "ALL"
}
skip_final_backup = true
}

# For newly created FSx ONTAP cluster
data "netapp-ontap_networking_ip_interfaces_data_source" "dr_intercluster_lifs" {
cx_profile_name = "dr_clus"
filter = {
svm_name = aws_fsx_ontap_storage_virtual_machine.mysvm.name
name = "inter*" # Filter to only get intercluster LIFs
}
resource "aws_fsx_ontap_volume" "test_src" {
storage_virtual_machine_id = aws_fsx_ontap_storage_virtual_machine.mysvm.id
name = "volx_src"
ontap_volume_type = "RW"
size_in_megabytes = 1024
junction_path = "/volx_src"
storage_efficiency_enabled = true
}

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


# For now let's try to get the source and destination IC LIFs via AWS TF provider.
data "aws_fsx_ontap_file_system" "source_fsxn" {
id = var.prime_fsxid
Expand All @@ -155,8 +143,8 @@ data "aws_fsx_ontap_file_system" "source_fsxn" {
# Now udse the LIF names and IP addresses to peer the clusters

resource "netapp-ontap_cluster_peers_resource" "cluster_peer" {
cx_profile_name = "primary_clus" # Source cluster profile
peer_cx_profile_name = "dr_clus" # Destination (peer) cluster profile
cx_profile_name = var.prime_clus_name # Source cluster profile
peer_cx_profile_name = var.dr_clus_name # Destination (peer) cluster profile

remote = {
# Destination cluster (DR) intercluster LIF IPs
Expand All @@ -172,3 +160,37 @@ resource "netapp-ontap_cluster_peers_resource" "cluster_peer" {
# passphrase = var.cluster_peer_passphrase # Optional, if you use passphrase for peering
peer_applications = ["snapmirror"]
}

resource "netapp-ontap_svm_peers_resource" "peer_svms" {
cx_profile_name = var.dr_clus_name
svm = {
name = aws_fsx_ontap_storage_virtual_machine.mysvm.name
}
peer = {
svm = {
name = var.prime_svm
}
cluster = {
name = var.prime_cluster_vserver
}
peer_cx_profile_name = var.prime_clus_name
}
applications = ["snapmirror", "flexcache"]
depends_on = [
netapp-ontap_cluster_peers_resource.cluster_peer
]
}

resource "netapp-ontap_snapmirror_resource" "snapmirror" {
for_each = data.netapp-ontap_storage_volume_data_source.src_vols
cx_profile_name = var.dr_clus_name
source_endpoint = {
path = join(":",[var.prime_svm,each.value.name])
}
destination_endpoint = {
path = join(":",[aws_fsx_ontap_storage_virtual_machine.mysvm.name, "${each.value.name}_dp"])
}
depends_on = [
netapp-ontap_svm_peers_resource.peer_svms
]
}
45 changes: 12 additions & 33 deletions Terraform/fsxn-replicate/output.tf
Original file line number Diff line number Diff line change
@@ -1,39 +1,18 @@
output "volume_details" {
value = {
for key, volume in data.netapp-ontap_storage_volume_data_source.my_vol : key => {
name = volume.name
type = volume.type
size = "${volume.space.size}${volume.space.size_unit}"
}
}
description = "Details of the volumes including name, type, size, and size unit"
}

#output "lifs" {
#output "volume_details" {
# value = {
# for key, lif in data.netapp-ontap_networking_ip_interfaces_data_source.primary_intercluster_lifs : key => {
# name = lif.ip_interfaces.name
# ip_address = lif.ip_interfaces.ip.ip_address
# for key, volume in data.netapp-ontap_storage_volume_data_source.src_vols : key => {
# name = volume.name
# type = volume.type
# size = "${volume.space.size}${volume.space.size_unit}"
# }
# }
# description = "Details of source intercluster LIFs"
# description = "Details of the volumes including name, type, size, and size unit"
#}

output "primary_intercluster_lifs_details" {
value = {
for lif in data.netapp-ontap_networking_ip_interfaces_data_source.primary_intercluster_lifs.ip_interfaces : lif.name => lif.ip.address
}
description = "Intercluster LIF names and IP addresses for the primary existing cluster"
}

output "data_from_aws_fsxn" {
value = {
intercluster = {
# dns_name = data.aws_fsx_ontap_file_system.source_fsxn.endpoints[0].intercluster[0].dns_name
# ip_addresses = data.aws_fsx_ontap_file_system.source_fsxn.endpoints[0].intercluster[0].ip_addresses
all_of_it = data.aws_fsx_ontap_file_system.source_fsxn
}
}
description = "All data from aws fsxn provider"
}
#output "data_from_aws_fsxn" {
# value = {
# all_of_it = data.aws_fsx_ontap_file_system.source_fsxn
# }
# description = "All data from aws fsxn provider"
#}

24 changes: 21 additions & 3 deletions Terraform/fsxn-replicate/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,24 @@ variable "prime_fsxid" {
default = "fs-020de2687bd98ccf7"
}

variable "prime_clus_name" {
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."
type = string
default = "primary_clus"
}

variable "prime_svm" {
description = "Name of svm for replication in the primary cluster."
type = string
default = "vs1cli"
}

variable "prime_cluster_vserver" {
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"
type = string
default = "FsxId020de2687bd98ccf7"
}

variable "prime_aws_region" {
description = "AWS regionfor the Primary ONTAP FSxN"
type = string
Expand All @@ -39,7 +51,7 @@ variable "username_pass_secrets_id" {
variable "list_of_volumes_to_replicate" {
description = "list of volumes to replicate to dr fsxn"
type = list(string)
default = ["cifs_share", "rvwn_from_bxp", "unix"]
default = ["cifs_share", "rvwn_from_bxp", "rvwn_voltb", "rvwn_volmb"]
}

variable "dr_fsx_name" {
Expand All @@ -48,6 +60,12 @@ variable "dr_fsx_name" {
default = "terraform-dr-fsxn"
}

variable "dr_clus_name" {
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."
type = string
default = "dr_clus"
}

variable "dr_fsx_deploy_type" {
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."
type = string
Expand All @@ -70,7 +88,7 @@ variable "dr_fsx_subnets" {
variable "dr_fsx_capacity_size_gb" {
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."
type = number
default = 1024
default = 2048
validation {
condition = var.dr_fsx_capacity_size_gb >= 1024 && var.dr_fsx_capacity_size_gb <= 1048576
error_message = "Invalid capacity size. Valid values are between 1024 (1TiB) and 1045876 (1 PiB)."
Expand Down Expand Up @@ -214,7 +232,7 @@ variable "dr_vpc_id" {
variable "dr_username_pass_secrets_id" {
description = "Name of secret ID in AWS secrets"
type = string
default = "rvwn_replicate_ontap_creds"
default = "rvwn_replicate_ontap_creds_dr"
}

variable "validate_certs" {
Expand Down

0 comments on commit d40844e

Please sign in to comment.