Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update examples and use Terraform test framework #135

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Test
on:
pull_request:
branches:
- main
jobs:
test:
name: Unit Tests
uses: equinor/terraform-baseline/.github/workflows/terraform-test.yml@main
with:
test-filter: tests/unit.tftest.hcl
39 changes: 21 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,45 +14,48 @@ See [examples](examples).

## Development

1. Read [this document](https://code.visualstudio.com/docs/devcontainers/containers).
1. Clone this repository:

1. Clone this repository.

1. Configure Terraform variables in a file `.devcontainer/devcontainer.env`:

```env
TF_VAR_resource_group_name=
TF_VAR_location=
```console
git clone https://github.com/equinor/terraform-azurerm-sql.git
```

1. Open repository in dev container.
1. Login to Azure:

## Testing
```console
az login
```

1. Change to the test directory:
1. Set active subscription:

```console
cd test
az account set -s <SUBSCRIPTION_NAME_OR_ID>
```

1. Login to Azure:
1. Set environment variables:

```console
az login
export TF_VAR_resource_group_name=<RESOURCE_GROUP_NAME>
export TF_VAR_location=<LOCATION>
export ARM_SKIP_PROVIDER_REGISTRATION=true
```

1. Set active subscription:
## Testing

1. Initialize working directory:

```console
az account set -s <SUBSCRIPTION_NAME_OR_ID>
terraform init
```

1. Run tests:
1. Execute tests:

```console
go test -timeout 60m
terraform test
```

See [`terraform test` command documentation](https://developer.hashicorp.com/terraform/cli/commands/test) for options.

## Contributing

See [Contributing guidelines](CONTRIBUTING.md).
19 changes: 16 additions & 3 deletions examples/basic/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ resource "random_id" "this" {
}

module "log_analytics" {
source = "github.com/equinor/terraform-azurerm-log-analytics?ref=v1.5.0"
source = "equinor/log-analytics/azurerm"
version = "2.2.0"

workspace_name = "log-${random_id.this.hex}"
resource_group_name = var.resource_group_name
location = var.location
}

module "storage" {
source = "github.com/equinor/terraform-azurerm-storage?ref=v11.0.0"
source = "equinor/storage/azurerm"
version = "12.3.0"

account_name = "st${random_id.this.hex}"
resource_group_name = var.resource_group_name
Expand All @@ -28,7 +30,8 @@ module "storage" {
}

module "sql" {
# source = "github.com/equinor/terraform-azurerm-sql?ref=v0.0.0"
# source = "equinor/sql/azurerm"
# version = "0.0.0"
source = "../.."

server_name = "sql-${random_id.this.hex}"
Expand All @@ -41,3 +44,13 @@ module "sql" {
azuread_administrator_login_username = "azureadadminlogin"
azuread_administrator_object_id = data.azurerm_client_config.current.object_id
}

module "database" {
# source = "equinor/sql/azurerm//modules/database"
# version = "0.0.0"
source = "../../modules/database"

database_name = "sqldb-${random_id.this.hex}"
server_id = module.sql.server_id
log_analytics_workspace_id = module.log_analytics.workspace_id
}
31 changes: 28 additions & 3 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ resource "random_id" "this" {
}

module "log_analytics" {
source = "github.com/equinor/terraform-azurerm-log-analytics?ref=v1.5.0"
source = "equinor/log-analytics/azurerm"
version = "2.2.0"

workspace_name = "log-${random_id.this.hex}"
resource_group_name = var.resource_group_name
location = var.location
}

module "storage" {
source = "github.com/equinor/terraform-azurerm-storage?ref=v10.3.0"
source = "equinor/storage/azurerm"
version = "12.3.0"

account_name = "st${random_id.this.hex}"
resource_group_name = var.resource_group_name
Expand All @@ -34,7 +36,8 @@ module "storage" {
}

module "sql" {
# source = "github.com/equinor/terraform-azurerm-sql?ref=v0.0.0"
# source = "equinor/sql/azurerm"
# version = "0.0.0"
source = "../.."

server_name = "sql-${random_id.this.hex}"
Expand Down Expand Up @@ -63,3 +66,25 @@ module "sql" {

tags = local.tags
}

module "database" {
# source = "equinor/sql/azurerm//modules/database"
# version = "0.0.0"
source = "../../modules/database"

database_name = "sqldb-${random_id.this.hex}"
server_id = module.sql.server_id
log_analytics_workspace_id = module.log_analytics.workspace_id

sku_name = "Basic"
storage_account_type = "Geo"
max_size_gb = 2

short_term_retention_policy_retention_days = 7
short_term_retention_policy_backup_interval_in_hours = 12

long_term_retention_policy_weekly_retention = "PT0S"
long_term_retention_policy_monthly_retention = "PT0S"
long_term_retention_policy_yearly_retention = "PT0S"
long_term_retention_policy_week_of_year = 1
}
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ resource "azurerm_monitor_diagnostic_setting" "this" {
}
}

# Metrics are not supported at the master database scope.
# Metrics are not supported at the master database scope.
metric {
category = "Basic"
enabled = false
Expand Down
17 changes: 0 additions & 17 deletions test/basic_example_test.go

This file was deleted.

17 changes: 0 additions & 17 deletions test/complete_example_test.go

This file was deleted.

56 changes: 0 additions & 56 deletions test/go.mod

This file was deleted.

Loading