This project deploys a Google Cloud infrastructure using Terraform to create a VPC, subnets, firewall rules, and compute instances.
This section configures a compute instance. It specifies the name, environment, project, instance tags, machine type, GCP zone, service account scopes, subnetwork (retrieved from the subnet module), and SSH keys for access.
module "compute_instance" {
source = "git@github.com:sureshyadav76/terraform-google-vm.git"
name = "app"
environment = "test"
instance_count = 1
instance_tags = ["foo", "bar"]
machine_type = "e2-small"
image = "ubuntu-2204-jammy-v20230908"
gcp_zone = "asia-northeast1-a"
service_account_scopes = ["cloud-platform"]
subnetwork = var.subnetwork
# Enable public IP only if enable_public_ip is true
enable_public_ip = true
metadata = {
ssh-keys = <<EOF
test:ssh-rsa AAAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxbLLNM= suresh@suresh
EOF
}
}
You can customize the input variables according to your specific requirements.
For detailed examples on how to use this module, please refer to the Examples directory within this repository.
Your Name Replace MIT and sureshyadav76 with the appropriate license and your information. Feel free to expand this README with additional details or usage instructions as needed for your specific use case.
This project is licensed under the MIT License - see the LICENSE file for details.
Name | Version |
---|---|
terraform | >= 1.6.6 |
>= 3.50, < 5.11.0 |
Name | Version |
---|---|
>= 3.50, < 5.11.0 |
Name | Source | Version |
---|---|---|
labels | git::https://github.com/sureshyadav76/terraform-google-labels.git | v1.0.0 |
Name | Type |
---|---|
google_compute_instance.default | resource |
google_client_config.current | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
allow_stopping_for_update | must be set to true or your instance must have a desired_status of TERMINATED in order to update this field. | bool |
true |
no |
create_instances | Toggle to determine whether instances should be created or not. Set to 'true' to create instances, 'false' to skip instance creation. | bool |
true |
no |
enable_public_ip | Predefined enable_public_ip address for the instance. | bool |
false |
no |
environment | Environment (e.g. prod , dev , staging ). |
string |
"" |
no |
gcp_zone | The GCP zone to create resources in | string |
"" |
no |
image | Source image family. If neither source_image nor source_image_family is specified, defaults to the latest public CentOS image. | string |
"ubuntu-2204-jammy-v20230908" |
no |
instance_count | The number of instances to create. | number |
1 |
no |
instance_tags | Network tags, provided as a list | list(string) |
[] |
no |
label_order | Label order, e.g. sequence of application name and environment name ,environment ,'attribute' [webserver ,qa ,devops ,public ,] . |
list(any) |
[ |
no |
machine_type | Machine type to create, e.g. n1-standard-1 | string |
"" |
no |
managedby | ManagedBy, eg 'sureshyadav76'. | string |
"sureshyadav76" |
no |
metadata | Metadata, provided as a map | map(string) |
{} |
no |
metadata_startup_script | User startup script to run when instances spin up | string |
"" |
no |
name | Name of the resource. Provided by the client when the resource is created. | string |
"test" |
no |
repository | Terraform current module repo | string |
"https://github.com/sureshyadav76/terraform-google-vm" |
no |
service_account_email | The service account e-mail address. | string |
"" |
no |
service_account_scopes | A list of service scopes. | list(string) |
[] |
no |
subnetwork | Subnet to deploy to. Only one of network or subnetwork should be specified. | string |
"" |
no |
Name | Description |
---|---|
cpu_platform | The CPU platform used by this instance. |
current_status | The current status of the instance. |
instance_count | The value of the instance_count variable. |
instance_count_output | The value of the instance_count variable. |
instance_id | The server-assigned unique identifier of this instance. |
label_fingerprint | The unique fingerprint of the labels. |
metadata_fingerprint | The unique fingerprint of the metadata. |
name | The name of the instance. |
self_link | The URI of the created resource. |
tags_fingerprint | The unique fingerprint of the tags. |