Last active
January 23, 2020 18:55
-
-
Save Timtech4u/8fb27a04e33c6b4915729023c38b6c3c to your computer and use it in GitHub Desktop.
Deploy to Cloud Run using Terraform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Configure GCP project | |
provider "google" { | |
project = "terraform-cr" | |
} | |
# Deploy image to Cloud Run | |
resource "google_cloud_run_service" "mywebapp" { | |
name = "mywebapp" | |
location = "us-central1" | |
template { | |
spec { | |
containers { | |
image = "gcr.io/terraform-cr/webapp" | |
} | |
} | |
} | |
traffic { | |
percent = 100 | |
latest_revision = true | |
} | |
} | |
# Create public access | |
data "google_iam_policy" "noauth" { | |
binding { | |
role = "roles/run.invoker" | |
members = [ | |
"allUsers", | |
] | |
} | |
} | |
# Enable public access on Cloud Run service | |
resource "google_cloud_run_service_iam_policy" "noauth" { | |
location = google_cloud_run_service.mywebapp.location | |
project = google_cloud_run_service.mywebapp.project | |
service = google_cloud_run_service.mywebapp.name | |
policy_data = data.google_iam_policy.noauth.policy_data | |
} | |
# Return service URL | |
output "url" { | |
value = "${google_cloud_run_service.mywebapp.status[0].url}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment