Skip to content

Commit 9b91a2c

Browse files
committed
Add table gcp_compute_machine_image Closes #517
1 parent b53b301 commit 9b91a2c

14 files changed

+431
-0
lines changed
+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Table: gcp_compute_machine_image
2+
3+
A machine image is a Compute Engine resource that stores all the configuration, metadata, permissions, and data from multiple disks of a virtual machine (VM) instance. You can use a machine image in many system maintenance, backup and recovery, and instance cloning scenarios.
4+
5+
## Examples
6+
7+
### Basic info
8+
9+
```sql
10+
select
11+
name,
12+
id,
13+
description,
14+
creation_timestamp,
15+
guest_flush,
16+
source_instance
17+
from
18+
gcp_compute_machine_image;
19+
```
20+
21+
### List machine images that are available
22+
23+
```sql
24+
select
25+
name,
26+
id,
27+
description,
28+
creation_timestamp,
29+
status
30+
from
31+
gcp_compute_machine_image
32+
where
33+
status = 'READY';
34+
```
35+
36+
### List the top 5 machine images that consume highest storage
37+
38+
```sql
39+
select
40+
name,
41+
id,
42+
self_link,
43+
status,
44+
total_storage_bytes
45+
from
46+
gcp_compute_machine_image
47+
order by
48+
total_storage_bytes asc;
49+
```
50+
51+
### Get instance properties of the machine images
52+
53+
```sql
54+
select
55+
name,
56+
id,
57+
instance_properties -> 'AdvancedMachineFeatures' as advanced_machine_features,
58+
instance_properties ->> 'CanIpForward' as can_ip_forward,
59+
instance_properties -> 'ConfidentialInstanceConfig' as confidential_instance_config,
60+
instance_properties ->> 'Description' as description,
61+
instance_properties -> 'Disks' as disks,
62+
instance_properties -> 'GuestAccelerators' as guest_accelerators,
63+
instance_properties ->> 'KeyRevocationActionType' as key_revocation_action_type,
64+
instance_properties -> 'Labels' as labels,
65+
instance_properties ->> 'MachineType' as machine_type,
66+
instance_properties -> 'Metadata' as metadata,
67+
instance_properties -> 'MinCpuPlatform' as min_cpu_platform,
68+
instance_properties -> 'NetworkInterfaces' as network_interfaces,
69+
instance_properties -> 'NetworkPerformanceConfig' as network_performance_config,
70+
instance_properties -> 'PrivateIpv6GoogleAccess' as private_ipv6_google_access,
71+
instance_properties ->> 'ReservationAffinity' as reservation_affinity,
72+
instance_properties -> 'ResourceManagerTags' as resource_manager_tags,
73+
instance_properties -> 'ResourcePolicies' as resource_policies,
74+
instance_properties -> 'Scheduling' as scheduling,
75+
instance_properties -> 'ServiceAccounts' as service_accounts,
76+
instance_properties -> 'ShieldedInstanceConfig' as shielded_instance_config,
77+
instance_properties -> 'Tags' as tags
78+
from
79+
gcp_compute_machine_image;
80+
```
81+
82+
### Get encryption details of the machine image
83+
84+
```sql
85+
select
86+
name,
87+
machine_image_encryption_key ->> 'KmsKeyName' as kms_key_name,
88+
machine_image_encryption_key ->> 'KmsKeyServiceAccount' as kms_key_service_account,
89+
machine_image_encryption_key ->> 'RawKey' as raw_key,
90+
machine_image_encryption_key ->> 'RsaEncryptedKey' as rsa_encrypted_key,
91+
machine_image_encryption_key ->> 'Sha256' as sha256,
92+
from
93+
gcp_compute_machine_image;
94+
```

gcp-test/tests/gcp_compute_machine_image/dependencies.txt

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"kind": "compute#machineImage",
4+
"name": "{{ resourceName }}",
5+
"self_link": "{{ output.self_link.value }}",
6+
"title": "{{ resourceName }}"
7+
}
8+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
select name, title, kind, self_link
2+
from gcp.gcp_compute_machine_image
3+
where name = '{{ resourceName }}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
{
3+
"akas": ["{{ output.resource_aka.value }}"],
4+
"name": "{{ resourceName }}",
5+
"title": "{{ resourceName }}"
6+
}
7+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
select name, title, akas
2+
from gcp.gcp_compute_machine_image
3+
where akas::text = '["{{ output.resource_aka.value }}"]';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
null
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
select name, id
2+
from gcp.gcp_compute_machine_image
3+
where name = 'dummy{{ resourceName }}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[
2+
{
3+
"akas": ["{{ output.resource_aka.value }}"],
4+
"title": "{{ resourceName }}"
5+
}
6+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
select title, akas
2+
from gcp.gcp_compute_machine_image
3+
where name = '{{ resourceName }}';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
variable "resource_name" {
3+
type = string
4+
default = "turbot-test-20200125-create-update"
5+
description = "Name of the resource used throughout the test."
6+
}
7+
8+
variable "gcp_project" {
9+
type = string
10+
default = "parker-aaa"
11+
description = "GCP project used for the test."
12+
}
13+
14+
variable "gcp_region" {
15+
type = string
16+
default = "us-east1"
17+
description = "GCP region used for the test."
18+
}
19+
20+
variable "gcp_zone" {
21+
type = string
22+
default = "us-east1-b"
23+
}
24+
25+
provider "google" {
26+
project = var.gcp_project
27+
region = var.gcp_region
28+
zone = var.gcp_zone
29+
}
30+
31+
data "google_client_config" "current" {}
32+
33+
data "null_data_source" "resource" {
34+
inputs = {
35+
scope = "gcp://cloudresourcemanager.googleapis.com/projects/${data.google_client_config.current.project}"
36+
}
37+
}
38+
39+
resource "google_compute_instance" "names_test_resource" {
40+
provider = google-beta
41+
name = var.resource_name
42+
machine_type = "f1-micro"
43+
zone = "us-east1-b"
44+
project = var.gcp_project
45+
46+
boot_disk {
47+
initialize_params {
48+
image = "debian-cloud/debian-11"
49+
}
50+
}
51+
52+
network_interface {
53+
network = "default"
54+
}
55+
}
56+
57+
resource "google_compute_machine_image" "names_test_resource" {
58+
provider = google-beta
59+
project = var.gcp_project
60+
name = var.resource_name
61+
source_instance = google_compute_instance.names_test_resource.self_link
62+
}
63+
64+
output "machine_type" {
65+
value = "f1-micro"
66+
}
67+
68+
output "resource_name" {
69+
value = var.resource_name
70+
}
71+
72+
output "self_link" {
73+
value = google_compute_machine_image.names_test_resource.self_link
74+
}
75+
76+
output "resource_aka" {
77+
value = "gcp://compute.googleapis.com/projects/${var.gcp_project}/machineImages/${var.resource_name}"
78+
}

gcp/plugin.go

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
6868
"gcp_compute_instance_metric_cpu_utilization_daily": tableGcpComputeInstanceMetricCpuUtilizationDaily(ctx),
6969
"gcp_compute_instance_metric_cpu_utilization_hourly": tableGcpComputeInstanceMetricCpuUtilizationHourly(ctx),
7070
"gcp_compute_instance_template": tableGcpComputeInstanceTemplate(ctx),
71+
"gcp_compute_machine_image": tableGcpComputeMachineImage(ctx),
7172
"gcp_compute_machine_type": tableGcpComputeMachineType(ctx),
7273
"gcp_compute_network": tableGcpComputeNetwork(ctx),
7374
"gcp_compute_node_group": tableGcpComputeNodeGroup(ctx),

0 commit comments

Comments
 (0)