Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions examples/selection_by_conditions/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,12 @@ module "aws_backup_example" {
# Selection configuration using conditions
selections = {
selection_by_conditions = {
name = "selection_by_conditions"
selection_tags = [
{
type = "STRINGEQUALS"
key = "Environment"
value = "prod"
},
{
type = "STRINGEQUALS"
key = "Service"
value = "web"
conditions = {
string_equals = {
"aws:ResourceTag/Environment" = "prod"
"aws:ResourceTag/Service" = "web"
}
]
}
}
}

Expand Down
29 changes: 29 additions & 0 deletions test/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,35 @@ func TestExamplesWithCustomVariables(t *testing.T) {
}
}

func TestConditionsVariableTypes(t *testing.T) {
t.Parallel()

// Test that the conditions variable accepts the proper structure
terraformOptions := &terraform.Options{
TerraformDir: "./fixtures/terraform/conditions",
NoColor: true,
PlanFilePath: "tfplan-conditions",
}

// Clean up plan file after test
defer func() {
planFile := filepath.Join("./fixtures/terraform/conditions", "tfplan-conditions")
if _, err := os.Stat(planFile); err == nil {
os.Remove(planFile)
}
}()

// Init and validate
RetryableInit(t, terraformOptions)

// Run terraform plan to validate the conditions structure works
RetryablePlan(t, terraformOptions)

// Validate that plan was created successfully
planFile := filepath.Join("./fixtures/terraform/conditions", "tfplan-conditions")
assert.FileExists(t, planFile, "Plan file should be created for conditions test")
}

func TestExampleTerraformFiles(t *testing.T) {
t.Parallel()

Expand Down
40 changes: 40 additions & 0 deletions test/fixtures/terraform/conditions/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
module "aws_backup_conditions" {
source = "../../../.."

# Basic configuration
plan_name = "conditions-backup-plan"
vault_name = "conditions-backup-vault"

rules = [
{
name = "conditions-backup-rule"
target_vault_name = "conditions-backup-vault"
schedule = "cron(0 5 ? * * *)"
start_window = 480
completion_window = 600
lifecycle = {
delete_after = 30
}
}
]

# Test the conditions functionality
selections = {
conditions_test = {
conditions = {
string_equals = {
"aws:ResourceTag/Environment" = "dev"
"aws:ResourceTag/BackupEnabled" = "true"
}
string_not_equals = {
"aws:ResourceTag/SkipBackup" = "true"
}
}
}
}

tags = {
Environment = "dev"
TestCase = "conditions"
}
}
14 changes: 14 additions & 0 deletions test/fixtures/terraform/conditions/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "plan_arn" {
description = "Backup plan ARN"
value = module.aws_backup_conditions.plan_arn
}

output "vault_arn" {
description = "Backup vault ARN"
value = module.aws_backup_conditions.vault_arn
}

output "plan_id" {
description = "Backup plan ID"
value = module.aws_backup_conditions.plan_id
}
17 changes: 17 additions & 0 deletions test/fixtures/terraform/conditions/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
variable "region" {
description = "AWS Region"
type = string
default = "us-east-1"
}

variable "plan_name" {
description = "Plan name"
type = string
default = "conditions-backup-plan"
}

variable "vault_name" {
description = "Vault name"
type = string
default = "conditions-backup-vault"
}
9 changes: 9 additions & 0 deletions test/fixtures/terraform/conditions/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
terraform {
required_version = ">= 1.0"
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
}
}
25 changes: 20 additions & 5 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ variable "plans" {
selections = optional(map(object({
resources = optional(list(string))
not_resources = optional(list(string))
conditions = optional(map(any))
conditions = optional(object({
string_equals = optional(map(string))
string_not_equals = optional(map(string))
string_like = optional(map(string))
string_not_like = optional(map(string))
}))
selection_tags = optional(list(object({
type = string
key = string
Expand Down Expand Up @@ -328,8 +333,13 @@ variable "selection_not_resources" {

variable "selection_conditions" {
description = "A map of conditions that you define to assign resources to your backup plans using tags."
type = map(any)
default = {}
type = object({
string_equals = optional(map(string))
string_not_equals = optional(map(string))
string_like = optional(map(string))
string_not_like = optional(map(string))
})
default = {}
}

variable "selection_tags" {
Expand Down Expand Up @@ -543,8 +553,13 @@ variable "backup_selections" {
type = map(object({
resources = optional(list(string))
not_resources = optional(list(string))
conditions = optional(map(any))
tags = optional(map(string))
conditions = optional(object({
string_equals = optional(map(string))
string_not_equals = optional(map(string))
string_like = optional(map(string))
string_not_like = optional(map(string))
}))
tags = optional(map(string))
}))
default = {}

Expand Down
Loading