Skip to content

Commit

Permalink
Merge pull request #274 from perfectsense/feature/cloudsql
Browse files Browse the repository at this point in the history
Implement cloudsql
  • Loading branch information
harjain99 authored Oct 9, 2024
2 parents a5e6d9a + b8b3283 commit 0f2b16d
Show file tree
Hide file tree
Showing 34 changed files with 4,915 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ dependencies {
// XXX: com.google.apis:google-api-services-iam:v1-rev316-1.25.0 uses older version of com.google.api-client:google-api-client
implementation 'com.google.api-client:google-api-client:1.31.5'
implementation 'com.google.apis:google-api-services-iam:v1-rev316-1.25.0'
implementation 'com.google.apis:google-api-services-sqladmin:v1-rev20240814-2.0.0'
implementation 'com.google.cloud:google-cloud-compute'
implementation 'com.google.cloud:google-cloud-dns'
implementation 'com.google.cloud:google-cloud-kms'
Expand Down
94 changes: 94 additions & 0 deletions examples/cloudsql/database-instance.gyro
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
google::database-instance database-instance-example
name: "gyro-db-test"

settings
activation-policy: "ALWAYS"
availability-type: "REGIONAL"
connector-enforcement: "NOT_REQUIRED"
data-disk-size-gb: 20
data-disk-type: 'PD_SSD'
deletion-protection-enabled: false
pricing-plan: "PER_USE"
storage-auto-resize: true
storage-auto-resize-limit: 100
tier: "db-perf-optimized-N-2"
edition: "ENTERPRISE_PLUS"

data-cache-config
data-cache-enabled: true
end

backup-configuration
enabled: true
start-time: "09:00"
transaction-log-retention-days: 14
binary-log-enabled: true

backup-retention-settings
retention-unit: "COUNT"
retained-backups: 15
end
end

user-labels: {
"example": "example"
}

ip-configuration
ipv4-enabled: true
server-ca-mode: 'GOOGLE_MANAGED_INTERNAL_CA'
ssl-mode: 'ALLOW_UNENCRYPTED_AND_ENCRYPTED'
private-network: $(external-query google::compute-network { name: "test-db" })

authorized-networks
name: "example-QA-enviroment"
value: "3.131.207.174/32"
end
end

location-preference
zone: 'us-central1-c'
secondary-zone: 'us-central1-b'
end

password-validation-policy
complexity: "COMPLEXITY_DEFAULT"
disallow-username-substring: true
enable-password-policy: true
min-length: 8
reuse-interval: 1
end
end

database-version: "MYSQL_8_0_31"
gce-zone: "us-central1-c"
secondary-gce-zone: "us-central1-b"
instance-type: "CLOUD_SQL_INSTANCE"
region: "us-central1"
backend-type: "SECOND_GEN"

scheduled-maintenance
can-reschedule: true
schedule-deadline-time: "2024-08-30T23:59:59.00Z"
start-time: "2024-12-31T23:59:59.00Z"
end
end

google::database-instance database-instance-example-replica
name: "gyro-db-test-replica"
master-instance: $(google::database-instance database-instance-example)

settings
edition: "ENTERPRISE_PLUS"
tier: "db-perf-optimized-N-2"

ip-configuration
ipv4-enabled: true
end

location-preference
zone: 'us-central1-c'
secondary-zone: 'us-central1-b'
end
end
end
60 changes: 60 additions & 0 deletions src/main/java/gyro/google/cloudsql/DatabaseInstanceFinder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright 2024, Brightspot.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package gyro.google.cloudsql;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import com.google.api.services.sqladmin.SQLAdmin;
import com.google.api.services.sqladmin.model.DatabaseInstance;
import gyro.core.Type;
import gyro.google.GoogleFinder;

/**
* Query a database instance.
*
* .. code-block:: gyro
*
* database-instance: $(external-query google::database-instance {name: 'database-instance-name'})
*/
@Type("database-instance")
public class DatabaseInstanceFinder extends GoogleFinder<SQLAdmin, DatabaseInstance, DatabaseInstanceResource> {

private String name;

/**
* The name of the Database Instance.
*/
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
protected List<DatabaseInstance> findAllGoogle(SQLAdmin client) throws Exception {
return client.instances().list(getProjectId()).execute().getItems();
}

@Override
protected List<DatabaseInstance> findGoogle(SQLAdmin client, Map<String, String> filters) throws Exception {
return Collections.singletonList(client.instances().get(getProjectId(), filters.get("name")).execute());
}
}
Loading

0 comments on commit 0f2b16d

Please sign in to comment.