Using Replit Agent? Learn how to add a configured Postgres database to your apps with a single prompt
Docs/Terraform

Neon Terraform provider

community

Neon sponsors the following community-developed Terraform provider for managing Neon Postgres platform resources:

Terraform Provider Neon — Maintainer: Dmitry Kisler

note

This provider is not maintained or officially supported by Neon. Use at your own discretion. If you have questions about the provider, please contact the project maintainer.

Provider usage notes

  • Provider upgrades: When using terraform init -upgrade to update a custom Terraform provider, be aware that changes in the provider’s schema or defaults can lead to unintended resource replacements. This may occur when certain attributes are altered or reset. For example, fields previously set to specific values might be reset to null, forcing the replacement of the entire resource.

    To avoid unintended resource replacements which can result in data loss:

    • Review the provider’s changelog for any breaking changes that might affect your resources before upgrading to a new version.
    • For CI pipelines and auto-approved pull requests, only use terraform init. Running terraform init -upgrade should be done manually followed by plan reviews.
    • Run terraform plan before applying any changes to detect potential differences and review the behavior of resource updates.
    • Use lifecycle protections on critical resources to ensure they're not recreated unintentionally.
    • Explicitly define all critical resource parameters in your Terraform configurations, even if they had defaults previously.
    • On Neon paid plans, you can enable branch protection to prevent unintended deletion of branches and projects. To learn more, see Protected branches.
  • Provider maintenance: As Neon enhances existing features and introduces new ones, the Neon API will continue to evolve. These changes may not immediately appear in community-maintained Terraform providers. If you notice that a provider requires an update, please reach out to the maintainer by opening an issue or contributing to the provider's GitHub repository.

Example application

The following example application demonstrates how to set up Terraform, connect to a Neon Postgres database, and perform a Terraform run that inserts data. It covers how to:

  • Use Go's os/exec package to run Terraform commands
  • Write a Go test function to validate Terraform execution
  • Execute Terraform commands such as init, plan, and apply

View the YouTube tutorial: Neon Postgres for Terraform with Go.

Resources

Last updated on

Was this page helpful?