-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add gcp_compute_instance_template template table. Closes #84 * Add tests to verify the table * Add docs Co-authored-by: Subhajit Kumar Mondal <subhajit@turbot.com> Co-authored-by: rajeshbal65 <rajesh.bal@turbot.com>
- Loading branch information
1 parent
864dfda
commit 44efc87
Showing
20 changed files
with
591 additions
and
1 deletion.
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,83 @@ | ||
# Table: gcp_compute_instance_template | ||
|
||
An instance template is a resource that use to create virtual machine (VM) instances and managed instance groups (MIGs). Instance templates define the machine type, boot disk image or container image, labels, and other instance properties. | ||
|
||
## Examples | ||
|
||
### List of c2-standard-4 machine type instance template | ||
|
||
```sql | ||
select | ||
name, | ||
id, | ||
instance_machine_type | ||
from | ||
gcp_compute_instance_template | ||
where | ||
instance_machine_type = 'c2-standard-4'; | ||
``` | ||
|
||
|
||
### Boot Disk info of each instance template | ||
```sql | ||
select | ||
name, | ||
id, | ||
disk ->> 'deviceName' as disk_device_name, | ||
disk -> 'initializeParams' ->> 'diskType' as disk_type, | ||
disk -> 'initializeParams' ->> 'diskSizeGb' as disk_size_gb, | ||
split_part( | ||
disk -> 'initializeParams' ->> 'sourceImage', | ||
'/', | ||
5 | ||
) as source_image, | ||
disk ->> 'mode' as mode | ||
from | ||
gcp_compute_instance_template, | ||
jsonb_array_elements(instance_disks) as disk; | ||
``` | ||
|
||
|
||
### List of SPECIFIC_RESERVATION Instance type instance template | ||
```sql | ||
select | ||
name, | ||
id, | ||
instance_reservation_affinity ->> 'consumeReservationType' as consume_reservation_type | ||
from | ||
gcp_compute_instance_template | ||
where | ||
instance_reservation_affinity ->> 'consumeReservationType' = 'SPECIFIC_RESERVATION'; | ||
``` | ||
|
||
|
||
### Network interface info of each instance template | ||
|
||
```sql | ||
select | ||
name, | ||
id, | ||
i ->> 'name' as name, | ||
split_part(i ->> 'network', '/', 10) as network_name, | ||
p ->> 'name' as access_config_name, | ||
p ->> 'networkTier' as access_config_network_tier, | ||
p ->> 'type' as access_config_type | ||
from | ||
gcp_compute_instance_template, | ||
jsonb_array_elements(instance_network_interfaces) as i, | ||
jsonb_array_elements(i -> 'accessConfigs') as p; | ||
``` | ||
|
||
|
||
### List of instance templates where instance_can_ip_forward is true | ||
|
||
```sql | ||
select | ||
name, | ||
id, | ||
instance_can_ip_forward | ||
from | ||
gcp_compute_instance_template | ||
where | ||
instance_can_ip_forward; | ||
``` |
Empty file.
58 changes: 58 additions & 0 deletions
58
gcp-test/tests/gcp_compute_instance_template/test-get-expected.json
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,58 @@ | ||
[ | ||
{ | ||
"description": "Test instance template to verify the table.", | ||
"instance_can_ip_forward": false, | ||
"instance_description": "A dummy description", | ||
"instance_disks": [ | ||
{ | ||
"autoDelete": true, | ||
"boot": true, | ||
"deviceName": "persistent-disk-0", | ||
"initializeParams": { | ||
"diskType": "pd-standard", | ||
"sourceImage": "projects/debian-cloud/global/images/family/debian-9" | ||
}, | ||
"interface": "SCSI", | ||
"kind": "compute#attachedDisk", | ||
"mode": "READ_WRITE", | ||
"type": "PERSISTENT" | ||
} | ||
], | ||
"instance_machine_type": "f1-micro", | ||
"instance_metadata": { | ||
"fingerprint": "{{ output.metadata_fingerprint.value }}", | ||
"items": [ | ||
{ | ||
"key": "foo", | ||
"value": "bar" | ||
} | ||
], | ||
"kind": "compute#metadata" | ||
}, | ||
"instance_network_interfaces": [ | ||
{ | ||
"kind": "compute#networkInterface", | ||
"name": "nic0", | ||
"network": "{{ output.network.value }}" | ||
} | ||
], | ||
"instance_scheduling": { | ||
"automaticRestart": true, | ||
"onHostMaintenance": "MIGRATE" | ||
}, | ||
"instance_service_accounts": [ | ||
{ | ||
"email": "{{ output.service_account.value }}", | ||
"scopes": ["https://www.googleapis.com/auth/cloud-platform"] | ||
} | ||
], | ||
"instance_tags": { | ||
"items": ["bar", "foo"] | ||
}, | ||
"kind": "compute#instanceTemplate", | ||
"location": "global", | ||
"name": "{{ resourceName }}", | ||
"project": "{{ output.project_id.value }}", | ||
"self_link": "https://www.googleapis.com/compute/v1/projects/{{ output.project_id.value }}/global/instanceTemplates/{{ resourceName }}" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_compute_instance_template/test-get-query.sql
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,3 @@ | ||
select name, description, instance_can_ip_forward, instance_description, instance_disks, instance_machine_type, instance_metadata, instance_network_interfaces, instance_scheduling, instance_service_accounts, instance_tags, kind, location, project, self_link | ||
from gcp.gcp_compute_instance_template | ||
where name = '{{ resourceName }}' |
10 changes: 10 additions & 0 deletions
10
gcp-test/tests/gcp_compute_instance_template/test-hydrate-expected.json
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,10 @@ | ||
[ | ||
{ | ||
"description": "Test instance template to verify the table.", | ||
"instance_description": "A dummy description", | ||
"instance_machine_type": "f1-micro", | ||
"kind": "compute#instanceTemplate", | ||
"name": "{{ resourceName }}", | ||
"self_link": "https://www.googleapis.com/compute/v1/projects/{{ output.project_id.value }}/global/instanceTemplates/{{ resourceName }}" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_compute_instance_template/test-hydrate-query.sql
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,3 @@ | ||
select name, instance_description, description, kind, instance_machine_type, self_link | ||
from gcp.gcp_compute_instance_template | ||
where name = '{{ resourceName }}' |
1 change: 1 addition & 0 deletions
1
gcp-test/tests/gcp_compute_instance_template/test-invalid-name-expected.json
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 @@ | ||
null |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_compute_instance_template/test-invalid-name-query.sql
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,3 @@ | ||
select name, id, description | ||
from gcp.gcp_compute_instance_template | ||
where name = '' |
6 changes: 6 additions & 0 deletions
6
gcp-test/tests/gcp_compute_instance_template/test-list-expected.json
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,6 @@ | ||
[ | ||
{ | ||
"description": "Test instance template to verify the table.", | ||
"name": "{{ resourceName }}" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_compute_instance_template/test-list-query.sql
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,3 @@ | ||
select name, description | ||
from gcp.gcp_compute_instance_template | ||
where title = '{{ resourceName }}' |
1 change: 1 addition & 0 deletions
1
gcp-test/tests/gcp_compute_instance_template/test-not-found-expected.json
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 @@ | ||
null |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_compute_instance_template/test-not-found-query.sql
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,3 @@ | ||
select name, id, description | ||
from gcp.gcp_compute_instance_template | ||
where name = 'dummy-{{ resourceName }}' |
9 changes: 9 additions & 0 deletions
9
gcp-test/tests/gcp_compute_instance_template/test-turbot-expected.json
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,9 @@ | ||
[ | ||
{ | ||
"akas": ["{{ output.resource_aka.value }}"], | ||
"tags": { | ||
"name": "{{ resourceName }}" | ||
}, | ||
"title": "{{ resourceName }}" | ||
} | ||
] |
3 changes: 3 additions & 0 deletions
3
gcp-test/tests/gcp_compute_instance_template/test-turbot-query.sql
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,3 @@ | ||
select tags, title, akas | ||
from gcp.gcp_compute_instance_template | ||
where name = '{{ resourceName }}' |
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 @@ | ||
{} |
124 changes: 124 additions & 0 deletions
124
gcp-test/tests/gcp_compute_instance_template/variables.tf
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,124 @@ | ||
|
||
variable "resource_name" { | ||
type = string | ||
default = "turbot-test-20200125-create-update" | ||
description = "Name of the resource used throughout the test." | ||
} | ||
|
||
variable "gcp_project" { | ||
type = string | ||
default = "niteowl-aaa" | ||
description = "GCP project used for the test." | ||
} | ||
|
||
variable "gcp_region" { | ||
type = string | ||
default = "us-east1" | ||
description = "GCP region used for the test." | ||
} | ||
|
||
variable "gcp_zone" { | ||
type = string | ||
default = "us-east1-b" | ||
} | ||
|
||
provider "google" { | ||
project = var.gcp_project | ||
region = var.gcp_region | ||
zone = var.gcp_zone | ||
} | ||
|
||
data "google_client_config" "current" {} | ||
|
||
data "null_data_source" "resource" { | ||
inputs = { | ||
scope = "gcp://cloudresourcemanager.googleapis.com/projects/${data.google_client_config.current.project}" | ||
} | ||
} | ||
|
||
resource "google_compute_network" "named_test_resource" { | ||
name = var.resource_name | ||
} | ||
|
||
resource "google_service_account" "named_test_resource" { | ||
account_id = var.resource_name | ||
display_name = var.resource_name | ||
} | ||
|
||
resource "google_compute_instance_template" "named_test_resource" { | ||
name = var.resource_name | ||
description = "Test instance template to verify the table." | ||
|
||
tags = ["foo", "bar"] | ||
|
||
labels = { | ||
name = var.resource_name | ||
} | ||
|
||
instance_description = "A dummy description" | ||
machine_type = "f1-micro" | ||
can_ip_forward = false | ||
|
||
scheduling { | ||
automatic_restart = true | ||
on_host_maintenance = "MIGRATE" | ||
} | ||
|
||
// Create a new boot disk from an image | ||
disk { | ||
source_image = "debian-cloud/debian-9" | ||
auto_delete = true | ||
boot = true | ||
} | ||
|
||
network_interface { | ||
network = google_compute_network.named_test_resource.name | ||
} | ||
|
||
metadata = { | ||
foo = "bar" | ||
} | ||
|
||
service_account { | ||
# Google recommends custom service accounts that have cloud-platform scope and permissions granted via IAM Roles. | ||
email = google_service_account.named_test_resource.email | ||
scopes = ["cloud-platform"] | ||
} | ||
} | ||
|
||
data "google_compute_image" "my_image" { | ||
family = "debian-9" | ||
project = "debian-cloud" | ||
} | ||
|
||
output "resource_aka" { | ||
value = "gcp://compute.googleapis.com/${google_compute_instance_template.named_test_resource.id}" | ||
} | ||
|
||
output "resource_name" { | ||
value = var.resource_name | ||
} | ||
|
||
output "resource_id" { | ||
value = google_compute_instance_template.named_test_resource.id | ||
} | ||
|
||
output "self_link" { | ||
value = google_compute_instance_template.named_test_resource.self_link | ||
} | ||
|
||
output "network" { | ||
value = google_compute_network.named_test_resource.self_link | ||
} | ||
|
||
output "service_account" { | ||
value = google_service_account.named_test_resource.email | ||
} | ||
|
||
output "metadata_fingerprint" { | ||
value = google_compute_instance_template.named_test_resource.metadata_fingerprint | ||
} | ||
|
||
output "project_id" { | ||
value = var.gcp_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
Oops, something went wrong.