Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save staticaland/eaa6a925de36dd191dd7200e27a4f046 to your computer and use it in GitHub Desktop.
Save staticaland/eaa6a925de36dd191dd7200e27a4f046 to your computer and use it in GitHub Desktop.
terraform_import_enable_global_write_forwarding

When importing a resource into Terraform, certain parameters might not cause any changes in the actual AWS API calls, which can lead to confusion.

Parameter State Handling

  1. Terraform Parameter Tracking:

    • Terraform tracks the parameters within its state file.
    • When you set a parameter like enable_global_write_forwarding = false in Terraform, it does not necessarily result in an API call to AWS. Instead, it updates Terraform's state.
  2. AWS Parameter Representation:

    • In AWS, parameters like enable_global_write_forwarding might not have a direct equivalent for false. If this parameter is set to false in Terraform, AWS might not register any change because the parameter doesn't get included in the API call.

Practical Example

For the enable_global_write_forwarding parameter:

  • In Terraform: Setting enable_global_write_forwarding = false updates Terraform's state.
  • In AWS: No change occurs in AWS because the parameter false does not result in an API call.

When you import a resource into Terraform, Terraform reads the current state from AWS. Since AWS does not register the false value for the parameter, Terraform can't detect this state during import, leading to potential discrepancies.

Example Command Explanation

The provided AWS CLI command:

aws rds describe-db-clusters --query '*[].{DBClusterIdentifier:DBClusterIdentifier,GlobalWriteForwardingStatus:GlobalWriteForwardingStatus}'

This command fetches details about your RDS DB clusters, specifically:

  • DBClusterIdentifier: The unique identifier of the DB cluster.
  • GlobalWriteForwardingStatus: The status of global write forwarding for the DB cluster.

By running this command, you can:

  1. List all your DB clusters.
  2. Check the GlobalWriteForwardingStatus to see if it aligns with your Terraform configuration.

Summary

When dealing with parameters like enable_global_write_forwarding, it's crucial to understand that setting them in Terraform may only update Terraform's state and not trigger an AWS API call. As a result, during the import process, Terraform might not detect the false state because AWS does not track it. Using AWS CLI commands helps verify the actual state in AWS, ensuring that your Terraform configurations align correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment