Google Compute Engine - Create Apache Server (Terraform)
In this post, I am going to create an apache web server on Google Compute Engine using Terraform.
Related:
- GCE (Browser): https://web-quickstart.blogspot.com/2021/05/google-compute-engine-create-apache.html
- EC2 (Terraform): https://web-quickstart.blogspot.com/2021/04/terraform-ec2-instance-with-ssh-setup.html
auth
gcloud auth application-default login
image
Get the list of images:
% gcloud compute images list | egrep 'NAME|centos'
NAME PROJECT FAMILY DEPRECATED STATUS
centos-7-v20210512 centos-cloud centos-7 READY
centos-8-v20210512 centos-cloud centos-8 READY
centos-stream-8-v20210512 centos-cloud centos-stream-8 READY
create
Create main.tf with the following content:
resource "google_compute_instance" "default" {
project = "YOUR_PROJECT_ID"
name = "instance-1"
zone = "us-central1-a"
machine_type = "e2-micro"
boot_disk {
initialize_params {
image = "centos-cloud/centos-7"
}
}
network_interface {
network = "default"
access_config {}
}
tags = ["http-server", "https-server"]
}
Run the terraform commands to create an instance.
terraform init
terraform plan
terraform apply
ssh
You can ssh into the server using gloud
gcloud compute ssh instance-1
https://cloud.google.com/compute/docs/instances/connecting-to-instance#gcloud
setup apache & cleanup
The remaining steps are same as https://web-quickstart.blogspot.com/2021/05/google-compute-engine-create-apache.html
1. install apache
2. access the server over http
3. destroy instance
Comments
Post a Comment