Skip to content

Commit

Permalink
update attributes & add terraform scripts
Browse files Browse the repository at this point in the history
Signed-off-by: balasubramanian-s <[email protected]>
  • Loading branch information
balasubramanian-s committed Feb 1, 2024
1 parent f10dfb6 commit 43aeb7e
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 63 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ The following resources are available in the InSpec GCP Profile
| [google_compute_interconnect](docs/resources/google_compute_interconnect.md) | [google_compute_interconnects](docs/resources/google_compute_interconnects.md) |
| [google_compute_interconnect_location](docs/resources/google_compute_interconnect_location.md) | [google_compute_interconnect_locations](docs/resources/google_compute_interconnect_locations.md) |
| [google_compute_license_code](docs/resources/google_compute_license_code.md) | No Plural Resource |
| [google_compute_machine_image](docs/resources/google_compute_machine_image.md) | [google_compute_machine_images](docs/resources/google_compute_machine_images.md) |
| [google_compute_network](docs/resources/google_compute_network.md) | [google_compute_networks](docs/resources/google_compute_networks.md) |
| [google_compute_network_endpoint_group](docs/resources/google_compute_network_endpoint_group.md) | [google_compute_network_endpoint_groups](docs/resources/google_compute_network_endpoint_groups.md) |
| [google_compute_node_group](docs/resources/google_compute_node_group.md) | [google_compute_node_groups](docs/resources/google_compute_node_groups.md) |
Expand Down
94 changes: 47 additions & 47 deletions docs/resources/google_compute_machine_image.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/resources/google_compute_machine_images.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A `google_compute_machine_images` is used to test a Google MachineImage resource

## Examples
```
describe google_compute_v1_machine_images(project: 'chef-gcp-inspec') do
describe google_compute_machine_images(project: 'chef-gcp-inspec') do
it { should exist }
end
```
Expand Down
2 changes: 1 addition & 1 deletion libraries/google_compute_machine_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@ def product_url(_ = nil)
end

def resource_base_url
'projects/{{project}}/global/machineImages/{{machine_image}}'
'projects/{{project}}/global/machineImages/{{name}}'
end
end
2 changes: 1 addition & 1 deletion libraries/google_compute_machine_images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class ComputeMachineImages < GcpResourceBase
def initialize(params = {})
super(params.merge({ use_http_transport: true }))
@params = params
@table = fetch_wrapped_resource('machineImages')
@table = fetch_wrapped_resource('items')
end

def fetch_wrapped_resource(wrap_path)
Expand Down
23 changes: 23 additions & 0 deletions test/integration/build/gcp-mm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ variable "region_network_endpoint_group" {
variable "secrets_manager_v1" {
type = any
}
variable "compute_machine_images" {
type = any
}

resource "google_compute_ssl_policy" "custom-ssl-policy" {
name = var.ssl_policy["name"]
Expand Down Expand Up @@ -1731,3 +1734,23 @@ resource "google_kms_crypto_key" "cryptokey" {
resource "google_kms_crypto_key_version" "example-key" {
crypto_key = google_kms_crypto_key.cryptokey.id
}

resource "google_compute_instance" "inspec" {
name = var.compute_machine_images.instance
machine_type = "e2-medium"

boot_disk {
initialize_params {
image = "debian-cloud/debian-11"
}
}

network_interface {
network = "default"
}
}

resource "google_compute_machine_image" "image" {
name = var.compute_machine_images.name
source_instance = google_compute_instance.inspec.self_link
}
4 changes: 4 additions & 0 deletions test/integration/configuration/mm-attributes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -640,3 +640,7 @@ crypto_key_version:
key_ring: "gcp-inspec-kms-key-ring"
crypto_key: "gcp-inspec-kms-crypto-key-policy"
region: "us-central-1"

compute_machine_images:
name: "image-1"
instance: "inspec-test-instance"
13 changes: 6 additions & 7 deletions test/integration/verify/controls/google_compute_machine_image.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.')

machine_image = input('machine_image', value: {
"machine_image": "value_machineimage",
"project": "value_project",
"kind": "value_kind",
"id": "value_id",
"project": "ppradhan",
"kind": "compute#machineImage",
"id": "7552526330490377685",
"creation_timestamp": "value_creationtimestamp",
"name": "value_name",
"name": "image-1",
"description": "value_description",
"self_link": "value_selflink",
"source_instance": "value_sourceinstance",
Expand All @@ -33,7 +32,7 @@
impact 1.0
title 'google_compute_machine_image resource test'

describe google_compute_v1_machine_image(machineImage: machine_image['machineImage'], project: gcp_project_id) do
describe google_compute_machine_image(name: machine_image['name'], project: gcp_project_id) do
it { should exist }
its('kind') { should cmp machine_image['kind'] }
its('id') { should cmp machine_image['id'] }
Expand All @@ -47,7 +46,7 @@

end

describe google_compute_v1_machine_image(machineImage: machine_image['machineImage'], project: gcp_project_id) do
describe google_compute_machine_image(name: machine_image['name'], project: gcp_project_id) do
it { should_not exist }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
gcp_project_id = input(:gcp_project_id, value: 'gcp_project_id', description: 'The GCP project identifier.')

machine_image = input('machine_image', value: {
"machine_image": "value_machineimage",
"project": "value_project",
"kind": "value_kind",
"id": "value_id",
"project": "ppradhan",
"kind": "compute#machineImage",
"id": "7552526330490377685",
"creation_timestamp": "value_creationtimestamp",
"name": "value_name",
"name": "image-1",
"description": "value_description",
"self_link": "value_selflink",
"source_instance": "value_sourceinstance",
Expand All @@ -33,7 +32,7 @@
impact 1.0
title 'google_compute_machine_images resource test'

describe google_compute_v1_machine_images(project: gcp_project_id) do
describe google_compute_machine_images(project: gcp_project_id) do
it { should exist }
end
end

0 comments on commit 43aeb7e

Please sign in to comment.