Problem
When automating a Terraform Enterprise (TFE) installation on a Red Hat Enterprise Linux (RHEL) instance in Google Cloud Platform (GCP), the google_compute_instance resource may fail to execute the user data script provided in the metadata_startup_script attribute.
This results in a silent failure where the TFE installation script does not run, and no TFE containers are started on the server.
Prerequisites
- A Google Cloud Platform project.
- A Red Hat Enterprise Linux instance on GCP.
Cause
The metadata_startup_script attribute relies on the cloud-init service to process and execute user data templates on the virtual machine instance. If cloud-init is not installed and enabled on the RHEL image, the startup script will not be executed.
Solution
To resolve this issue, you must connect to the RHEL instance and manually install and enable the cloud-init service.
-
Install the
cloud-initpackage using thednfpackage manager.$ dnf install cloud-init
-
Enable the
cloud-initservice to start automatically on boot.$ systemctl enable cloud-init
-
Start the
cloud-initservice immediately.$ systemctl start cloud-init
Outcome
After installing and starting the cloud-init service, it will process the user data from the instance metadata. If the instance is rebooted or a new instance is created from a custom image with cloud-init installed, the metadata_startup_script will execute as expected, completing the TFE installation.
Additional Information
- For more details on the GCP compute instance resource, refer to the google_compute_instance resource documentation.