Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 5.5: database host is evaluated to null #32179

Closed
speller opened this issue Jun 23, 2023 · 5 comments · Fixed by #32287
Closed

[Bug]: 5.5: database host is evaluated to null #32179

speller opened this issue Jun 23, 2023 · 5 comments · Fixed by #32287
Labels
bug Addresses a defect in current functionality. service/rds Issues and PRs that pertain to the rds service.
Milestone

Comments

@speller
Copy link
Contributor

speller commented Jun 23, 2023

Terraform Core Version

1.5.0

AWS Provider Version

5.5.0

Affected Resource(s)

No response

Expected Behavior

Working fine

Actual Behavior

I'm using the database host in other configurations. But after the recent release of version 5.5, I got this weird error:

│ Error: Invalid template interpolation value
│ 
│   on main.tf line 154, in locals:
│  154:     {name: "DATABASE_URL", value: "mysql://${local.db_user}:${local.db_password}@${module.db.host}:${module.db.port}/${local.db_name}?serverVersion=8&charset=utf8mb4"},
│     ├────────────────
│     │ module.db.host is null
│ 
│ The expression result is null. Cannot include a null value in a string
│ template.

The module is defined this way:

output "host" {
  value = var.cluster ? aws_rds_cluster.app-db[0].endpoint : aws_db_instance.app-db[0].address
}

resource "aws_db_instance" "app-db" {
  count = var.cluster ? 0 : 1
  apply_immediately = true
  identifier_prefix = local.infra_name_hyphen
  instance_class = var.instance_type
  allocated_storage = var.storage_size
  max_allocated_storage = var.max_storage_size
  storage_type = var.storage_type
  engine = var.engine
  engine_version = local.db_engine_version_full
  parameter_group_name = aws_db_parameter_group.app-db.name
  username = var.user
  password = var.password
  skip_final_snapshot = var.skip_final_snapshot
  db_subnet_group_name = aws_db_subnet_group.db-nets.name
  db_name = var.initial_db_name
  allow_major_version_upgrade = var.allow_major_version_upgrade
  auto_minor_version_upgrade = true
  vpc_security_group_ids = [
    aws_security_group.app-db.id,
  ]
  snapshot_identifier = var.snapshot_id
  delete_automated_backups = var.delete_automated_backups
  backup_retention_period = var.backup_retention_days
  storage_encrypted = true
  enabled_cloudwatch_logs_exports = var.cloudwatch_logs_export
  multi_az = var.multi_az
  tags = {
    Name = local.infra_name_hyphen
    "cost:env" = var.cost_env
    "cost:app" = var.cost_app
  }
  lifecycle {
    create_before_destroy = true
    ignore_changes = [
      snapshot_identifier,
    ]
  }
}

Related plan:

# module.db.aws_db_instance.app-db[0] will be created
  + resource "aws_db_instance" "app-db" {
      + address                               = (known after apply)
      + allocated_storage                     = 10
      + allow_major_version_upgrade           = false
      + apply_immediately                     = true
      + arn                                   = (known after apply)
      + auto_minor_version_upgrade            = true
      + availability_zone                     = (known after apply)
      + backup_retention_period               = 1
      + backup_window                         = (known after apply)
      + ca_cert_identifier                    = (known after apply)
      + character_set_name                    = (known after apply)
      + copy_tags_to_snapshot                 = false
      + db_name                               = "pkg"
      + db_subnet_group_name                  = "redacted"
      + delete_automated_backups              = true
      + enabled_cloudwatch_logs_exports       = [
          + "slowquery",
        ]
      + endpoint                              = (known after apply)
      + engine                                = "mysql"
      + engine_version                        = "8.0"
      + engine_version_actual                 = (known after apply)
      + hosted_zone_id                        = (known after apply)
      + id                                    = (known after apply)
      + identifier                            = (known after apply)
      + identifier_prefix                     = "redacted"
      + instance_class                        = "db.t4g.micro"
      + iops                                  = (known after apply)
      + kms_key=(sensitive)
      + latest_restorable_time                = (known after apply)
      + license_model                         = (known after apply)
      + listener_endpoint                     = (known after apply)
      + maintenance_window                    = (known after apply)
      + master_user_secret=(sensitive)
      + master_user_secret=(sensitive)
      + max_allocated_storage                 = 0
      + monitoring_interval                   = 0
      + monitoring_role_arn                   = (known after apply)
      + multi_az                              = false
      + nchar_character_set_name              = (known after apply)
      + network_type                          = (known after apply)
      + option_group_name                     = (known after apply)
      + parameter_group_name                  = (known after apply)
      + password=(sensitive)
      + performance_insights_enabled          = false
      + performance_insights_kms_key=(sensitive)
      + performance_insights_retention_period = (known after apply)
      + port                                  = (known after apply)
      + publicly_accessible                   = false
      + replica_mode                          = (known after apply)
      + replicas                              = (known after apply)
      + resource_id                           = (known after apply)
      + skip_final_snapshot                   = true
      + snapshot_identifier                   = (known after apply)
      + status                                = (known after apply)
      + storage_encrypted                     = true
      + storage_throughput                    = (known after apply)
      + storage_type                          = "gp2"
      + timezone                              = (known after apply)
      + username                              = "admin"
      + vpc_security_group_ids                = (known after apply)
    }
  # module.db.aws_db_parameter_group.app-db will be created

And it is created with no issues:

module.db.aws_db_instance.app-db[0]: Creation complete after 1m22s [id=db-H35redacted]

Nothing special. I believe this is related to #31594 when the provider decides that the database is ready when it is not ready.

Restarting the same deployment with no changes fixes the issue.

@speller speller added bug Addresses a defect in current functionality. needs-triage Waiting for first response or review from a maintainer. labels Jun 23, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added the service/rds Issues and PRs that pertain to the rds service. label Jun 23, 2023
@justinretzolk justinretzolk removed the needs-triage Waiting for first response or review from a maintainer. label Jun 23, 2023
@johanneswuerbach
Copy link
Contributor

johanneswuerbach commented Jun 29, 2023

We ran into the same issue and looking into the terraform state, the status of the created instance is status = "creating", which sounds like there is a bug in the waiting logic and the provide stopped waiting for instances to be available 🤔

In our case the instance was newly created using v5.5.0 and a clean state.

@ewbankkit
Copy link
Contributor

I can reproduce this in our acceptance tests:

% make testacc TESTARGS='-run=TestAccRDSInstance_identifierPrefix\|TestAccRDSInstance_identifierGenerated' PKG=rds
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./internal/service/rds/... -v -count 1 -parallel 20  -run=TestAccRDSInstance_identifierPrefix\|TestAccRDSInstance_identifierGenerated -timeout 180m
=== RUN   TestAccRDSInstance_identifierPrefix
=== PAUSE TestAccRDSInstance_identifierPrefix
=== RUN   TestAccRDSInstance_identifierGenerated
=== PAUSE TestAccRDSInstance_identifierGenerated
=== CONT  TestAccRDSInstance_identifierPrefix
=== CONT  TestAccRDSInstance_identifierGenerated
=== NAME  TestAccRDSInstance_identifierPrefix
    instance_test.go:188: Step 2/2 error running import: ImportStateVerify attributes not equivalent. Difference is shown below. The - symbol indicates attributes missing after import.
        
          map[string]string{
        + 	"address":        "tf-acc-test-prefix-20230629185347776800000002.cvflxcqblmy1.us-west-2.rds.amazonaws.com",
        + 	"endpoint":       "tf-acc-test-prefix-20230629185347776800000002.cvflxcqblmy1.us-west-2.rds.amazonaws.com:3306",
        + 	"hosted_zone_id": "Z1PVIF0B656C1W",
        - 	"port":           "0",
        + 	"port":           "3306",
        - 	"status":         "creating",
        + 	"status":         "available",
          }
--- FAIL: TestAccRDSInstance_identifierPrefix (425.76s)
--- PASS: TestAccRDSInstance_identifierGenerated (547.74s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-aws/internal/service/rds	552.980s
FAIL
make: *** [testacc] Error 1

@github-actions github-actions bot added this to the v5.6.0 milestone Jun 29, 2023
@github-actions
Copy link

This functionality has been released in v5.6.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/rds Issues and PRs that pertain to the rds service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants