Skip to content

Commit 30ceafc

Browse files
committed
Fixed variable validation.
1 parent 1467bc1 commit 30ceafc

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ resource "aws_fsx_ontap_file_system" "terraform-fsxn" {
3030
route_table_ids = var.route_table_ids
3131
tags = var.tags
3232
disk_iops_configuration = var.disk_iops_configuration
33+
34+
lifecycle {
35+
precondition {
36+
condition = !var.create_sg || (var.cidr_block != "" && var.source_security_group_id == "" || var.cidr_block == "" && var.source_security_group_id != "")
37+
error_message = "You must specify EITHER cidr_block OR source_security_group_id when creating a security group, not both."
38+
}
39+
precondition {
40+
condition = var.create_sg || var.security_group_id != ""
41+
error_message = "You must specify a security group ID when not creating a security group."
42+
}
43+
}
3344
}
3445

3546
resource "aws_fsx_ontap_storage_virtual_machine" "mysvm" {

Terraform/deploy-fsx-ontap/module/variables.tf

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ variable "security_group_id" {
2020
description = "If you are not creating the SG, provide the ID of the SG to be used"
2121
type = string
2222
default = ""
23-
validation {
24-
condition = !var.create_sg and var.security_group_id != ""
25-
error_message = "You must provide the ID of the security group to be used."
26-
}
2723
}
2824

2925
/*
@@ -36,20 +32,12 @@ variable "cidr_for_sg" {
3632
description = "cidr block to be used for the created security ingress rules."
3733
type = string
3834
default = "10.0.0.0/8"
39-
validation {
40-
condition = var.create_sg and var.source_security_group_id == "" and var.cidr_for_sg != ""
41-
error_message = "You can't specify both source_security_group_id and cidr_for_sg. Please specify only one."
42-
}
4335
}
4436

4537
variable "source_security_group_id" {
46-
description = "The ID of the security group to allow access to the FSxN file system.
38+
description = "The ID of the security group to allow access to the FSxN file system."
4739
type = string
4840
default = ""
49-
validation {
50-
condition = var.create_sg and var.source_security_group_id != "" and var.cidr_for_sg == ""
51-
error_message = "You can't specify both source_security_group_id and cidr_for_sg. Please specify only one."
52-
}
5341
}
5442

5543
variable "vpc_id" {
@@ -137,7 +125,7 @@ variable "fsx_secret_name" {
137125
description = "The name of the secure where the FSxN passwood is stored"
138126
type = string
139127
default = ""
140-
validataion {
128+
validation {
141129
condition = var.fsx_secret_name != ""
142130
error_message = "You must provide the name of the secret where the FSxN password is stored."
143131
}

0 commit comments

Comments
 (0)