hashicorp / terraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.
https://www.terraform.io/
Other
42.6k stars 9.54k forks source link

PostgreSQL provider #3650

Closed ringods closed 8 years ago

ringods commented 9 years ago

One of the last pieces missing for me to complete a full Terraform setup is a PostgreSQL provider. One of my colleagues is already working on this, but I wanted to chime in to see whether this work could get accepted upstream.

My AWS setup ends currently with the creation of an RDS instance, but I want the ability to create more than one database on this server, with more than a single owner role. That's what the PostgreSQL provider is for.

The initial resources which will be supported are:

An example of how it would show in Terraform:

# These are the PostgreSQL resources I would like to create:
resource "postgresql_role" "rq_db_user" {
  host = "${aws_db_instance.rq_web_api_rds.address}
  username = "${var.admin_user}"
  password = "${var.admin_password}"
  name = "rq_database_user"
  login = "true"
}

resource "postgresql_db" "rq_database" {
  host = "${aws_db_instance.address}
  username = "${var.admin_user}"
  password = "${var.admin_password}"
  name = "rq_database"
  owner = "${postgresql_role.rq_db_user.name} 
}

If this is something which might be helpful for Terraform, we will submit a pull request shortly to accompany this ticket.

ringods commented 9 years ago

@catsby I very much hope this ends in upstream. A general remark I have is that any provider which doesn't make it in upstream, can't be used in Atlas. Or are you guys working on a way for Atlas to pull third-party providers?

mvdkleijn commented 9 years ago

Possibly a silly question from my end, but wouldn't this fall into the realm of a Chef provisioner instead of a provider?

If I understood correctly, providers exist to provide the "hardware" (of sorts) and the provisioners to configure / setup that hardware further. Seems to me that PostgreSQL would be a classic example of "provisioning software on hardware provided by XYZ" (openstack for example)

Edit: in other words... you'd probably be better off writing a Chef cookbook?

apparentlymart commented 9 years ago

This seems like a natural complement to #3122, with similar motivations.

In particular, provisioning the database with Chef implies that the database is running on a server to which you have SSH access. That is not true when you are using a service like Amazon RDS where the only access you have is via the database's native network protocol.

mvdkleijn commented 9 years ago

I can see your point regarding RDS. My feeling is that this should be a provisioner instead of a provider, but I was just curious. :smile:

ringods commented 8 years ago

@mvdkleijn My take on having the PostgreSQL support as a provider comes from Terraform's own documentation:

Terraform provides a flexible abstraction of resources and providers. 
This model allows for representing everything from physical hardware, 
virtual machines, and containers, to email and DNS providers.

You can use a provisioner to install bind and it's configuration on a Linux machine, but if you want to rely on DNS as a service, then it's well suited for a provider. In my view, DNS is not much different from a database service. In the AWS RDS case, you get a pre-provisioned machine with PostgreSQL. From there on, I consider it PostgreSQL-as-a-Service, which then matches the Terraform description of a provider.

My short-sighted view:

ringods commented 8 years ago

Given the fact the Google SQL provider (instance+database) pull request (#3617) is merged into upstream, I think the generic PostgreSQL provider pull request (#3653) and generic MySQL provider pull request (#3122) should end up in 0.6.7 too!

All of this database support in the same version, now wouldn't that be handy? :-)

apparentlymart commented 8 years ago

This was fixed by closing #3653. If folks want to add additional resources to this provider, let's make separate issues and/or pull requests for those.

ghost commented 4 years ago

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.