GOOGLE-PROFESSIONAL-CLOUD-DEVELOPER practice question 34 of 35
You want to create “fully baked” or “golden” Compute Engine images for your application. You need to bootstrap your application to connect to the appropriate database according to the environment the application is running on (test, staging, production). What should you do?
Full set: 265 questionsThis approach correctly utilizes instance metadata, which is the standard Google Cloud mechanism for passing configuration data to a virtual machine instance at runtime. By storing the database connection string as a custom metadata value, a single "golden" image can be used across all environments (test, staging, production). The application within the instance can then query the internal metadata server—a highly available local service—to retrieve the appropriate connection string for its specific environment. This decouples the application artifact from its runtime configuration, which is a fundamental best practice for creating scalable and manageable systems.
A. This approach is inefficient and contradicts the "golden image" principle. It creates image sprawl, making updates and management complex and error-prone.
B. Tags are primarily intended for network firewall rules and resource organization, not for passing application configuration or sensitive data like connection strings.
C. Setting instance metadata does not automatically create a corresponding environment variable within the instance. A startup script would be needed to read the metadata and export it as an environment variable.
1. Google Cloud Documentation, Compute Engine, "Storing and retrieving instance metadata": This document explicitly states, "Custom metadata is useful for passing in arbitrary values to your instance that can be used by your startup scripts and other code running on your instance." It provides examples of querying the metadata server from within an instance using curl "http://metadata.google.internal/computeMetadata/v1/instance/attributes/DATABASE" -H "Metadata-Flavor: Google". This directly supports the method described in option D.
2. Google Cloud Documentation, VPC, "Tags overview": This page clarifies the purpose of tags: "Tags are strings that you can add to your Compute Engine virtual machine (VM) instances. Tags let you make firewall rules and routes applicable to specific VM instances." This confirms that using tags for application configuration, as suggested in option B, is not their intended use.
3. Google Cloud Architecture Center, "Building immutable infrastructure with Packer and Spinnaker on Compute Engine": This article describes the best practice of creating immutable or "golden" images. It emphasizes separating the application artifact from its configuration, which is injected at launch time. This principle invalidates option A and supports the dynamic configuration approach of option D.
4. Google Cloud Documentation, Compute Engine, "Running startup scripts": This documentation shows that to use metadata values as environment variables, a script must first query the metadata server and then export the value. This confirms that the direct link assumed in option C does not exist automatically. For example, a script would need a line like DBSTRING=$(curl ...) followed by export DBSTRING.
Keep practicing
Take the free GOOGLE-PROFESSIONAL-CLOUD-DEVELOPER practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other GOOGLE-PROFESSIONAL-CLOUD-DEVELOPER practice questions
- Question 1You have an application controlled by a managed instance group. When you deploy a new ver…
- Question 2Your service adds text to images that it reads from Cloud Storage. During busy times of t…
- Question 3You have been tasked with planning the migration of your company’s application from on-pr…
- Question 4You plan to make a simple HTML application available on the internet. This site keeps inf…
- Question 5HipLocal's APIs are showing occasional failures, but they cannot find a pattern. They wan…
- Question 6Your company has created an application that uploads a report to a Cloud Storage bucket. …
