Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assignment 6 #18

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ resource "random_password" "password" {
override_special = "-@&4"
}

data "google_project" "project-id" {
}

resource "google_compute_network" "private_vpc" {
name = var.vpc_name
auto_create_subnetworks = var.auto_create_subnets
Expand Down Expand Up @@ -136,12 +139,39 @@ output "db_private_ip" {
value = "${google_sql_database_instance.db_instance.private_ip_address}"
}

resource "google_service_account" "webapp_instance_service_account" {
account_id = "webapp-service-account"
display_name = "webapp-instance-account"
}

resource "google_project_iam_binding" "webapp_logging_binding" {
project = data.google_project.project-id.project_id
role = "roles/logging.admin"
members = [
"serviceAccount:${google_service_account.webapp_instance_service_account.email}"
]
}

resource "google_project_iam_binding" "webapp_monitoring_binding" {
project = data.google_project.project-id.project_id
role = "roles/monitoring.metricWriter"
members = [
"serviceAccount:${google_service_account.webapp_instance_service_account.email}"
]
}

resource "google_compute_instance" "webapp_instance" {
name = var.webapp_instance_name
machine_type = var.webapp_instance_type
zone = var.zone

tags = var.webapp_instance_tags
allow_stopping_for_update = true

service_account {
email = google_service_account.webapp_instance_service_account.email
scopes = ["https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring.write"]
}
boot_disk {
initialize_params {
image = var.webapp_instance_image
Expand Down Expand Up @@ -169,3 +199,17 @@ resource "google_compute_instance" "webapp_instance" {
sudo echo "spring.jpa.hibernate.ddl-auto=update" >> /opt/webapp/application.properties
EOT
}

data "google_dns_managed_zone" "webapp_zone" {
name = "webapp-zone"
}

resource "google_dns_record_set" "zone_instance" {
name = data.google_dns_managed_zone.webapp_zone.dns_name
managed_zone = data.google_dns_managed_zone.webapp_zone.name
type = "A"
ttl = 300
rrdatas = [
google_compute_instance.webapp_instance.network_interface[0].access_config[0].nat_ip
]
}
Loading