Skip to content

Commit 78bcef4

Browse files
Merge branch 'main' into feat/azure-private-dns-check
2 parents 55f7adf + 3d9c959 commit 78bcef4

File tree

8 files changed

+387
-30
lines changed

8 files changed

+387
-30
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Terraform Database Example
2+
3+
This creates an example postgres instance using docker.
4+
5+
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.
6+
7+
## Running this module manually
8+
9+
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`.
10+
2. Run `terraform init`.
11+
3. Run `terraform apply`.
12+
4. When you're done, run `terraform destroy`.
13+
14+
## Running automated tests against this module
15+
16+
1. Install [Terraform](https://www.terraform.io/) and make sure it's on your `PATH`.
17+
2. Install [Golang](https://golang.org/) and make sure this code is checked out into your `GOPATH`.
18+
3. `go mod tidy`
19+
4. `go test -v test/terraform_database_example_test.go`
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
terraform {
2+
required_providers {
3+
docker = {
4+
source = "kreuzwerker/docker"
5+
version = "~> 3.0"
6+
}
7+
}
8+
9+
required_version = ">= 1.3.0"
10+
}
11+
12+
provider "docker" {
13+
}
14+
15+
resource "docker_network" "postgres_network" {
16+
name = "postgres_network"
17+
}
18+
19+
resource "docker_volume" "postgres_volume" {
20+
name = "postgres_data"
21+
}
22+
23+
resource "docker_container" "postgres" {
24+
name = "postgres"
25+
image = "postgres:15"
26+
27+
env = [
28+
"POSTGRES_USER=${var.username}",
29+
"POSTGRES_PASSWORD=${var.password}",
30+
"POSTGRES_DB=${var.database_name}"
31+
]
32+
33+
ports {
34+
internal = 5432
35+
external = var.port
36+
}
37+
38+
networks_advanced {
39+
name = docker_network.postgres_network.name
40+
}
41+
42+
restart = "always"
43+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
output "host" {
2+
value = var.host
3+
}
4+
5+
output "port" {
6+
value = var.port
7+
}
8+
9+
output "username" {
10+
value = var.username
11+
}
12+
13+
output "password" {
14+
value = var.password
15+
}
16+
17+
output "database_name" {
18+
value = var.database_name
19+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
variable "host" {
2+
default = "localhost"
3+
}
4+
5+
variable "port" {
6+
default = "32768"
7+
}
8+
9+
variable "username" {
10+
default = "docker"
11+
}
12+
13+
variable "password" {
14+
default = "docker"
15+
}
16+
17+
variable "database_name" {
18+
default = "docker"
19+
}

go.mod

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ require (
3030
github.com/oracle/oci-go-sdk v7.1.0+incompatible
3131
github.com/pquerna/otp v1.4.0
3232
github.com/sirupsen/logrus v1.9.3
33-
github.com/stretchr/testify v1.9.0
33+
github.com/stretchr/testify v1.10.0
3434
github.com/tmccombs/hcl2json v0.6.4
3535
github.com/urfave/cli v1.22.16
3636
github.com/zclconf/go-cty v1.15.0
37-
golang.org/x/crypto v0.31.0
38-
golang.org/x/net v0.31.0
37+
golang.org/x/crypto v0.32.0
38+
golang.org/x/net v0.34.0
3939
golang.org/x/oauth2 v0.24.0
4040
google.golang.org/api v0.206.0
4141
google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f
@@ -46,8 +46,8 @@ require (
4646

4747
require (
4848
cloud.google.com/go/cloudbuild v1.19.0
49-
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0
50-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0
49+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0
50+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
5151
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3 v3.0.0
5252
github.com/aws/aws-sdk-go-v2 v1.32.5
5353
github.com/aws/aws-sdk-go-v2/config v1.28.5
@@ -71,10 +71,12 @@ require (
7171
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1
7272
github.com/aws/aws-sdk-go-v2/service/ssm v1.56.0
7373
github.com/aws/aws-sdk-go-v2/service/sts v1.33.1
74+
github.com/denisenkom/go-mssqldb v0.12.3
7475
github.com/gonvenience/ytbx v1.4.4
7576
github.com/hashicorp/go-getter/v2 v2.2.3
7677
github.com/homeport/dyff v1.6.0
7778
github.com/jackc/pgx/v5 v5.7.1
79+
github.com/lib/pq v1.10.9
7880
github.com/slack-go/slack v0.15.0
7981
gotest.tools/v3 v3.5.1
8082
)
@@ -140,6 +142,8 @@ require (
140142
github.com/go-openapi/swag v0.22.3 // indirect
141143
github.com/gogo/protobuf v1.3.2 // indirect
142144
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
145+
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
146+
github.com/golang-sql/sqlexp v0.1.0 // indirect
143147
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
144148
github.com/golang/protobuf v1.5.4 // indirect
145149
github.com/gonvenience/bunt v1.3.5 // indirect
@@ -203,8 +207,8 @@ require (
203207
go.opentelemetry.io/otel/trace v1.29.0 // indirect
204208
golang.org/x/mod v0.18.0 // indirect
205209
golang.org/x/sync v0.10.0 // indirect
206-
golang.org/x/sys v0.28.0 // indirect
207-
golang.org/x/term v0.27.0 // indirect
210+
golang.org/x/sys v0.29.0 // indirect
211+
golang.org/x/term v0.28.0 // indirect
208212
golang.org/x/text v0.21.0 // indirect
209213
golang.org/x/time v0.8.0 // indirect
210214
golang.org/x/tools v0.22.0 // indirect

0 commit comments

Comments
 (0)