terraform-aws-backup icon indicating copy to clipboard operation
terraform-aws-backup copied to clipboard

0.14.0 doesn't work: Inconsistent conditional result types

Open nightspotlight opened this issue 2 years ago • 6 comments

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

after having upgraded the module in my configuration to 0.14.0, I'm getting these errors on terraform apply:

╷
│ Error: Insufficient rule blocks
│ 
│   on .terraform/modules/backup/main.tf line 57, in resource "aws_backup_plan" "default":
│   57: resource "aws_backup_plan" "default" {
│ 
│ At least 1 "rule" blocks are required.
╵
╷
│ Error: Inconsistent conditional result types
│ 
│   on .terraform/modules/backup/main.tf line 62, in resource "aws_backup_plan" "default":
│   62:     for_each = length(var.rules) > 0 ? var.rules : local.compatible_rules
│     ├────────────────
│     │ local.compatible_rules is tuple with 1 element
│     │ var.rules is list of map of string with 3 elements
│ 
│ The true and false result expressions must have consistent types. The 'true' value is list of map of string, but the 'false' value is tuple.
╵

Expected Behavior

applies successfully

Steps to Reproduce

Steps to reproduce the behavior:

  1. have Terraform:
Terraform v1.2.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.14.0
  1. have a config like:
terraform {
  required_version = "~> 1.0"

  backend "remote" {
    organization = "example"

    workspaces {
      prefix = "backup-"
    }
  }

  required_providers {
    aws = {
      source  = "hashicorp/aws"
      version = "~> 4.14.0"
    }
  }
}

provider "aws" {
  profile = "profile"
  region  = "us-east-2"
}

data "terraform_remote_state" "main" {
  backend = "remote"

  config = {
    organization = "example"

    workspaces = {
      name = "main-${terraform.workspace}"
    }
  }
}

module "label" {
  source  = "cloudposse/label/null"
  version = "~> 0.25.0"

  context = data.terraform_remote_state.main.outputs.label_context
  name    = "rds"

  tags = {
    terraform_state = "backup-${terraform.workspace}"
  }
}

module "backup" {
  source  = "cloudposse/backup/aws"
  version = "~> 0.14.0"

  context = data.terraform_remote_state.main.outputs.label_context
  name    = module.label.name

  kms_key_arn = aws_kms_key.backup.arn

  selection_tags = [
    {
      type  = "STRINGEQUALS"
      key   = "aws_backup"
      value = "true"
    }
  ]

  rules = [
    {
      name              = "${module.label.id}-daily"
      schedule          = "cron(0 5 ? * * *)"
      start_window      = 60 * 8      # minutes
      completion_window = 60 * 24 * 7 # minutes
      delete_after      = 7 * 5       # days
    },
    {
      name              = "${module.label.id}-weekly"
      schedule          = "cron(0 5 ? * SAT *)"
      start_window      = 60 * 8      # minutes
      completion_window = 60 * 24 * 7 # minutes
      delete_after      = 30 * 3      # days
    },
    {
      name               = "${module.label.id}-monthly"
      schedule           = "cron(0 5 1 * ? *)"
      start_window       = 60 * 8      # minutes
      completion_window  = 60 * 24 * 7 # minutes
      cold_storage_after = 30 * 3      # days
      delete_after       = 365 * 7     # days
    }
  ]

  tags = module.label.tags
}
  1. Run terraform init -upgrade
  2. Run terraform workspace select myworkspace
  3. Run terraform apply

Screenshots

  • -

Environment:

  • MacBookPro16,1 macOS 12.4 (21F79) Darwin Kernel Version 21.5.0
Terraform v1.2.3
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.14.0

Additional Context

broke after this chain of changes got applied over my #39:

  • #42
  • #43

nightspotlight avatar Jul 01 '22 15:07 nightspotlight

@nitrocode I was going to switch from my fork to the upstream release 0.14.0, but the release doesn't work. not sure if it's the module or my Terraform version. looks like I'm not alone though, as there's currently a fix submitted for review: #45 How does 0.14.0 work for you?

nightspotlight avatar Jul 01 '22 15:07 nightspotlight

@nightspotlight I put 0.14.0 as a pre-release.

Could you test the PR branch in #45 and see if it works for you ?

If not, then we may have to work on cutting a 1.0 release, use the migration guide, remove all the deprecated variables, update tests, etc

nitrocode avatar Jul 01 '22 20:07 nitrocode

@nightspotlight I had same error message with 0.14.0, if you are using new rules variable instead of legacy variables, then new rules list should be like this

rules = [
    {
      name               = "${module.label.id}-monthly"
      schedule           = "cron(0 5 1 * ? *)"
      start_window       = 60 * 8      # minutes
      completion_window  = 60 * 24 * 7 # minutes
      lifecycle = {
        cold_storage_after = 30 * 3      # days
        delete_after       = 365 * 7     # days
    }
  ]

for new rules, the dynamic block of lifecycle expect rule.value.lifecycle. migration doc is bit misleading

yadachi avatar Jul 25 '22 08:07 yadachi

same error here with the following call:

module "aurora-backup-eu" {
  source  = "cloudposse/backup/aws"
  version = "0.14.0"

  namespace = "sample"
  stage = local.environment
  name = "rds"

  backup_resources = [
    module.sample-aurora-cluster.primary_arn
  ]

  rules = [
    {
      name = "backup"
      schedule = "cron(0 12/12 ? * * *)"
      start_window = 60
      completion_window = 120
      cold_storage_after = 30
      delete_after = 180
    }
  ]
}

for the moment I just removed the conditional for dynamic "rule" and it works.

Israphel avatar Oct 14 '22 19:10 Israphel

for new rules, the dynamic block of lifecycle expect rule.value.lifecycle. migration doc is bit misleading

the migration guide was correct as of my change #39 until they've changed the code in #43. for this reason I never ended up upgrading to upstream tag, I'm still using my fork. I'll try using the new syntax some time. I think the docs need an update

nightspotlight avatar Oct 19 '22 22:10 nightspotlight

Thank you for all the comments folks. Sounds like we could use help here. Perhaps we can remove the deprecated inputs and focus on using the new interface.

PRs are always welcome if it doesn't work as intended.

nitrocode avatar Oct 20 '22 05:10 nitrocode