Cycle Error in Terraform when deploying an RDS Instance

Viewed 168

I keep getting this error when trying to do a Terraform Plan.

I'm deploying a RDS Instance with an IAM Profile attached to it.

resource "aws_db_instance" "sql_server_instance" {
  allocated_storage     = var.min_storage
  max_allocated_storage = var.max_storage
  engine                = "sqlserver-se"
  engine_version        = "15.00.4073.23.v1"
  license_model         = "license-included"
  instance_class        = "db.t3.xlarge"
  #name                 = "rds-${var.environment}-sql-server-01"
  username                        = "${var.environment}rdsmaster"
  password                        = random_password.password.result
  db_subnet_group_name            = aws_db_subnet_group.subnet_group.name
  deletion_protection             = false
  enabled_cloudwatch_logs_exports = ["error"]
  multi_az                        = var.rds_multi_az
  domain                          = aws_directory_service_directory.gemsad.id
  domain_iam_role_name            = aws_db_instance_role_association.db_iam_role.arn
  skip_final_snapshot             = true

  vpc_security_group_ids = [
    aws_security_group.sql_sg.id,
  ]

  depends_on = [
    aws_security_group.sql_sg,
    aws_db_instance_role_association.db_iam_role
  ]
}

resource "aws_db_instance_role_association" "db_iam_role" {
  db_instance_identifier = aws_db_instance.sql_server_instance.id
  feature_name           = "S3_INTEGRATION"
  role_arn               = aws_iam_role.app_server_role.arn
}

The IAM Profile is the following:

resource "aws_iam_role" "app_server_role" {
  name                 = "app-server-role"
  assume_role_policy   = data.aws_iam_policy_document.app_server_assume_role.json
  permissions_boundary = "arn:aws:iam::${var.account_id}:policy/******"
}

This is the error I get on my pipeline:

 Error: Cycle: aws_db_instance_role_association.db_iam_role, aws_db_instance.sql_server_instance

Can anyone see where I am going wrong?

1 Answers

Try it without the depends_on aws_db_instance_role_association.db_iam_role This will first try to create the association, but in it if needs the Db to be created... so that is your cycle I believe.

Related