amazon-web-servicesterraformamazon-rdsamazon-aurora

terraform aws aurora module: argument "engine" required, but it's actually there


I'm trying to instantiate an rds aurora cluster using the rds-aurora module: https://registry.terraform.io/modules/terraform-aws-modules/rds-aurora/aws/latest

However, despite mostly following the documentation and the examples, I can't get rid of the following errors:

╷
│ Error: only lowercase alphanumeric characters and hyphens allowed in "cluster_identifier"
│ 
│   with module.rds-aurora.aws_rds_cluster.this[0],
│   on .terraform/modules/rds-aurora/main.tf line 49, in resource "aws_rds_cluster" "this":
│   49:   cluster_identifier                  = var.cluster_use_name_prefix ? null : var.name
│ 
╵
╷
│ Error: first character of "cluster_identifier" must be a letter
│ 
│   with module.rds-aurora.aws_rds_cluster.this[0],
│   on .terraform/modules/rds-aurora/main.tf line 49, in resource "aws_rds_cluster" "this":
│   49:   cluster_identifier                  = var.cluster_use_name_prefix ? null : var.name
│ 
╵
╷
│ Error: Missing required argument
│ 
│   with module.rds-aurora.aws_rds_cluster.this[0],
│   on .terraform/modules/rds-aurora/main.tf line 64, in resource "aws_rds_cluster" "this":
│   64:   engine                              = var.engine
│ 
│ The argument "engine" is required, but no definition was found.

I am very confused by all three of them. The last one, "argument engine is required" is the weirdest, since I have the argument clearly in my code, with a value that according to the documentation should be valid. I don't really understand the other two concerning cluster_identifier either, since, if I'm interpreting that right, it should use the name for that, and the name "webcam-service-aurora-db" appears to fulfill all the criteria.

I've wrapped it all out of my current module and put it into a simple one-file affair which I'll post here. You should be able to take it and run it and reproduce the problem. There must be something I'm fundamentally misunderstanding (wouldn't be surprising, it's my first time with terraform), but I can't find out what it is.

The entire code (providers and all):

terraform {
  required_providers {

    aws = {
      source  = "hashicorp/aws"
      version = "~> 5.78.0"
    }
  }
}

// Choose non-default regions like this, otherwise will always deploy to the default region configured in aws profile.
provider "aws" {
  region = "eu-central-1"
}

module "rds-aurora" {
  source  = "terraform-aws-modules/rds-aurora/aws"
  version = "9.10.0"
}


module "aurora" {
  source = "terraform-aws-modules/rds-aurora/aws"

  name = "webcam-service-aurora-db"
  engine = "aurora-mysql"
  engine_version = "8.0"
  instance_class = "db.t4g.medium"
  vpc_id = "vpc-073c3bc9571c4bffe"

  master_username = "root"

  instances = {
    one = {}
  }

  storage_encrypted = false
  apply_immediately = true
  skip_final_snapshot = true
  monitoring_interval = 10
  enabled_cloudwatch_logs_exports = ["error", "slowquery"]

  tags = {
    Environment = "experiment"
    Terraform = "true"
  }

}

You should be able to put this into a .tf file, run init, and then plan to produce the error. Or maybe you're experienced enough to just spot what I'm doing wrong.


Solution

  • You are declaring one use of the module with no arguments at all, just a version attribute, here:

    module "rds-aurora" {
      source  = "terraform-aws-modules/rds-aurora/aws"
      version = "9.10.0"
    }
    

    Then you declare another use of the module, with all your attributes, but no version defined. You need to delete that first declaration, and add a version attribute in the other one.