-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/azure-private-dns-check
- Loading branch information
Showing
8 changed files
with
387 additions
and
30 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Terraform Database Example | ||
|
||
This creates an example postgres instance using docker. | ||
|
||
Check out [test/terraform_database_example_test.go](/test/terraform_database_example_test.go) to see how you can write automated tests for database. In order to make go test code work, you need to provide host, port, username, password and database name of a existing database, which you have already created on cloud platform or using docker before testing. Only Microsoft SQL Server, PostgreSQL and MySQL are supported. | ||
|
||
## Running this module manually | ||
|
||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. | ||
2. Run `terraform init`. | ||
3. Run `terraform apply`. | ||
4. When you're done, run `terraform destroy`. | ||
|
||
## Running automated tests against this module | ||
|
||
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`. | ||
2. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`. | ||
3. `go mod tidy` | ||
4. `go test -v test/terraform_database_example_test.go` |
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,43 @@ | ||
terraform { | ||
required_providers { | ||
docker = { | ||
source = "kreuzwerker/docker" | ||
version = "~> 3.0" | ||
} | ||
} | ||
|
||
required_version = ">= 1.3.0" | ||
} | ||
|
||
provider "docker" { | ||
} | ||
|
||
resource "docker_network" "postgres_network" { | ||
name = "postgres_network" | ||
} | ||
|
||
resource "docker_volume" "postgres_volume" { | ||
name = "postgres_data" | ||
} | ||
|
||
resource "docker_container" "postgres" { | ||
name = "postgres" | ||
image = "postgres:15" | ||
|
||
env = [ | ||
"POSTGRES_USER=${var.username}", | ||
"POSTGRES_PASSWORD=${var.password}", | ||
"POSTGRES_DB=${var.database_name}" | ||
] | ||
|
||
ports { | ||
internal = 5432 | ||
external = var.port | ||
} | ||
|
||
networks_advanced { | ||
name = docker_network.postgres_network.name | ||
} | ||
|
||
restart = "always" | ||
} |
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 "host" { | ||
value = var.host | ||
} | ||
|
||
output "port" { | ||
value = var.port | ||
} | ||
|
||
output "username" { | ||
value = var.username | ||
} | ||
|
||
output "password" { | ||
value = var.password | ||
} | ||
|
||
output "database_name" { | ||
value = var.database_name | ||
} |
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 @@ | ||
variable "host" { | ||
default = "localhost" | ||
} | ||
|
||
variable "port" { | ||
default = "32768" | ||
} | ||
|
||
variable "username" { | ||
default = "docker" | ||
} | ||
|
||
variable "password" { | ||
default = "docker" | ||
} | ||
|
||
variable "database_name" { | ||
default = "docker" | ||
} |
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
Oops, something went wrong.