gce_compute
Version information
This version is compatible with:
- Puppet Enterprise 3.x
- Puppet 3.x
- , , , ,
This module has been deprecated by its author since Jan 8th 2019.
The author has suggested google-gcompute as its replacement.
Start using this module
Documentation
#Puppet for Google Compute Engine
##Table of Contents
##Overview
The gce_compute module provides everything you need to manage compute instances, disk storage and network interfaces in Google Compute Engine in Puppet's declarative DSL. It will even provision and configure Puppet Enterprise or Puppet Open Source during instance creation.
It should work on any system that supports Google's Cloud SDK but it has not been tested on Windows.
##Setup
In order to use this module, you will need to signup for a Google Cloud Platform account and enable Google Compute Engine.
Setup a host with Google Cloud SDK
You will need to designate one machine to be your host.
This machine will be responsible for provisioning objects into Google Compute
using the gcloud compute
command-line utility that is bundled as part of the Cloud
SDK.
You may either use a virtual machine inside of your Google Cloud project as your host, or you may use a machine outside of the project.
Setup a host inside of your Google Cloud project
If you would like to use a virtual machine inside of your project as your host, setup is simple. Create the instance manually, either on the Developers Console or via the gcloud
command-line interface, making sure to enable the compute-rw
scope for your instance.
- In the Developers Console, create an instance via
Compute > Compute Engine > VM instances > New instance
, show the security options, and select "Read Write" underProject Access > Compute
. - In
gcloud
, just usegcloud compute instances create
with the--scopes compute-rw
flag.
Once you've setup your instance with the compute-rw
scope, you don't need do anything else: gcloud
comes preinstalled on the VM, and the instance is able to read and write resources within its project.
Setup a host outside of your Google Cloud project
If you would like to use a machine outside of your project as your host, you'll need to install and authenticate gcloud.
Install Puppet and this module
You'll now want to install Puppet on your host. Once you've installed Puppet, do
$ puppet module install puppetlabs-gce_compute
At this point, you should be ready to go!
Quick Start with Puppet Enterprise
These instructions assume you have installed and configured the Google Cloud SDK and Puppet from the previous step.
Puppet Enterprise is free to evaluate on up to 10 nodes and is installed for you as part of these examples.
Bring up a GCE instance that will auto-install the PE Master
One of the easiest ways to take advantage of this module is to build a single
instance in Google Compute Engine to serve as your Puppet Enterprise master and
console. After going through the setup, copy the the manifest in examples/puppet_enterprise/up.pp
, to your host, and run
$ puppet apply up.pp
The install may take up to ten minutes but the master instance should be up within a minute or two. The manifest is configured to wait until all of the startup scripts are finished running.
As of right now, the puppet-test-enterprise-agent-instance
doesn't properly
connect to the master.
Use the future parser to build many more instances.
You can do something like this, in agent.pp
:
$a = ['1','2','3','4','5','6','7','8']
each( $a ) |$value|{
gce_instance { "sample-agent-${value}":
ensure => present,
zone => 'us-central1-f',
startup_script => 'pe-simplified-agent.sh',
block_for_startup_script => true,
metadata => {
'pe_role' => 'agent',
'pe_master' => 'puppet-test-enterprise-master-instance',
'pe_version' => '3.3.1',
}
}
$ puppet apply agent.pp --parser future
Usage
The gce_compute module provides the following resource types:
gce_instance
- Virtual machine instances that can be assigned roles.gce_disk
- Persistent disks that can be attached to instances.gce_firewall
- Firewall rules that specify the traffic to your instances.gce_network
- Networks that routes internal traffic between virtual machine instances. Firewalls and instances are associated with networks.gce_forwardingrule
- Load balancer forwarding rules.gce_httphealthcheck
- Load balancer HTTP health checking.gce_targetpool
- Load balancer collection of instances.gce_targetpoolhealthcheck
- Assignment of a health-check to a targetpool.gce_targetpoolinstance
- Assignment of an instance to a targetpool.
These types allow users to describe application stacks in Google Compute Engine using Puppet's DSL. This provides the following benefits:
- Users can express application deployments as text that can be version controlled.
- Teams can share and collaborate on application deployments described using Puppet's DSL.
- Users can take advantage of the composition aspects of the Puppet DSL to create reusable and extendable abstraction layers on top of multi-node deployment descriptions.
- Allows Puppet to support ongoing management of application stacks created in GCE.
Service Account Scopes
Note that if your GCE instances will need access to other Google Cloud
services (e.g.
Google Cloud Storage,
Google BigQuery, etc.) then you
can specify access with the scopes
attribute. For more information
about Service Account scopes, see
this page.
The PE Quick Start example assigns the Master a compute-ro service scope which allows it to query metadata about other instances within the GCE project. This information is used for automatic certificate signing.
Automatic Certificate Signing
If you plan to host your Puppet master and agents in Google Compute Engine, this module can take advantage of Google's API and Metadata services to verify and automatically connect agents to the master so that they can immediately be assigned work after creation.
To use this capability, you must specify particular properties in your gce_instance resources.
- Within the Puppet Master resource, assign a service account scope that can query GCE metadata.
service_account_scopes => ['compute-ro'],
-
The Puppet Master resource also needs to install the gce_compute module and configure itself with the provided autosigner class.
modules => ['puppetlabs-gce_compute'], manifest => 'include gce_compute::autosign',
-
Within the host resources, assign the
pe-simplified-agent.sh
startup script.
startupscript => 'pe-simplified-agent.sh',
With this configuration, agents will retrieve particular metadata about themselves from the GCE metadata service and insert them into their certificate signing request. The Puppet Master will query the metadata service for the same information and ensure that it matches what the agent claims in its CSR.
Be careful. This configuration trusts that you've protected your Google credentials and that you trust everyone who has credentials to provision instances inside of your Google Compute Engine project. So long as this chain remains trustworthy, this method will reliably connect newly provisioned instances to your PE infrastructure without interaction.
Enable/Disable Live Instance Migration
Your Compute Engine instances, by default, will enable live migration. In
the event that Google needs to perform a datacenter maintenance, your instance
will be automatically migrated to a new location without visible impact.
This feature can be disabled by setting maintenance_policy
to TERMINATE
.
Classifying resources
In addition to creating instances with gce_instance
, you may pass additional parameters to configure and classify the instance. The work is done during instance creation by a bootstrap script. The module includes a scripts to configure both open source Puppet and Puppet Enterprise.
In the gce_instance
resource, you may provide the following parameter to choose a startup script. You can use any executable script that's located in the gce_compute modules files directory and can be interpreted by the OS that GCE provisions.
startupscript => 'puppet-community.sh'
startupscript => 'puppet-enterprise.sh'
startupscript => 'script_to_use.sh'
The classification is currently only supported by running puppet apply
during the bootstrapping process of the created instances
by passing in the contents of a manifest file with the manifest
parameter.
Classification is specified with the following gce_instance
parameters:
puppet_master
- Hostname of the puppet master instance that the agent instance must be able to resolve. If this parameter is specified, then it is used as theserver
parameter inpuppet.conf
.puppet_service
-absent
orpresent
; if this parameter is specified, then the puppet service is automatically started on the managed instance and set to restart on boot (in/etc/default/puppet
).puppet_manifest
- A string to pass in as a local manifest file and applied during the bootstrap process. You can use any manifest that's located in the gce_compute modules files directory.puppet_modules
- List of modules that should be installed from the forge.puppet_module_repos
- Modules that should be installed from GitHub. Accepts a hash where the keys indicates the module directory where the module should be installed and the value points to the GitHub repo.
If you would like Puppet to wait until the startup script has completed running, you may use the following parameters:
block_for_startup_script
- Whether the resource should block until its startup sctipt has completed.startup_script_timeout
- Amount of time to wait before timing out when blocking for a startup script.
Puppet Enterprise
If you choose startupscript => 'puppet-enterprise.sh'
, you can provide data needed for the PE installer answer file in the metadata
parameter.
The following example specifies the PE version and PE Console login details.
metadata => {
'pe_role' => 'master',
'pe_version' => '3.1.0',
'pe_consoleadmin' => 'admin@example.com',
'pe_consolepwd' => 'puppetize',
},
This example will provision a PE Agent and will point it to your PE master.
metadata => {
'pe_role' => 'agent',
'pe_master' => "[gce_instance_namevar].c.[gce_projectid].internal",
'pe_version' => '3.1.0',
},
##Development
To setup a development environment, follow the Setup instructions above, up until
$ puppet module install puppetlabs-gce_compute
Instead, clone this repository, cd
into the repository, then do
$ rake install
If you're going to be doing any kind of modifications, I highly recommend using rbenv, ruby-build, (don't forget the dependencies!) and bundler.
###Testing
This module has unit and live integration, (acceptance,) tests. The whole test suite takes about 20 minutes, and can be run using
$ rake spec
Unit tests live in spec/unit
, and include tests for types and providers, and can be run with
$ rake spec:unit
Live integration tests live in spec/integration
, and will actually spin up and tear down live resources in your GCP environment. Integration
tests can be run with
$ rake spec:integration
Integration tests use the system puppet and modules, so, in preparation for running, Rake will automatically install the current version of the module. If you would like to run an individual test file, you must reinstall the module manually, for example:
$ rake install && rspec spec/integration/puppet/puppet_community_spec.rb
If integration tests fail, they'll leave resources lying around in you project. To cleanup, you can remove them altogether:
$ rake spec:integration:clean
or individually, for example:
$ rake install && puppet apply examples/puppet_community/down.pp
Migrating from v0
In rewriting this module since v0, types have changed to be as consistent with gcloud
as possible, which causes some breaking changes in the types. Below are notes about what attributes have changed name, (and to what,) what attributes are no longer supported, and also the manifest syntax changes.
(This attempts to be a complete list, but may not be. If you have questions, ask, or file a bug.)
gce_disk
size_gb
is nowsize
;source_image
is nowimage
; andwait_until_complete
is no longer supported—all commands wait until they are complete.
gce_firewallrule
This resource used to be called gce_firewall.
allowed
is nowallow
, and takes an array of strings rather than a comma-separated string;allowed_ip_sources
is nowsource_ranges
, and takes an array of strings rather than a comma-separated string; andallowed_tag_sources
is nowsource_tags
, and takes an array of strings rather than a comma-separated string.
gce_forwardingrule
ip
is nowaddress
, and takes the name of an address resource;protocol
is nowip_protocol
; andtarget
is nowtarget_pool
.
gce_httphealthcheck
check_interval_sec
is nowcheck_interval
;check_timeout_sec
is nowtimeout
;
gce_instance
authorized_ssh_keys
is no longer supported, (read more at Connecting to an instance using ssh);disk
is nowboot_disk
, and if noboot_disk
is specified, a disk will be automatically provisioned, and will be set to auto-destroy when the instance is deleted;external_ip_address
is nowaddress
, and takes the name of an address resource;internal_ip_address
was read-only, and is no longer supported;on_host_maintenance
is nowmaintenance_policy
;service_account
andservice_account_scopes
are now both reflected inscopes
, andscopes
takes an array of strings, (seeexamples/gce_instance/up.pp
for an example);add_compute_key_to_project
is no longer supported, (read more at Connecting to an instance using ssh);use_compute_key
is no longer supported, (read more at Connecting to an instance using ssh);enc_classes
is no longer supported;manifest
is nowpuppet_manifest
, and takes a manifest filename, rather than an inline manifest;modules
is nowpuppet_modules
, and the metadata is space-separated rather than comma-separated; andmodule_repos
is nowpuppet_module_repos
, is now stored inpuppet_module_repos
metadata, instead ofpuppet_repos
, and that metadata is space-separated rather than comma-separated.
See examples/puppet_community/up.pp
for an example of how to use the Puppet attributes: puppet_master
, puppet_service
, puppet_manifest
, puppet_modules
, and puppet_module_repos
.
gce_network
gateway
was read-only, and is no longer supported.
gce_targetpool
health_checks
is nowhealth_check
.instances
now takes a hash, of zones and lists of instances, (seeexamples/gce_targetpool/up.pp
for an example).
gce_targetpoolhealthcheck & gce_targetpoolinstance
Both of these types are now reflected in gce_targetpool
, (see examples/gce_targetpool/up.pp
for an example).
Types in this module release
2015-07-29 - Release 1.0.0
Summary
Almost the entire module is rewritten to use gcloud instead of the deprecated gcutil. Docs have been revamped, lots of examples added, and general clean-up to make the module much more usable.
2014-09-26 - Release 0.5.0
Version 0.5.0 adds the ability to autosign certificates in a trusted fashion, between a PE master and the Google Cloud Platform API. See the README for more details which was also improved in this version.
2014-05-27 - Release 0.4.0
This release adds new targetpool functionality, makes it easier to manage the project key, fixes a number of small bugs, and improves the documentation.
Features
- Prefer user-specified boot disk if present.
- Add
add_compute_key_to_project
to manage SSH key. - Add
region
,session_affinity
,backup_pool
, andfailover_ratio
for targetpool resources.
Bugfixes
- Remove prep_master function from puppet-enterprise.sh.
- Fix instance blocking on startup script.
- Further fixes for GCE v1.
- Rewrite the README.
- Adds on_host_maintenance instructions.
- Hack around failure when metadata param absent.
Known Bugs
- No known bugs
20131210 v0.3.0
- Updated for GCE v1 (General Availability) and Cloud SDK
- Remove tested support for older gcutil versions running against beta APIs
- Matt Bookman contributions for puppet_master, puppet_service, on_host_maintenance
20131105 v0.2.0
- Updated for gcutil-1.10.0 (v1beta16)
- Fixes #18 submited by @jhoblitt
- Fixes #17 v1beta16 with help from Matt Bookman
20130814 v0.1.0
- Updated for gcutil-1.8.3 (v1beta15)
- Added GCE Load-Balancer support
- Added custom manifest support
20130513 v0.0.2
- Updated for gcutil-1.7.2 (v1beta14)
20120920 v0.0.1
- Initial release by @bodepd
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2013 Puppet Labs Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.