-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from openoakland/postgresdb
Refactor modules to pull out postgres database
- Loading branch information
Showing
18 changed files
with
262 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
*.lock.info | ||
*.tfplan | ||
*.tfstore | ||
*.tfstate | ||
*.tfstate.backup | ||
terraform.tfvars | ||
.terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# beanstalk_app | ||
|
||
Creates an Elastic Beanstalk app. | ||
|
||
## Usage | ||
|
||
```hcl | ||
module "myapp" { | ||
source = "github.com/openoakland/terraform-modules.git//beanstalk_app?ref=2.0.0 | ||
app_name = "myapp" | ||
} | ||
``` | ||
|
||
### Variables | ||
|
||
See [beanstalk_app/variables.tf](./variables.tf). | ||
|
||
|
||
### Outputs | ||
|
||
N/A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# beanstalk_web_env | ||
|
||
Creates an AWS Elastic Beanstalk web environment with load balancer and auto | ||
scaling group. | ||
|
||
|
||
## Usage | ||
|
||
```hcl | ||
module "myapp" { | ||
source = "github.com/openoakland/terraform-modules.git//beanstalk_app?ref=2.0.0 | ||
app_name = "myapp" | ||
} | ||
module "myapp_prod_web" { | ||
source = "github.com/openoakland/terraform-modules//beanstalk_web_env?ref=v2.0.0" | ||
app_name = "myapp" | ||
app_instance = "production" | ||
dns_zone_name = "myapp.aws.example.com" | ||
dns_zone_id = "${aws_route53_zone.myapp_zone.id}" | ||
environment_variables { | ||
DATABASE_URL = "postgres://dbuser:dbpassword@dbhost/dbname" | ||
} | ||
} | ||
``` | ||
|
||
### Variables | ||
|
||
See [beanstalk_web_env/variables.tf](./variables.tf). | ||
|
||
|
||
### Outputs | ||
|
||
See [beanstalk_web_env/outputs.tf](./outputs.tf). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
output "cname" { | ||
description = "CNAME of the created Beanstalk environment." | ||
value = "${aws_elastic_beanstalk_environment.environment.cname}" | ||
} | ||
|
||
output "fqdn" { | ||
description = "Public FQDN of the created Beanstalk environment." | ||
value = "${aws_route53_record.environment.fqdn}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# postgresd | ||
|
||
Creates a PostgreSQL RDS database instnace. | ||
|
||
|
||
## Usage | ||
|
||
```hcl | ||
module "db" { | ||
source = "github.com/openoakland/terraform-modules.git//postgresdb?ref=2.0.0 | ||
db_name = "myapp_db" | ||
db_password = "${var.db_password}" | ||
db_username = "myappuser" | ||
namespace = "myapp-prod" | ||
} | ||
``` | ||
|
||
### Variables | ||
|
||
See [postgresdb/variables.tf](./variables.tf). | ||
|
||
|
||
### Outputs | ||
|
||
See [postgresdb/outputs.tf](./outputs.tf). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
resource "aws_security_group" "allowed" { | ||
name = "${var.namespace}-db-access" | ||
} | ||
|
||
resource "aws_security_group" "database" { | ||
name = "${var.namespace}-db" | ||
|
||
// Allow HTTP connections from the application instances | ||
ingress { | ||
from_port = 5432 | ||
to_port = 5432 | ||
protocol = "tcp" | ||
|
||
security_groups = ["${aws_security_group.allowed.id}"] | ||
} | ||
} | ||
|
||
resource "aws_db_instance" "database" { | ||
allocated_storage = 20 | ||
storage_type = "gp2" | ||
engine = "postgres" | ||
engine_version = "10.5" | ||
instance_class = "db.t2.micro" | ||
deletion_protection = "${var.deletion_protection}" | ||
identifier = "${var.namespace}" | ||
final_snapshot_identifier = "${var.namespace}-final" | ||
name = "${var.db_name}" | ||
username = "${var.db_username}" | ||
password = "${var.db_password}" | ||
publicly_accessible = "false" | ||
backup_retention_period = "7" | ||
backup_window = "10:00-10:30" | ||
skip_final_snapshot = "${var.skip_final_snapshot}" | ||
|
||
vpc_security_group_ids = [ | ||
"${aws_security_group.database.id}", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
output "database_url" { | ||
description = "DATABASE_URL to configure for applications to use this database." | ||
value = "postgresql://${var.db_username}:${var.db_password}@${aws_db_instance.database.endpoint}/${var.db_name}" | ||
} | ||
|
||
output "postgis_database_url" { | ||
description = "DATABASE_URL to configure for applications to use this database, with postgis:// prefix." | ||
value = "postgis://${var.db_username}:${var.db_password}@${aws_db_instance.database.endpoint}/${var.db_name}" | ||
} | ||
|
||
output "security_group_id" { | ||
description = "Id of the security group with access to database." | ||
value = "${aws_security_group.allowed.id}" | ||
} | ||
|
||
output "security_group_name" { | ||
description = "Name of the security group with access to database." | ||
value = "${aws_security_group.allowed.name}" | ||
} |
Oops, something went wrong.