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

Cannot set null/undefined value for rds instances' port. #1874

Closed
l01cd3v opened this issue Oct 12, 2017 · 2 comments
Closed

Cannot set null/undefined value for rds instances' port. #1874

l01cd3v opened this issue Oct 12, 2017 · 2 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/rds Issues and PRs that pertain to the rds service. upstream-terraform Addresses functionality related to the Terraform core binary.

Comments

@l01cd3v
Copy link

l01cd3v commented Oct 12, 2017

Terraform Version

Terraform v0.10.7

Affected Resource(s)

aws_db_instance

Terraform Configuration Files

resource "aws_db_instance" "myrds" {

    name = "mydb"
    instance_class = "db.t2.small"
    engine = "postgres"
    allocated_storage = 20
    storage_type = "gp2"
    username = "test"
    password = "testtest"
    port = 0
}

Debug Output

https://gist.github.com/l01cd3v/0ea630ea620eae9519e9a12535ddc5c3

Expected Behavior

The 0 value should be discarded and replaced with the "" value, both when creating and updating the instance.

Actual Behavior

Terraform attempts to create/update the DB and set the port to 0.
When creating the DB, AWS discards this value and uses the default port; terraform succeeds.
When updating, AWS throws an error because 0 is not an authorized value, terraform fails.

Steps to Reproduce

Using the sample configuration file, run the following:

  1. terraform init
  2. terraform plan (confirm 0 and not for port value)
  3. terraform apply (confirm success)
  4. terraform plan (confirm port change 3306 -> 0)
  5. terraform apply (confirm failure)

Important Factoids

None

References

Seems similar to #1544, which references hashicorp/terraform#5471 (comment)

@radeksimko radeksimko added enhancement Requests to existing resources that expand the functionality or scope. upstream-terraform Addresses functionality related to the Terraform core binary. labels Oct 15, 2017
@radeksimko radeksimko added the service/rds Issues and PRs that pertain to the rds service. label Jan 28, 2018
@bflad
Copy link
Contributor

bflad commented Jul 24, 2019

Hi folks 👋 This issue is resolved in Terraform 0.12, which supports new functionality in the configuration language aimed at solving this issue. The new null value can be used to omit arguments as if they were not defined in the configuration at all. For doing similar with configuration blocks, please see the new dynamic block syntax.

Given this configuration:

# The port argument is a hardcoded null in this illustrative example,
# however it can be sourced from a variable or local value.

resource "aws_db_instance" "test" {
  allocated_storage   = 5
  engine              = "postgres"
  identifier          = "null-testing"
  instance_class      = "db.t2.micro"
  password            = "avoid-plaintext-passwords"
  port                = null
  username            = "testing"
  skip_final_snapshot = true
}

Produces the following plan output:

$ terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # aws_db_instance.test will be created
  + resource "aws_db_instance" "test" {
      + address                               = (known after apply)
      + allocated_storage                     = 5
      + apply_immediately                     = (known after apply)
      + arn                                   = (known after apply)
      + auto_minor_version_upgrade            = true
      + availability_zone                     = (known after apply)
      + backup_retention_period               = (known after apply)
      + backup_window                         = (known after apply)
      + ca_cert_identifier                    = (known after apply)
      + character_set_name                    = (known after apply)
      + copy_tags_to_snapshot                 = false
      + db_subnet_group_name                  = (known after apply)
      + endpoint                              = (known after apply)
      + engine                                = "postgres"
      + engine_version                        = (known after apply)
      + hosted_zone_id                        = (known after apply)
      + id                                    = (known after apply)
      + identifier                            = "null-testing"
      + identifier_prefix                     = (known after apply)
      + instance_class                        = "db.t2.micro"
      + kms_key_id                            = (known after apply)
      + license_model                         = (known after apply)
      + maintenance_window                    = (known after apply)
      + monitoring_interval                   = 0
      + monitoring_role_arn                   = (known after apply)
      + multi_az                              = (known after apply)
      + name                                  = (known after apply)
      + option_group_name                     = (known after apply)
      + parameter_group_name                  = (known after apply)
      + password                              = (sensitive value)
      + performance_insights_enabled          = false
      + performance_insights_kms_key_id       = (known after apply)
      + performance_insights_retention_period = (known after apply)
      + port                                  = (known after apply)
      + publicly_accessible                   = false
      + replicas                              = (known after apply)
      + resource_id                           = (known after apply)
      + skip_final_snapshot                   = true
      + status                                = (known after apply)
      + storage_type                          = (known after apply)
      + timezone                              = (known after apply)
      + username                              = "testing"
      + vpc_security_group_ids                = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Enjoy! 🚀

@bflad bflad closed this as completed Jul 24, 2019
@ghost
Copy link

ghost commented Nov 2, 2019

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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks!

@ghost ghost locked and limited conversation to collaborators Nov 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. service/rds Issues and PRs that pertain to the rds service. upstream-terraform Addresses functionality related to the Terraform core binary.
Projects
None yet
Development

No branches or pull requests

3 participants