Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for regional Google compute disk #164

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 43 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,49 +171,49 @@ The following resources are available in the InSpec GCP Profile
| [google_compute_network](docs/resources/google_compute_network.md) | [google_compute_networks](docs/resources/google_compute_networks.md) |
| [google_compute_project_info](docs/resources/google_compute_project_info.md) | [google_compute_region](docs/resources/google_compute_region.md) |
| [google_compute_region_instance_group_manager](docs/resources/google_compute_region_instance_group_manager.md) | [google_compute_region_instance_group_managers](docs/resources/google_compute_region_instance_group_managers.md) |
| [google_compute_regions](docs/resources/google_compute_regions.md) | [google_compute_route](docs/resources/google_compute_route.md) |
| [google_compute_router](docs/resources/google_compute_router.md) | [google_compute_routers](docs/resources/google_compute_routers.md) |
| [google_compute_routes](docs/resources/google_compute_routes.md) | [google_compute_snapshot](docs/resources/google_compute_snapshot.md) |
| [google_compute_snapshots](docs/resources/google_compute_snapshots.md) | [google_compute_ssl_certificate](docs/resources/google_compute_ssl_certificate.md) |
| [google_compute_ssl_certificates](docs/resources/google_compute_ssl_certificates.md) | [google_compute_ssl_policies](docs/resources/google_compute_ssl_policies.md) |
| [google_compute_ssl_policy](docs/resources/google_compute_ssl_policy.md) | [google_compute_subnetwork](docs/resources/google_compute_subnetwork.md) |
| [google_compute_subnetworks](docs/resources/google_compute_subnetworks.md) | [google_compute_target_http_proxies](docs/resources/google_compute_target_http_proxies.md) |
| [google_compute_target_http_proxy](docs/resources/google_compute_target_http_proxy.md) | [google_compute_target_https_proxies](docs/resources/google_compute_target_https_proxies.md) |
| [google_compute_target_https_proxy](docs/resources/google_compute_target_https_proxy.md) | [google_compute_target_pool](docs/resources/google_compute_target_pool.md) |
| [google_compute_target_pools](docs/resources/google_compute_target_pools.md) | [google_compute_target_tcp_proxies](docs/resources/google_compute_target_tcp_proxies.md) |
| [google_compute_target_tcp_proxy](docs/resources/google_compute_target_tcp_proxy.md) | [google_compute_url_map](docs/resources/google_compute_url_map.md) |
| [google_compute_url_maps](docs/resources/google_compute_url_maps.md) | [google_compute_vpn_tunnel](docs/resources/google_compute_vpn_tunnel.md) |
| [google_compute_vpn_tunnels](docs/resources/google_compute_vpn_tunnels.md) | [google_compute_zone](docs/resources/google_compute_zone.md) |
| [google_compute_zones](docs/resources/google_compute_zones.md) | [google_container_cluster](docs/resources/google_container_cluster.md) |
| [google_container_clusters](docs/resources/google_container_clusters.md) | [google_container_node_pool](docs/resources/google_container_node_pool.md) |
| [google_container_node_pools](docs/resources/google_container_node_pools.md) | [google_container_regional_cluster](docs/resources/google_container_regional_cluster.md) |
| [google_container_regional_clusters](docs/resources/google_container_regional_clusters.md) | [google_dns_managed_zone](docs/resources/google_dns_managed_zone.md) |
| [google_dns_managed_zones](docs/resources/google_dns_managed_zones.md) | [google_dns_resource_record_set](docs/resources/google_dns_resource_record_set.md) |
| [google_dns_resource_record_sets](docs/resources/google_dns_resource_record_sets.md) | [google_kms_crypto_key](docs/resources/google_kms_crypto_key.md) |
| [google_kms_crypto_key_iam_binding](docs/resources/google_kms_crypto_key_iam_binding.md) | [google_kms_crypto_key_iam_bindings](docs/resources/google_kms_crypto_key_iam_bindings.md) |
| [google_kms_crypto_keys](docs/resources/google_kms_crypto_keys.md) | [google_kms_key_ring](docs/resources/google_kms_key_ring.md) |
| [google_kms_key_ring_iam_binding](docs/resources/google_kms_key_ring_iam_binding.md) | [google_kms_key_ring_iam_bindings](docs/resources/google_kms_key_ring_iam_bindings.md) |
| [google_kms_key_rings](docs/resources/google_kms_key_rings.md) | [google_logging_project_exclusion](docs/resources/google_logging_project_exclusion.md) |
| [google_logging_project_sink](docs/resources/google_logging_project_sink.md) | [google_logging_project_sinks](docs/resources/google_logging_project_sinks.md) |
| [google_organization](docs/resources/google_organization.md) | [google_organizations](docs/resources/google_organizations.md) |
| [google_project](docs/resources/google_project.md) | [google_project_alert_policies](docs/resources/google_project_alert_policies.md) |
| [google_project_alert_policy](docs/resources/google_project_alert_policy.md) | [google_project_alert_policy_condition](docs/resources/google_project_alert_policy_condition.md) |
| [google_project_iam_binding](docs/resources/google_project_iam_binding.md) | [google_project_iam_bindings](docs/resources/google_project_iam_bindings.md) |
| [google_project_iam_custom_role](docs/resources/google_project_iam_custom_role.md) | [google_project_logging_audit_config](docs/resources/google_project_logging_audit_config.md) |
| [google_project_metric](docs/resources/google_project_metric.md) | [google_project_metrics](docs/resources/google_project_metrics.md) |
| [google_projects](docs/resources/google_projects.md) | [google_pubsub_subscription](docs/resources/google_pubsub_subscription.md) |
| [google_pubsub_subscriptions](docs/resources/google_pubsub_subscriptions.md) | [google_pubsub_topic](docs/resources/google_pubsub_topic.md) |
| [google_pubsub_topics](docs/resources/google_pubsub_topics.md) | [google_service_account](docs/resources/google_service_account.md) |
| [google_service_account_key](docs/resources/google_service_account_key.md) | [google_service_account_keys](docs/resources/google_service_account_keys.md) |
| [google_service_accounts](docs/resources/google_service_accounts.md) | [google_sourcerepo_repositories](docs/resources/google_sourcerepo_repositories.md) |
| [google_sourcerepo_repository](docs/resources/google_sourcerepo_repository.md) | [google_sql_database_instance](docs/resources/google_sql_database_instance.md) |
| [google_sql_database_instances](docs/resources/google_sql_database_instances.md) | [google_sql_users](docs/resources/google_sql_users.md) |
| [google_storage_bucket](docs/resources/google_storage_bucket.md) | [google_storage_bucket_acl](docs/resources/google_storage_bucket_acl.md) |
| [google_storage_bucket_iam_binding](docs/resources/google_storage_bucket_iam_binding.md) | [google_storage_bucket_iam_bindings](docs/resources/google_storage_bucket_iam_bindings.md) |
| [google_storage_bucket_object](docs/resources/google_storage_bucket_object.md) | [google_storage_bucket_objects](docs/resources/google_storage_bucket_objects.md) |
| [google_storage_buckets](docs/resources/google_storage_buckets.md) | [google_storage_default_object_acl](docs/resources/google_storage_default_object_acl.md) |
| [google_storage_object_acl](docs/resources/google_storage_object_acl.md) | [google_user](docs/resources/google_user.md) |
| [google_users](docs/resources/google_users.md) | |
| [google_compute_regional_disk](docs/resources/google_compute_regional_disk.md) | [google_compute_regions](docs/resources/google_compute_regions.md) |
| [google_compute_route](docs/resources/google_compute_route.md) | [google_compute_router](docs/resources/google_compute_router.md) |
| [google_compute_routers](docs/resources/google_compute_routers.md) | [google_compute_routes](docs/resources/google_compute_routes.md) |
| [google_compute_snapshot](docs/resources/google_compute_snapshot.md) | [google_compute_snapshots](docs/resources/google_compute_snapshots.md) |
| [google_compute_ssl_certificate](docs/resources/google_compute_ssl_certificate.md) | [google_compute_ssl_certificates](docs/resources/google_compute_ssl_certificates.md) |
| [google_compute_ssl_policies](docs/resources/google_compute_ssl_policies.md) | [google_compute_ssl_policy](docs/resources/google_compute_ssl_policy.md) |
| [google_compute_subnetwork](docs/resources/google_compute_subnetwork.md) | [google_compute_subnetworks](docs/resources/google_compute_subnetworks.md) |
| [google_compute_target_http_proxies](docs/resources/google_compute_target_http_proxies.md) | [google_compute_target_http_proxy](docs/resources/google_compute_target_http_proxy.md) |
| [google_compute_target_https_proxies](docs/resources/google_compute_target_https_proxies.md) | [google_compute_target_https_proxy](docs/resources/google_compute_target_https_proxy.md) |
| [google_compute_target_pool](docs/resources/google_compute_target_pool.md) | [google_compute_target_pools](docs/resources/google_compute_target_pools.md) |
| [google_compute_target_tcp_proxies](docs/resources/google_compute_target_tcp_proxies.md) | [google_compute_target_tcp_proxy](docs/resources/google_compute_target_tcp_proxy.md) |
| [google_compute_url_map](docs/resources/google_compute_url_map.md) | [google_compute_url_maps](docs/resources/google_compute_url_maps.md) |
| [google_compute_vpn_tunnel](docs/resources/google_compute_vpn_tunnel.md) | [google_compute_vpn_tunnels](docs/resources/google_compute_vpn_tunnels.md) |
| [google_compute_zone](docs/resources/google_compute_zone.md) | [google_compute_zones](docs/resources/google_compute_zones.md) |
| [google_container_cluster](docs/resources/google_container_cluster.md) | [google_container_clusters](docs/resources/google_container_clusters.md) |
| [google_container_node_pool](docs/resources/google_container_node_pool.md) | [google_container_node_pools](docs/resources/google_container_node_pools.md) |
| [google_container_regional_cluster](docs/resources/google_container_regional_cluster.md) | [google_container_regional_clusters](docs/resources/google_container_regional_clusters.md) |
| [google_dns_managed_zone](docs/resources/google_dns_managed_zone.md) | [google_dns_managed_zones](docs/resources/google_dns_managed_zones.md) |
| google_dns_resource_record_set](docs/resources/google_dns_resource_record_set.md) | [google_dns_resource_record_sets](docs/resources/google_dns_resource_record_sets.md) |
| [google_kms_crypto_key](docs/resources/google_kms_crypto_key.md) | [google_kms_crypto_key_iam_binding](docs/resources/google_kms_crypto_key_iam_binding.md) |
| [google_kms_crypto_key_iam_bindings](docs/resources/google_kms_crypto_key_iam_bindings.md) | [google_kms_crypto_keys](docs/resources/google_kms_crypto_keys.md) |
| [google_kms_key_ring](docs/resources/google_kms_key_ring.md) | [google_kms_key_ring_iam_binding](docs/resources/google_kms_key_ring_iam_binding.md) |
| [google_kms_key_ring_iam_bindings](docs/resources/google_kms_key_ring_iam_bindings.md) | [google_kms_key_rings](docs/resources/google_kms_key_rings.md) |
| [google_logging_project_exclusion](docs/resources/google_logging_project_exclusion.md) | [google_logging_project_sink](docs/resources/google_logging_project_sink.md) |
| [google_logging_project_sinks](docs/resources/google_logging_project_sinks.md) | [google_organization](docs/resources/google_organization.md) |
| [google_organizations](docs/resources/google_organizations.md) | [google_project](docs/resources/google_project.md) |
| [google_project_alert_policies](docs/resources/google_project_alert_policies.md) | [google_project_alert_policy](docs/resources/google_project_alert_policy.md) |
| [google_project_alert_policy_condition](docs/resources/google_project_alert_policy_condition.md) | [google_project_iam_binding](docs/resources/google_project_iam_binding.md) |
| [google_project_iam_bindings](docs/resources/google_project_iam_bindings.md) | [google_project_iam_custom_role](docs/resources/google_project_iam_custom_role.md) |
| [google_project_logging_audit_config](docs/resources/google_project_logging_audit_config.md) | [google_project_metric](docs/resources/google_project_metric.md) |
| [google_project_metrics](docs/resources/google_project_metrics.md) | [google_projects](docs/resources/google_projects.md) |
| [google_pubsub_subscription](docs/resources/google_pubsub_subscription.md) | [google_pubsub_subscriptions](docs/resources/google_pubsub_subscriptions.md) |
| [google_pubsub_topic](docs/resources/google_pubsub_topic.md) | [google_pubsub_topics](docs/resources/google_pubsub_topics.md) |
| [google_service_account](docs/resources/google_service_account.md) | [google_service_account_key](docs/resources/google_service_account_key.md) |
| [google_service_account_keys](docs/resources/google_service_account_keys.md) | [google_service_accounts](docs/resources/google_service_accounts.md) |
| [google_sourcerepo_repositories](docs/resources/google_sourcerepo_repositories.md) | [google_sourcerepo_repository](docs/resources/google_sourcerepo_repository.md) |
| [google_sql_database_instance](docs/resources/google_sql_database_instance.md) | [google_sql_database_instances](docs/resources/google_sql_database_instances.md) |
| [google_sql_users](docs/resources/google_sql_users.md) | [google_storage_bucket](docs/resources/google_storage_bucket.md) |
| [google_storage_bucket_acl](docs/resources/google_storage_bucket_acl.md) | [google_storage_bucket_iam_binding](docs/resources/google_storage_bucket_iam_binding.md) |
| [google_storage_bucket_iam_bindings](docs/resources/google_storage_bucket_iam_bindings.md) | [google_storage_bucket_object](docs/resources/google_storage_bucket_object.md) |
| [google_storage_bucket_objects](docs/resources/google_storage_bucket_objects.md) | [google_storage_buckets](docs/resources/google_storage_buckets.md) |
| [google_storage_default_object_acl](docs/resources/google_storage_default_object_acl.md) | [google_storage_object_acl](docs/resources/google_storage_object_acl.md) |
| [google_user](docs/resources/google_user.md) | [google_users](docs/resources/google_users.md) |

## Examples

Expand Down
55 changes: 55 additions & 0 deletions docs/resources/google_compute_regional_disk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: About the google_compute_regional_disk resource
platform: gcp
---

## Syntax
A `google_compute_regional_disk` is used to test a Google Regional Disk resource

## Examples
```
describe google_compute_regional_disk(project: 'chef-gcp-inspec', name: 'my_disk', region: 'region') do
it { should exist }
its('type') { should match 'pd-standard' }
end

describe.one do
google_compute_regional_disk(project: 'chef-gcp-inspec', name: 'my_disk', region: 'region').labels.each_pair do |key, value|
describe key do
it { should cmp "environment" }
end
end
end

describe google_compute_regional_disk(project: 'chef-gcp-inspec', name: 'nonexistent', region: 'region') do
it { should_not exist }
end
```

## Properties
Properties that can be accessed from the `google_compute_regional_disk` resource:

* `label_fingerprint`: The fingerprint used for optimistic locking of this resource. Used internally during updates.

* `creation_timestamp`: Creation timestamp in RFC3339 text format.

* `description`: An optional description of this resource. Provide this property when you create the resource.

* `id`: The unique identifier for the resource.

* `name`: Name of the resource. Provided by the client when the resource is created. The name must be 1-63 characters long, and comply with RFC1035. Specifically, the name must be 1-63 characters long and match the regular expression `[a-z]([-a-z0-9]*[a-z0-9])?` which means the first character must be a lowercase letter, and all following characters must be a dash, lowercase letter, or digit, except the last character, which cannot be a dash.

* `size_gb`: Size of the persistent disk, specified in GB. You can specify this field when creating a persistent disk using the sourceImage or sourceSnapshot parameter, or specify it alone to create an empty persistent disk. If you specify this field along with sourceImage or sourceSnapshot, the value of sizeGb must not be less than the size of the sourceImage or the size of the snapshot.

* `physical_block_size_bytes`: Physical block size of the persistent disk, in bytes. If not present in a request, a default value is used. Currently supported sizes are 4096 and 16384, other sizes may be added in the future. If an unsupported value is requested, the error message will list the supported values for the caller's project.

* `type`: URL of the disk type resource describing which disk type to use to create the disk. Provide this when creating the disk.

* `region`: A reference to the region where the disk resides.

* `replica_zones`: A reference to the zones where the disk resides.


## GCP Permissions

Ensure the [Compute Engine API](https://console.cloud.google.com/apis/library/compute.googleapis.com/) is enabled for the current project.
96 changes: 96 additions & 0 deletions libraries/google_compute_regional_disk.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# frozen_string_literal: false

require 'gcp_backend'
require 'google/compute/property/disk_disk_encryption_key'
require 'google/compute/property/disk_source_image_encryption_key'
require 'google/compute/property/disk_source_snapshot_encryption_key'

# A provider to manage Compute Engine resources.
class RegionalDisk < GcpResourceBase
name 'google_compute_regional_disk'
desc 'RegionalDisk'
supports platform: 'gcp'

attr_reader :id
attr_reader :creation_timestamp
attr_reader :name
attr_reader :params
attr_reader :description
attr_reader :size_gb
attr_reader :zone
attr_reader :source_snapshot
attr_reader :source_snapshot_id
attr_reader :source_snapshot_encryption_key
attr_reader :source_image
attr_reader :source_image_id
attr_reader :source_image_encryption_key
attr_reader :type
attr_reader :licenses
attr_reader :last_attach_timestamp
attr_reader :last_detach_timestamp
attr_reader :users
attr_reader :disk_encryption_key
attr_reader :labels
attr_reader :label_fingerprint
attr_reader :physical_block_size_bytes
attr_reader :region
attr_reader :replica_zones
attr_reader :status

def initialize(params)
super(params.merge({ use_http_transport: true }))
@params = params
@fetched = @connection.fetch(product_url, resource_base_url, params)
parse unless @fetched.nil?
end

def parse
@id = @fetched['id']
@creation_timestamp = parse_time_string(@fetched['creationTimestamp'])
@name = @fetched['name']
@size_gb = @fetched['sizeGb']
@type = @fetched['type']
@label_fingerprint = @fetched['labelFingerprint']
@region = @fetched['region']
@replica_zones = @fetched['replicaZones']
@physical_block_size_bytes = @fetched['physicalBlockSizeBytes']
@description = @fetched['description']
@last_attach_timestamp = parse_time_string(@fetched['lastAttachTimestamp'])
@last_detach_timestamp = parse_time_string(@fetched['lastDetachTimestamp'])
@labels = @fetched['labels']
@licenses = @fetched['licenses']
@users = @fetched['users']
@source_image = @fetched['sourceImage']
@zone = @fetched['zone']
@source_image_encryption_key = GoogleInSpec::Compute::Property::DiskSourceImageEncryptionKey.new(@fetched['sourceImageEncryptionKey'], to_s)
@source_image_id = @fetched['sourceImageId']
@disk_encryption_key = GoogleInSpec::Compute::Property::DiskDiskEncryptionKey.new(@fetched['diskEncryptionKey'], to_s)
@source_snapshot = @fetched['sourceSnapshot']
@source_snapshot_encryption_key = GoogleInSpec::Compute::Property::DiskSourceSnapshotEncryptionKey.new(@fetched['sourceSnapshotEncryptionKey'], to_s)
@source_snapshot_id = @fetched['sourceSnapshotId']
@stat = @fetched['status']
end

# Handles parsing RFC3339 time string
def parse_time_string(time_string)
time_string ? Time.parse(time_string) : nil
end

def exists?
[email protected]?
end

def to_s
"RegionalDisk #{@params[:name]}"
end

private

def product_url
'https://www.googleapis.com/compute/v1/'
end

def resource_base_url
'projects/{{project}}/regions/{{region}}/disks/{{name}}'
end
end
Loading