Skip to content

Commit

Permalink
Merge branch 'main' into feat/azure-private-dns-check
Browse files Browse the repository at this point in the history
  • Loading branch information
johannes-engler-mw authored Jan 22, 2025
2 parents 55f7adf + 3d9c959 commit 78bcef4
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 30 deletions.
19 changes: 19 additions & 0 deletions examples/terraform-database-example/REAME.md
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`
43 changes: 43 additions & 0 deletions examples/terraform-database-example/main.tf
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"
}
19 changes: 19 additions & 0 deletions examples/terraform-database-example/outputs.tf
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
}
19 changes: 19 additions & 0 deletions examples/terraform-database-example/variables.tf
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"
}
18 changes: 11 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ require (
github.com/oracle/oci-go-sdk v7.1.0+incompatible
github.com/pquerna/otp v1.4.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/stretchr/testify v1.10.0
github.com/tmccombs/hcl2json v0.6.4
github.com/urfave/cli v1.22.16
github.com/zclconf/go-cty v1.15.0
golang.org/x/crypto v0.31.0
golang.org/x/net v0.31.0
golang.org/x/crypto v0.32.0
golang.org/x/net v0.34.0
golang.org/x/oauth2 v0.24.0
google.golang.org/api v0.206.0
google.golang.org/genproto v0.0.0-20241113202542-65e8d215514f
Expand All @@ -46,8 +46,8 @@ require (

require (
cloud.google.com/go/cloudbuild v1.19.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.14.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.7.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appcontainers/armappcontainers/v3 v3.0.0
github.com/aws/aws-sdk-go-v2 v1.32.5
github.com/aws/aws-sdk-go-v2/config v1.28.5
Expand All @@ -71,10 +71,12 @@ require (
github.com/aws/aws-sdk-go-v2/service/sqs v1.37.1
github.com/aws/aws-sdk-go-v2/service/ssm v1.56.0
github.com/aws/aws-sdk-go-v2/service/sts v1.33.1
github.com/denisenkom/go-mssqldb v0.12.3
github.com/gonvenience/ytbx v1.4.4
github.com/hashicorp/go-getter/v2 v2.2.3
github.com/homeport/dyff v1.6.0
github.com/jackc/pgx/v5 v5.7.1
github.com/lib/pq v1.10.9
github.com/slack-go/slack v0.15.0
gotest.tools/v3 v3.5.1
)
Expand Down Expand Up @@ -140,6 +142,8 @@ require (
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gonvenience/bunt v1.3.5 // indirect
Expand Down Expand Up @@ -203,8 +207,8 @@ require (
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.8.0 // indirect
golang.org/x/tools v0.22.0 // indirect
Expand Down
Loading

0 comments on commit 78bcef4

Please sign in to comment.