forked from GoogleCloudPlatform/DataflowTemplates
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e897c4f
commit 1033f23
Showing
81 changed files
with
4,568 additions
and
21 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,86 @@ | ||
name: Spanner to Source DB Unit Test | ||
|
||
on: | ||
push: | ||
paths: | ||
- 'v2/spanner-to-sourcedb/**' | ||
- '.github/workflows/spanner-sourcedb.yml' | ||
# branches: [ main ] | ||
pull_request: | ||
paths: | ||
- 'v2/spanner-to-sourcedb/**' | ||
# branches: [ main ] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
cache: maven | ||
|
||
- name: Cache Maven packages | ||
uses: actions/cache@v3 | ||
with: | ||
path: ~/.m2 | ||
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} | ||
restore-keys: ${{ runner.os }}-m2 | ||
|
||
- name: Run Tests | ||
run: | | ||
cd v2/spanner-to-sourcedb | ||
mvn test | ||
- name: Generate Test Report | ||
if: success() || failure() | ||
run: | | ||
cd v2/spanner-to-sourcedb | ||
mvn surefire-report:report-only | ||
- name: Upload Test Results | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: test-results | ||
path: v2/spanner-to-sourcedb/target/site/surefire-report.html | ||
|
||
- name: Upload Coverage Results | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: coverage-results | ||
path: v2/spanner-to-sourcedb/target/site/jacoco/ | ||
|
||
code-quality: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 11 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '11' | ||
distribution: 'temurin' | ||
cache: maven | ||
|
||
- name: SpotBugs Analysis | ||
run: | | ||
cd v2/spanner-to-sourcedb | ||
mvn com.github.spotbugs:spotbugs-maven-plugin:check | ||
- name: PMD Analysis | ||
run: | | ||
cd v2/spanner-to-sourcedb | ||
mvn pmd:check | ||
- name: Checkstyle | ||
run: | | ||
cd v2/spanner-to-sourcedb | ||
mvn checkstyle:check |
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 @@ | ||
bucket = "reverse-replication-tf-state" |
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,11 @@ | ||
#Create State Bucket | ||
echo "----------------------------------" | ||
echo "Create Terraform State Bucket" | ||
echo "----------------------------------" | ||
cd terraform-state-bucket | ||
terraform init | ||
terraform plan | ||
terraform apply --auto-approve | ||
|
||
|
||
|
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,74 @@ | ||
global: | ||
region: "asia-south1" | ||
state_bucket: "reverse-replication-tf-state" | ||
project_id: "daring-fiber-439305-v4" | ||
|
||
dataflow-bucket: | ||
name: "reverse-replication-dataflow-templates" | ||
|
||
pubsub: | ||
topic: "spanner-reverse-replication" | ||
sub: "spanner-reverse-replication-sub" | ||
|
||
spanner: | ||
name: "spanner-reverse-replication" | ||
display_name: "Spanner Reverse Replication" | ||
num_nodes: 1 | ||
edition: "STANDARD" | ||
config: "regional-asia-south1" | ||
|
||
network: | ||
vpc_name: "reverse-replication" | ||
auto_create_subnetworks: false | ||
description: "Reverse Replication" | ||
subnet_name: "reverse-replication-asia-south1" | ||
subnet_ip: "10.0.0.0/16" | ||
subnet_description: "reverse replication asia south 1" | ||
|
||
cassandra: | ||
instance_name: "cassandra-1" | ||
zone: "asia-south1-a" | ||
instance: "linux" | ||
instance_type: "n2-standard-2" | ||
disk_size_gb: 100 | ||
disk_type: "pd-balanced" | ||
image: "ubuntu-os-cloud/ubuntu-2204-lts" | ||
create_internal_static_ip: true | ||
create_external_static_ip: true | ||
allow_stopping_for_update: true | ||
|
||
mysql: | ||
instance_name: "mysql-1" | ||
zone: "asia-south1-a" | ||
instance: "linux" | ||
instance_type: "n2-standard-2" | ||
disk_size_gb: 100 | ||
disk_type: "pd-balanced" | ||
image: "ubuntu-os-cloud/ubuntu-2204-lts" | ||
create_internal_static_ip: true | ||
create_external_static_ip: true | ||
allow_stopping_for_update: true | ||
|
||
firewall-cassandra: | ||
name: "allow-cassandra" | ||
description: "allow cassandra" | ||
protocol: "tcp" | ||
ports: ["7000", "7001", "9042", "7199"] | ||
source_ranges: ["10.0.0.0/16","52.220.17.199/32","13.234.0.44/32"] | ||
target_tags: ["cassandra-1"] | ||
|
||
firewall-mysql: | ||
name: "allow-mysql" | ||
description: "allow mysql" | ||
protocol: "tcp" | ||
ports: ["3306"] | ||
source_ranges: ["10.0.0.0/16", "52.220.17.199/32", "13.234.0.44/32"] | ||
target_tags: ["mysql-1"] | ||
|
||
firewall-ssh: | ||
name: "allow-ssh" | ||
description: "allow ssh" | ||
protocol: "tcp" | ||
ports: ["22"] | ||
source_ranges: ["0.0.0.0/0"] | ||
target_tags: ["cassandra-1", "mysql-1"] |
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,26 @@ | ||
resource "random_id" "suffix" { | ||
count = var.random_bucket_suffix ? 1 : 0 | ||
byte_length = 2 | ||
} | ||
|
||
resource "google_storage_bucket" "bucket" { | ||
name = var.random_bucket_suffix ? join("-", [var.bucket_name, lower(random_id.suffix[0].id)]) : var.bucket_name | ||
location = upper(var.bucket_location) | ||
force_destroy = var.force_destroy | ||
project = var.project_id | ||
storage_class = upper(var.storage_class) | ||
public_access_prevention = var.public_access_prevention | ||
labels = var.labels | ||
uniform_bucket_level_access = var.uniform_bucket_level_access | ||
|
||
versioning { | ||
enabled = var.version_enabled | ||
} | ||
|
||
dynamic "encryption" { | ||
for_each = var.encryption == null ? [] : [var.encryption] | ||
content { | ||
default_kms_key_name = encryption.value.default_kms_key_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,8 @@ | ||
output "bucket_url" { | ||
description = "Storage Bucket url" | ||
value = google_storage_bucket.bucket.url | ||
} | ||
output "bucket_name" { | ||
description = "Storage Bucket Name" | ||
value = google_storage_bucket.bucket.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,64 @@ | ||
variable "project_id" { | ||
description = "GCP Project ID" | ||
type = string | ||
} | ||
|
||
variable "bucket_name" { | ||
description = "The name of the bucket" | ||
type = string | ||
} | ||
|
||
variable "bucket_location" { | ||
description = "The Bucket Location" | ||
type = string | ||
} | ||
|
||
variable "force_destroy" { | ||
description = "Should Storage Bucket needs to be forcefully destroyed" | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "storage_class" { | ||
description = "The Storage Class of the new bucket. Supported values include: STANDARD, MULTI_REGIONAL, REGIONAL, NEARLINE, COLDLINE, ARCHIVE" | ||
type = string | ||
default = "STANDARD" | ||
} | ||
|
||
variable "labels" { | ||
description = "A map of key/value label pairs to assign to the bucket" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "version_enabled" { | ||
description = "The versioning state of the bucket" | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "encryption" { | ||
description = "A Cloud KMS key that will be used to encrypt objects inserted into this bucket" | ||
type = object({ | ||
default_kms_key_name = string // The id of a Cloud KMS key that will be used to encrypt objects inserted into this bucket | ||
}) | ||
default = null | ||
} | ||
|
||
variable "uniform_bucket_level_access" { | ||
description = "Enables Uniform bucket-level access access to a bucket" | ||
type = bool | ||
default = true | ||
} | ||
|
||
variable "public_access_prevention" { | ||
description = "Flag to enable or disable public access prevention" | ||
type = string | ||
default = "enforced" | ||
} | ||
|
||
variable "random_bucket_suffix" { | ||
description = "Flag to determine whether to include a random suffix in the bucket name" | ||
type = bool | ||
default = false | ||
} |
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,98 @@ | ||
resource "google_compute_instance" "vm_instance" { | ||
name = var.instance_name | ||
machine_type = var.instance_type | ||
zone = var.zone | ||
project = var.project | ||
hostname = var.instance != "windows" ? "" : "${var.instance_name}.${var.domain}" | ||
tags = var.tags | ||
labels = var.labels | ||
metadata_startup_script = var.startup_script | ||
allow_stopping_for_update = var.allow_stopping_for_update | ||
|
||
boot_disk { | ||
auto_delete = var.auto_delete | ||
initialize_params { | ||
size = var.disk_size_gb | ||
type = var.disk_type | ||
image = var.image != "" ? var.image : "windows-cloud/windows-2019" | ||
} | ||
disk_encryption_key_raw = var.disk_encryption_key != null ? base64encode(var.disk_encryption_key) : null | ||
} | ||
|
||
dynamic "attached_disk" { | ||
for_each = var.disks != "" ? var.disks : {} | ||
content { | ||
source = google_compute_disk.default[attached_disk.key].id | ||
device_name = attached_disk.value["device_name"] | ||
} | ||
} | ||
|
||
service_account { | ||
email = var.service_account == "" ? "" : var.service_account | ||
scopes = var.scopes | ||
} | ||
|
||
network_interface { | ||
network = "projects/${var.network_project_id}/global/networks/${var.network}" | ||
subnetwork = "projects/${var.network_project_id}/regions/${var.region}/subnetworks/${var.subnetwork}" | ||
network_ip = var.create_internal_static_ip ? google_compute_address.internal_static_ip[0].address : null | ||
|
||
dynamic "access_config" { | ||
for_each = var.create_external_static_ip ? [1] : [] | ||
content { | ||
nat_ip = google_compute_address.external_static_ip[0].address | ||
} | ||
} | ||
} | ||
|
||
metadata = { | ||
block-project-ssh-keys = "${var.block-project-ssh-keys}" | ||
serial-port-enable = "${var.serial-port-enable}" | ||
ssh-keys = var.ssh-keys == "" ? null : file(var.ssh-keys) | ||
enable-oslogin = var.enable_oslogin | ||
} | ||
|
||
scheduling { | ||
on_host_maintenance = var.on_host_maintenance | ||
preemptible = var.preemptible | ||
} | ||
|
||
deletion_protection = var.deletion_protection | ||
|
||
shielded_instance_config { | ||
enable_secure_boot = var.enable_secure_boot | ||
enable_vtpm = var.enable_vtpm | ||
enable_integrity_monitoring = var.enable_integrity_monitoring | ||
} | ||
depends_on = [google_compute_address.internal_static_ip] | ||
} | ||
|
||
resource "google_compute_disk" "default" { | ||
for_each = var.disks | ||
name = "${var.instance_name}-disk-${each.key}" | ||
type = each.value.type | ||
project = var.project | ||
disk_encryption_key { | ||
kms_key_self_link = var.disk_encryption_key | ||
} | ||
zone = var.zone | ||
size = each.value.size | ||
} | ||
|
||
# Conditional creation of internal static IP | ||
resource "google_compute_address" "internal_static_ip" { | ||
count = var.create_internal_static_ip ? 1 : 0 | ||
name = "${var.instance_name}-internal-ip" | ||
address_type = "INTERNAL" | ||
region = var.region | ||
subnetwork = "projects/${var.network_project_id}/regions/${var.region}/subnetworks/${var.subnetwork}" | ||
project = var.project | ||
} | ||
|
||
# Conditional creation of external static IP | ||
resource "google_compute_address" "external_static_ip" { | ||
count = var.create_external_static_ip ? 1 : 0 | ||
name = "${var.instance_name}-external-ip" | ||
region = var.region | ||
project = var.project | ||
} |
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,15 @@ | ||
############################# | ||
## GCP VM - Output ## | ||
############################# | ||
|
||
output "vm-name" { | ||
value = google_compute_instance.vm_instance.name | ||
} | ||
|
||
output "vm-internal-ip" { | ||
value = var.create_internal_static_ip ? google_compute_instance.vm_instance.network_interface.0.network_ip : null | ||
} | ||
|
||
output "vm-external-ip" { | ||
value = var.create_external_static_ip ? google_compute_address.external_static_ip[0].address : null | ||
} |
Oops, something went wrong.