You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CI/CD Workshop Google Cloud Terraform
This repository contains Terraform code that demonstrates how to create a new Google Cloud Instance and deploy a Docker container using Google's Container-Optimized OS image. The Container-Optimized OS is an operating system image optimized for running Docker containers on Compute Engine VMs. By leveraging this image, you can quickly and securely deploy your Docker containers on Google Cloud Platform.
Prerequisites
Before using this code, ensure that you have completed the following steps:
Create a free Google Cloud account.
Create a new Google Cloud Platform project by following the instructions here.
Generate Google Cloud credentials by visiting the create service account key page. Save the JSON credentials file in the terraform/google_cloud/ directory. Rename the file to cicd_demo_gcp_creds.json for security reasons and add it to the project's .gitignore file to prevent accidental exposure.
Install Terraform locally by following the instructions here.
Usage
To use this Terraform code, follow these steps:
Open a terminal and navigate to the terraform/google_cloud/ directory.
Run terraform init to initialize the Google Terraform Plugins.
Update the values in the main.tf file according to your project's configuration:
Modify the project_name variable to match the name of your Google Cloud project.
Update the docker_declaration variable with the desired Docker image.
Adjust other variables, such as port_number and boot_image_name, if necessary.
Run terraform plan -out=plan.txt to generate an execution plan and preview the changes that Terraform will make.
Execute the plan by running terraform apply plan.txt. This command will create a new Google Compute Instance based on the Terraform configuration and the specified Docker image.
Once the instance is created, the public IP address will be displayed as the output. Copy the IP address and append :5000 to access the deployed application, e.g., http://<Public_IP_Address>:5000.
To clean up the resources created by Terraform, run terraform destroy. This command will destroy the assets created in this tutorial.
Optional: DNS Host Configuration
If you want to assign a domain name to your deployment, you can follow these optional steps to configure a DNS hostname using NameCheap.com:
Install the terraform-provider-namecheap plugin by running the provided commands in a terminal. This plugin allows Terraform to interact with NameCheap.com.
Retrieve your NameCheap.com API credentials and tokens by enabling API access and following the instructions provided here.
Configure the namecheap.tf file with your NameCheap provider credentials, domain name, and desired host name. Remember to protect the sensitive information in this file and add it to the project's .gitignore file.
Run terraform apply to create a new DNS hostname entry for your domain using the specified host name.
Summary
This repository provides a comprehensive guide and Terraform code for deploying a server on Google Cloud Platform and running a Docker container using Terraform. By following the instructions and customizing the variables to match your project's requirements, you can quickly set up a CI/CD environment with ease.
Resources
0 commit comments