why did i get a db creating error from terraform

0

Hello everyone!
i was trying to create rds mysql with terraform. but i got a error and i could not create resource of mysql rds.
I thought I had the right version and instance class combination, but I couldn't figure it out and couldn't solve the problem
Why did i get the error?

  • Error Message
Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

aws_db_instance.example: Creating...
╷
│ Error: creating RDS DB Instance (terraform-up-and-running20240902113600380800000001): InvalidParameterCombination: RDS does not support creating a DB instance with the following combination: DBInstanceClass=db.t2.micro, Engine=mysql, EngineVersion=8.0.35, LicenseModel=general-public-license. For supported combinations of instance class and database engine version, see the documentation.
│       status code: 400, request id: e4711bee-604c-463e-a1b2-390568590564
│
│   with aws_db_instance.example,
│   on main.tf line 25, in resource "aws_db_instance" "example":
│   25: resource "aws_db_instance" "example" {
  • Terraform Source
terraform {
  required_version = ">= 1.0.0, < 2.0.0"

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

  backend "s3" {
    bucket         = "daigo-bucket-testing"
    key            = "stage/data-stores/mysql/terraform.tfstate"
    region         = "us-east-2"
    dynamodb_table = "daigo-dynamodb-testing"
    encrypt        = true

  }
}

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

resource "aws_db_instance" "example" {
  identifier_prefix   = "terraform-up-and-running"
  engine              = "mysql"
  allocated_storage   = 10
  instance_class      = "db.t2.micro"
  skip_final_snapshot = true

  db_name             = var.db_name

  username = var.db_username
  password = var.db_password
}

Could you help me to fix it as soon as possible?

Thank you

2 Answers
3
Accepted Answer

Hi Daigo Tsuchiya,

Please go through the below steps I hope it will help solve your issue.

1. Change the Instance Class

The db.t2.micro instance type may not support the MySQL version you're trying to use. You can switch to a different instance class like db.t3.micro, which is often compatible with newer versions of MySQL.

Update your aws_db_instance resource to use db.t3.micro:

resource "aws_db_instance" "example" {
  identifier_prefix   = "terraform-up-and-running"
  engine              = "mysql"
  engine_version      = "8.0.35"   # Ensure this is the correct version for your instance class
  allocated_storage   = 10
  instance_class      = "db.t3.micro"  # Updated instance class
  skip_final_snapshot = true

  db_name             = var.db_name

  username = var.db_username
  password = var.db_password
}

2. Specify the Engine Version (Optional)

Although it's not always necessary, specifying the engine version explicitly can help avoid issues. If you continue to face issues, you might also want to check which versions are compatible with the db.t3.micro instance class in the AWS RDS Documentation.

https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_MySQL.html

3. Review Other Parameters

Ensure that all other parameters in your aws_db_instance resource are correct. For example, you might want to specify backup_retention_period or parameter_group_name based on your requirements.

Full Example with Modifications Here’s how your updated aws_db_instance resource might look:

resource "aws_db_instance" "example" {
  identifier_prefix   = "terraform-up-and-running"
  engine              = "mysql"
  engine_version      = "8.0.35"  # Make sure this version is supported by the instance class
  allocated_storage   = 10
  instance_class      = "db.t3.micro"  # Updated instance class
  skip_final_snapshot = true

  db_name             = var.db_name
  username            = var.db_username
  password            = var.db_password
  backup_retention_period = 7  # Optional: Set backup retention if needed
}

Troubleshooting

AWS Documentation: Double-check the AWS RDS documentation for the specific MySQL version you are using and the supported instance classes.

Terraform Plan: Run terraform plan to ensure that your changes are correctly reflected and to review any additional issues that might come up.

EXPERT
answered a month ago
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago
2

Default storage type for RDS in terraform is gp2 where minimum size for MySQL is 20GB (you have only 10).

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-rds-dbinstance.html#cfn-rds-dbinstance-allocatedstorage

You can change it to 20 or specify ”standard” storage if you only want 10.

storage_type - (Optional) One of "standard" (magnetic), "gp2" (general purpose SSD), "gp3" (general purpose SSD that needs iops independently) or "io1" (provisioned IOPS SSD). The default is "io1" if iops is specified, "gp2" if not

profile picture
EXPERT
Kallu
answered a month ago
profile picture
EXPERT
reviewed a month ago
profile picture
EXPERT
reviewed a month ago
  • thank for your comment!
    i have fixed my source with your comment but i am getting same error..

    • Error Message
    Do you want to perform these actions?
      Terraform will perform the actions described above.
      Only 'yes' will be accepted to approve.
    
      Enter a value: yes
    
    aws_db_instance.example: Creating...
    ╷
    │ Error: creating RDS DB Instance (terraform-up-and-running20240903153256753400000001): InvalidParameterCombination: RDS does not support creating a DB instance with the following combination: DBInstanceClass=db.t2.micro, Engine=mysql, EngineVersion=8.0.35, LicenseModel=general-public-license. For supported combinations of instance class and database engine version, see the documentation.
    │       status code: 400, request id: 3ee5c548-5db0-406a-b44a-3daab35dff79
    │
    │   with aws_db_instance.example,
    │   on main.tf line 25, in resource "aws_db_instance" "example":
    │   25: resource "aws_db_instance" "example" {
    
    • Fixed Source
    resource "aws_db_instance" "example" {
      identifier_prefix   = "terraform-up-and-running"
      engine              = "mysql"
      allocated_storage   = 20 # i fixed it
      instance_class      = "db.t2.micro"
      skip_final_snapshot = true
    
      db_name             = var.db_name
    
      username = var.db_username
      password = var.db_password
    }
    
  • I was able to correct the problem when I modified it based on the following solution. https://repost.aws/questions/QU1llceoaxT2Or7r4kcWKuDg/why-did-i-get-a-db-creating-error-from-terraform#ANlZkrmcLHQ6W0GCbB3kKnwA

    However Your comments have given me a new perspective, thank you so much!

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions