GoogleCloudPlatform / cloud-run-button

Let anyone deploy your GitHub repos to Google Cloud Run with a single click
https://cloud.run
Apache License 2.0
527 stars 92 forks source link

Provisioning resources via Terraform #137

Closed steren closed 3 years ago

steren commented 4 years ago

I wish the "Run on Google Cloud" allowed me to provision and configure GCP resources in a declarative way, and using a Terraform template seem very appropriate.

Take the example of https://github.com/sethvargo/gcr-cleaner: it needs 2 service accounts, some specific IAM permissions, one Cloud Run service, one Cloud Scheduler job. This could be done via a sequence of gcloud commands, but it could also be done using Terraform.

ahmetb commented 4 years ago

It should be doable already. Just ship terraform files in the repo and run terraform via pre/post-create hook since terraform already exists in Cloud Shell image.

The only part we currently don't support is that we don't yet allow customization of service account of Cloud Run service. (But it still can be done with a post-hook.). But it's on our list.

steren commented 4 years ago

Great, my suggestion is to document this more "officially"

ahmetb commented 4 years ago

We talk about hooks in the readme but since Terraform isn’t exactly a common case, we might add an “Example Repo with Terraform” link next to the hooks description.

tomlarkworthy commented 4 years ago

I tried it out: https://github.com/boardingparty/backend_gcp One issue is that the button assumes you want to standup a Cloud Run service, when in the case of running terraform we don't (its a batch process). I just let it fail out. Still! I like the idea a lot.

UPDATE: You need the CR deployment in order to remember the env variables in the app.json

tomlarkworthy commented 4 years ago

This is cool:- https://github.com/boardingparty/minecraft_gcp

jamesward commented 4 years ago

Woah! Nice work!

ahmetb commented 4 years ago

@tomlarkworthy it seems like it's not really deploying a Cloud Run app? so that could be a little weird/odd for your users. Have you thought about directly integrating with Open in Cloud Shell?

jamesward commented 4 years ago

We should look further into a generalized "Cloud Shell Button" that can be used for non-Cloud Run use cases. :)

tomlarkworthy commented 4 years ago

Yes the cloud run button image is a bit misleading, should be Run in Cloud Shell really. I could change the graphic on the button, but Google supplied that one. Another option would be my own "Boarding Party" one.

I have no users, this was just fooling around, but it worked out so I will try promoting next weeks or so. I am open to suggestions on what you think the graphic should be. The current Cloud Run button promotes your source engineering better so maybe you prefer keeping it as is? I am ambivalent and open to suggestions.

I think this exercise shows a more generalised Button is very useful. Terraform is such a great tool. Cloud run is awesome, but it's usually just 1 thing inside are larger organism (database, reverse proxy, pubsub, cloud scheduler etc.) The Cloud Run buttons scope is too narrow, you can't build rich apps in a single stateless container, it's UX power is limited. With Terraform you can provision everything, even stuff on 3rd party services (e.g. GitHub hooks, imaging adding CD via a merge)!

steren commented 4 years ago

The button says "Run on Google Cloud", it does not say "Deploy to Google Cloud Run".

So the button is 100% compatible with deploying o other places than Cloud Run. I always imagined that the button would be able to do more than Cloud Run deployments.

ahmetb commented 3 years ago

Terraform does not fit here because you need to store a ".tfstate" file long-term to be able to re-deploy it the second (or more) time. It won’t work well with the model we have.

tomlarkworthy commented 3 years ago

you put terraform state in a storage bucket (https://github.com/boardingparty/minecraft_gcp/blob/master/boardingparty/install/sync#L5). By all means close because you don't want to put resources into it, but your reasoning as written isn't idiomatic Terraform.

"This state is stored by default in a local file named "terraform.tfstate", but it can also be stored remotely, which works better in a team environment." -- https://www.terraform.io/docs/state/index.html