A google_compute_instance is used to test a Google Instance resource
This resource has beta fields available. To retrieve these fields, include beta: true in the constructor for the resource
describe google_compute_instance(project: 'chef-gcp-inspec', zone: 'zone', name: 'inspec-instance') do
it { should exist }
its('machine_type') { should match 'n1-standard-1' }
its('tags.items') { should include 'foo' }
its('tags.items') { should include 'bar' }
its('tag_count') { should cmp 2 }
its('service_account_scopes') { should include 'https://www.googleapis.com/auth/compute.readonly' }
its('metadata_keys') { should include '123' }
its('metadata_values') { should include 'asdf' }
end
describe google_compute_instance(project: 'chef-gcp-inspec', zone: 'zone', name: 'nonexistent') do
it { should_not exist }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm-not-there') do
it { should_not exist }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('status') { should eq 'RUNNING' }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('machine_type') { should match "f1-micro" }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('cpu_platform') { should match "Intel" }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('disk_count'){should eq 2}
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('network_interfaces_count'){should eq 1}
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('tag_count'){should eq 1}
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('first_network_interface_nat_ip_exists'){ should be true }
its('first_network_interface_name'){ should eq "external-nat" }
its('first_network_interface_type'){ should eq "one_to_one_nat" }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone: 'us-east1-b', name: 'inspec-test-vm') do
its('labels_keys') { should include 'my_favourite_label' }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone:'us-east1-b', name:'inspec-test-vm').label_value_by_key('business-area') do
it { should match '^(marketing|research)$' }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone:'us-east1-b', name:'inspec-test-vm') do
its('metadata_keys') { should include 'patching-type' }
end
describe google_compute_instance(project: 'chef-inspec-gcp', zone:'us-east1-b', name:'inspec-test-vm').metadata_value_by_key('patching-window') do
it { should match '^\d{1}-\d{2}$' }
end
Properties that can be accessed from the google_compute_instance resource:
can_ip_forwardcpu_platformcreation_timestampdeletion_protectiondisksauto_deletebootdevice_namedisk_encryption_keyraw_keyrsa_encrypted_keysha256indexinitialize_paramsdisk_namedisk_size_gbdisk_typesource_imagesource_image_encryption_keyraw_keysha256interfacePossible values:
modePossible values:
sourcetypePossible values:
licensesguest_acceleratorsaccelerator_count : The number of the guest accelerator cards exposed to this instance.
accelerator_type : Full or partial URL of the accelerator type resource to expose to this instance.
hostnameidlabel_fingerprintlabelsmetadatamachine_typemin_cpu_platformname[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.network_interfacesaccess_configs : An array of configurations for this interface. Currently, only one access config, ONE_TO_ONE_NAT, is supported. If there are no accessConfigs specified, then this instance will have no external internet access.
`name`
: The name of this access configuration. The default and recommended name is External NAT but you can use any arbitrary string you would like. For example, My external IP or Network Access.
`nat_ip`
: Reference to an address. An external IP address associated with this instance. Specify an unused static external IP address available to the project or leave this field undefined to use an IP from a shared ephemeral IP address pool. If you specify a static external IP address, it must live in the same region as the zone of the instance.
`type`
: The type of configuration. The default and only option is ONE_TO_ONE_NAT.
Possible values:
- ONE_TO_ONE_NAT
`set_public_ptr`
: Specifies whether a public DNS PTR record should be created to map the external IP address of the instance to a DNS domain name.
`public_ptr_domain_name`
: The DNS domain name for the public PTR record. You can set this field only if the setPublicPtr field is enabled.
`network_tier`
: This signifies the networking tier used for configuring this access configuration. If an AccessConfig is specified without a valid external IP address, an ephemeral IP will be created with this networkTier. If an AccessConfig with a valid external IP address is specified, it must match that of the networkTier associated with the Address resource owning that IP.
Possible values:
- PREMIUM
- STANDARD
alias_ip_ranges : An array of alias IP ranges for this network interface. Can only be specified for network interfaces on subnet-mode networks.
`ip_cidr_range`
: The IP CIDR range represented by this alias IP range. This IP CIDR range must belong to the specified subnetwork and cannot contain IP addresses reserved by system or used by other network interfaces. This range may be a single IP address (e.g. 10.2.3.4), a netmask (e.g. /24) or a CIDR format string (e.g. 10.1.2.0/24).
`subnetwork_range_name`
: Optional subnetwork secondary range name specifying the secondary range from which to allocate the IP CIDR range for this alias IP range. If left unspecified, the primary range of the subnetwork will be used.
name : The name of the network interface, generated by the server. For network devices, these are eth0, eth1, etc
network : Specifies the title of an existing network. When creating an instance, if neither the network nor the subnetwork is specified, the default network global/networks/default is used; if the network is not specified but the subnetwork is specified, the network is inferred.
network_ip : An IPv4 internal network address to assign to the instance for this network interface. If not specified by the user, an unused internal IP is assigned by the system.
subnetwork : Reference to a VPC network. If the network resource is in legacy mode, do not provide this property. If the network is in auto subnet mode, providing the subnetwork is optional. If the network is in custom subnet mode, then this field should be specified.
schedulingautomatic_restart : Specifies whether the instance should be automatically restarted if it is terminated by Compute Engine (not terminated by a user). You can only set the automatic restart option for standard instances. Preemptible instances cannot be automatically restarted.
on_host_maintenance : Defines the maintenance behavior for this instance. For standard instances, the default behavior is MIGRATE. For preemptible instances, the default and only possible behavior is TERMINATE. For more information, see Setting Instance Scheduling Options.
preemptible : Defines whether the instance is preemptible. This can only be set during instance creation, it cannot be set or changed after the instance has been created.
service_accountsemail : Email address of the service account.
scopes : The list of scopes to be made available for this service account.
shielded_instance_configenable_secure_boot : Defines whether the instance has Secure Boot enabled.
enable_vtpm : Defines whether the instance has the vTPM enabled
enable_integrity_monitoring : Defines whether the instance has integrity monitoring enabled.
statusPossible values:
status_messagetagsfingerprintitemszoneEnsure the Compute Engine API is enabled for the current project.
© Chef Software, Inc.
Licensed under the Creative Commons Attribution 3.0 Unported License.
The Chef™ Mark and Chef Logo are either registered trademarks/service marks or trademarks/servicemarks of Chef, in the United States and other countries and are used with Chef Inc's permission.
We are not affiliated with, endorsed or sponsored by Chef Inc.
https://docs.chef.io/inspec/resources/google_compute_instance/