GOOGLE-PROFESSIONAL-CLOUD-DEVELOPER practice question 14 of 35

You are developing an application that will be launched on Compute Engine instances into multiple distinct projects, each corresponding to the…

Full set: 265 questions
You are developing an application that will be launched on Compute Engine instances into multiple distinct projects, each corresponding to the environments in your software development process (development, QA, staging, and production). The instances in each project have the same application code but a different configuration. During deployment, each instance should receive the application’s configuration based on the environment it serves. You want to minimize the number of steps to configure this flow. What should you do?
Answer options
A: When creating your instances, configure a startup script using the gcloud command to determine the project name that indicates the correct environment.
B: In each project, configure a metadata key “environment” whose value is the environment it serves. Use your deployment tool to query the instance metadata and configure the application based on the “environment” value. Correct answer
C: Deploy your chosen deployment tool on an instance in each project. Use a deployment job to retrieve the appropriate configuration file from your version control system, and apply the configuration when deploying the application on each instance.
D: During each instance launch, configure an instance custom-metadata key named “environment” whose value is the environment the instance serves. Use your deployment tool to query the instance metadata, and configure the application based on the “environment” value.
Correct Answer:
B. In each project, configure a metadata key “environment” whose value is the environment it serves. Use your deployment tool to query the instance metadata and configure the application based on the “environment” value.
Explanation

The most efficient and scalable solution is to use project-wide custom metadata. By setting a metadata key-value pair (e.g., environment: production) at the project level, all Compute Engine instances within that project automatically inherit this metadata. An application or a startup script on any instance can then query the metadata server to retrieve the value of the "environment" key. This approach minimizes configuration steps because the metadata is set only once per project, rather than for each individual instance, and it decouples the configuration from potentially brittle conventions like project naming.

Why Incorrect

A. This is less robust than using dedicated metadata. It creates a dependency on project naming conventions, which might change or not be consistently applied, making the solution brittle.
C. This option is incomplete. It describes a deployment process but fails to address the core problem of how the deployment tool will determine which environment's configuration to apply.
D. This approach is less efficient than using project-wide metadata. It requires configuring the metadata for every single instance at launch, which is more steps and more error-prone than setting it once for the entire project.

References

1. Official Google Cloud Documentation - Storing and retrieving metadata:

Source: Google Cloud Documentation, "About VM metadata".

Reference: In the "Types of metadata" section, it states: "You can set custom metadata for a project and for an instance. Metadata that you set at the project level is available to all of the virtual machine (VM) instances in that project." This directly supports the efficiency and inheritance model of option B.

Link: https://cloud.google.com/compute/docs/metadata/overview#custom-metadata

2. Official Google Cloud Documentation - Setting custom project-wide metadata:

Source: Google Cloud Documentation, "Set custom metadata".

Reference: The section "Set project-wide custom metadata" provides the gcloud compute project-info add-metadata command. This demonstrates the single action required per project, confirming that it minimizes configuration steps for an entire environment, as required by the question.

Link: https://cloud.google.com/compute/docs/metadata/set-custom-metadata#set-project-wide-custom-metadata

Scroll to Top