Skip to content

Commit

Permalink
fix: add attribute deletion_policy in the google_service_networking_c…
Browse files Browse the repository at this point in the history
…onnection to fix terratest failure| DEVOP-4496 (#42)

* fix: add attribute deletion_policy in the google_service_networking_connection | DEVOP-4496

* fix: semaetic pr fix
  • Loading branch information
bibek4699 authored Jun 17, 2024
1 parent f766c84 commit bf3c00c
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 126 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/checkov.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Checkov GitHub Action"
permissions: read-all

on:
pull_request:
branches: [test, dev, qa, prod, main]

jobs:
checkov:
name: checkov
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: "recursive"
token: ${{ secrets.GITHUB_TOKEN }}
- name: Create empty baseline (if needed)
run: |
if [ -f .checkov.baseline ]; then
echo "⏩⏩⏩ Baseline file exists - do nothing."
else
echo "🆕🆕🆕 Baseline file does not exist - creating empty baseline file."
echo "{}" >> .checkov.baseline
fi
- name: Output baseline contents to console
run: |
echo "Checkov baseline file (.checkov.baseline) contents:"
cat .checkov.baseline
- name: Run Checkov
id: checkov
uses: bridgecrewio/checkov-action@master
with:
config_file: ".checkov.yaml"
23 changes: 0 additions & 23 deletions .github/workflows/checkov.yml

This file was deleted.

6 changes: 3 additions & 3 deletions .github/workflows/semantic-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Semantic Pull Request"
name: "semantic-pull-request"
permissions: read-all

on:
Expand All @@ -10,10 +10,10 @@ on:

jobs:
main:
name: Semantic Pull Request
name: semantic-pull-request
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v4
- uses: amannn/action-semantic-pull-request@v5
name: Semantic Pull Request
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0 # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases
rev: v4.6.0 # Get the latest from: https://github.com/pre-commit/pre-commit-hooks/releases
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/antonbabenko/pre-commit-terraform
rev: v1.83.2 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
rev: v1.91.0 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
hooks:
- id: terraform_fmt
- id: terraform_docs
Expand All @@ -24,7 +24,7 @@ repos:
- id: terraform_checkov
exclude: (test/|examples/)
- repo: https://github.com/gitguardian/ggshield
rev: v1.18.1 # Update to latest version by running `pre-commit autoupdate`
rev: v1.28.0 # Update to latest version by running `pre-commit autoupdate`
hooks:
- id: ggshield
language: python
Expand Down
1 change: 0 additions & 1 deletion examples/create_mysql_instance_with_private_ip/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module "test_sql_database_instance_private_ip" {

depends_on = [module.google_service_networking_connection_private_vpc_connection]


settings_backup_configuration_binary_log_enabled = var.settings_backup_configuration_binary_log_enabled
settings_backup_configuration_enabled = var.settings_backup_configuration_enabled
settings_ip_configuration_ipv4_enabled = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ user_host = "%"
user_type = "BUILT_IN"
user_name = "sql-user"

settings_tier = "db-f1-micro"
settings_tier = "db-g1-small"
settings_availability_type = "ZONAL"
settings_disk_size = 10
settings_disk_type = "PD_SSD"
Expand Down
8 changes: 5 additions & 3 deletions examples/mysql_instance_with_read_replica/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,20 @@ module "google_service_networking_connection_private_vpc_connection" {
network = module.google_compute_network_private_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [module.google_compute_global_address_private_ip.name]
deletion_policy = "ABANDON"
}

module "sql_database_instance" {
source = "../../modules/google_sql_database_instance"

depends_on = [
module.google_service_networking_connection_private_vpc_connection
]

name = "sql-rr-${random_id.instance_suffix.hex}"
#checkov:skip=CKV_GCP_79:Ensure SQL database is using latest Major version"
database_version = "MYSQL_8_0"

depends_on = [module.google_service_networking_connection_private_vpc_connection]


settings_backup_configuration_binary_log_enabled = var.settings_backup_configuration_binary_log_enabled
settings_backup_configuration_enabled = var.settings_backup_configuration_enabled

Expand Down
1 change: 1 addition & 0 deletions examples/postgres_instance_with_read_replica/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module "google_service_networking_connection_private_vpc_connection" {
network = module.google_compute_network_private_network.id
service = "servicenetworking.googleapis.com"
reserved_peering_ranges = [module.google_compute_global_address_private_ip.name]
deletion_policy = "ABANDON"
}

module "sql_database_instance" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ user_host = null
user_type = "BUILT_IN"
user_name = "sql-user"

settings_tier = "db-f1-micro"
settings_tier = "db-g1-small"
settings_availability_type = "REGIONAL"
settings_disk_size = 10
settings_disk_type = "PD_SSD"
Expand Down
1 change: 1 addition & 0 deletions modules/google_service_networking_connection/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ resource "google_service_networking_connection" "network" {
network = var.network
service = var.service
reserved_peering_ranges = var.reserved_peering_ranges
deletion_policy = var.deletion_policy
}
6 changes: 6 additions & 0 deletions modules/google_service_networking_connection/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ variable "reserved_peering_ranges" {
description = "(Required) Named IP address range(s) of PEERING type reserved for this service provider. Note that invoking this method with a different range when connection is already established will not reallocate already provisioned service producer subnetworks."
type = list(string)
}

variable "deletion_policy" {
description = "(Optional) The deletion policy for the peering. One of 'DELETE' or 'ABANDON'. Defaults to 'DELETE'."
type = string
default = ""
}
91 changes: 0 additions & 91 deletions test/gcp_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,97 +12,6 @@ import (
func TestTerraformCreateGCPSQL(t *testing.T) {
t.Parallel()

//t.Run("create mysql with public ip", func(t *testing.T) {
// t.Parallel()
//
// testDirectory := test_structure.CopyTerraformFolderToTemp(t, "..", "examples/create_mysql_instance_with_public_ip")
//
// // retryable errors in terraform testing.
// terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// TerraformDir: testDirectory,
// })
//
// defer terraform.Destroy(t, terraformOptions)
//
// terraform.InitAndApply(t, terraformOptions)
//
// var output string
//
// output = terraform.Output(t, terraformOptions, "random_string")
// assert.NotEmpty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_terraform_sql_instance_name")
// assert.Contains(t, output, "sql-public")
//
// output = terraform.Output(t, terraformOptions, "test_terraform_sql_self_link")
// assert.Contains(t, output, "sql-public")
//
// output = terraform.Output(t, terraformOptions, "test_terraform_sql_service_account_email_address")
// assert.NotEmpty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_terraform_sql_connection_name")
// assert.NotEmpty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_sql_user_name")
// assert.Equal(t, output, "sql-user")
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_1_id")
// assert.Contains(t, output, "db-first")
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_2_id")
// assert.Contains(t, output, "db-second")
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_public_ip_address")
// assert.NotEmpty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_private_ip_address")
// assert.Empty(t, output)
//})
//
//t.Run("create mysql with private ip", func(t *testing.T) {
// t.Parallel()
//
// testDirectory := test_structure.CopyTerraformFolderToTemp(t, "..", "examples/create_mysql_instance_with_private_ip")
//
// // retryable errors in terraform testing.
// terraformOptions := terraform.WithDefaultRetryableErrors(t, &terraform.Options{
// TerraformDir: testDirectory,
// })
//
// defer terraform.Destroy(t, terraformOptions)
//
// terraform.InitAndApply(t, terraformOptions)
//
// var output string
//
// output = terraform.Output(t, terraformOptions, "random_string")
// assert.NotEmpty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_instance_name")
// assert.Contains(t, output, "sql-private")
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_self_link")
// assert.Contains(t, output, "sql-private")
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_service_account_email_address")
// assert.NotEmpty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_connection_name")
// assert.NotEmpty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_sql_user_name")
// assert.Equal(t, output, "sql-user")
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_id")
// assert.Contains(t, output, "db-first")
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_public_ip_address")
// assert.Empty(t, output)
//
// output = terraform.Output(t, terraformOptions, "test_sql_database_instance_private_ip_private_ip_address")
// assert.NotEmpty(t, output)
//})

t.Run("create mysql with read replica", func(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit bf3c00c

Please sign in to comment.