This page describes when and why you should create deterministic instance templates. Deterministic instance templates make it explicitly clear in terms of the type of third-party services or applications that should be installed on your instances when the instance template is deployed. By creating deterministic instance templates, you minimize ambiguity and unexpected behavior from your instance templates.
In general, we recommend that the properties of your instance template are as explicit and deterministic as possible. If you employ startup scripts in your instance templates that install or use third-party services, make sure that these scripts provide explicit information, such as the version of application to install. Compute Engine can only rely on information defined in the template and has no control over referenced third-party services. If your template is too vague, your instance template might behave unexpectedly.
Note: This is just an example snippet pointing to a non-existent server at 108.59.87.185. Copying this example directly will fail when the script attempts to connect to 108.59.87.185. Instead, replace the last line with your own server information, if applicable.
The script does not explicitly define which version of apache2 to install, and relies on the current version available in the apt-get repository.
The script relies on a file hosted on a third-party that isn’t versioned and could have been changed since the last time the instance template was used.
If you use an autoscaler, a non-deterministic instance template could cause your autoscaler to add new instances to a managed instance group with a different configuration, such as a different version of apache2.
Similarly, if you applied this template to a managed instance group, updated the group to a different template using the Instance Group Updater service, and then decided to rollback to the previous template, you might end up with instances using a different version of apache2 or index.php file than before the update, because your instances would always fetch the most recent version at startup.
Create a custom image to use as the image for the template. This is preferable to startup scripts as it guarantees every instance will be the same, while startup scripts might have different result after distribution package updates. Use startup scripts in your instance templates for prototyping and rapid development, and use custom images when you are ready to deploy production-quality services.
where “version_2_1_3” is a subdirectory containing PHP scripts for the version 2.1.3 of your service.