google-cloud

Google Cloud Platform: Clojure + {GAE, GCE, anything else on Google Platform}
mozinator2 2020-12-09T08:55:03.054100Z

Hope I am not spamming this channel too much 😉 If so let me know This is my work in progress how I enable google cloud services using babashka instead of terraform

(->>
  (->
    (gc :get (purl :use pid "services") 
        {:query-params {"fields" "services/name,nextPageToken"
                        "filter" "state:ENABLED"}})
    (get :services []))
  (map :name)
  (map #(last (s/split % #"/" )))
  set
  (clojure.set/difference 
    #{"<http://sqladmin.googleapis.com|sqladmin.googleapis.com>"
      "<http://iam.googleapis.com|iam.googleapis.com>"
      "<http://containerregistry.googleapis.com|containerregistry.googleapis.com>"
      "<http://sql-component.googleapis.com|sql-component.googleapis.com>"
      "<http://secretmanager.googleapis.com|secretmanager.googleapis.com>"
      "<http://run.googleapis.com|run.googleapis.com>"
      "<http://cloudbuild.googleapis.com|cloudbuild.googleapis.com>"})
  vec
  (#(when-not (empty? %) 
      (gc :post (purl :use pid "services:batchEnable") {:body {:service-ids %}})))
  (wait-for-operation :use))
and this is how it was in terraform
resource "google_project_service" "service" {
  for_each = toset([
    "<http://run.googleapis.com|run.googleapis.com>", 
    "<http://containerregistry.googleapis.com|containerregistry.googleapis.com>", 
    "<http://cloudbuild.googleapis.com|cloudbuild.googleapis.com>",
    "<http://sql-component.googleapis.com|sql-component.googleapis.com>",
    "<http://sqladmin.googleapis.com|sqladmin.googleapis.com>",
    "<http://secretmanager.googleapis.com|secretmanager.googleapis.com>"
  ])

  service = each.key

  project            = google_project.project.project_id
  disable_on_destroy = false
}
How I do it in babashka/clojure is imperative but written in an idempotent way but I think that a next step could be to have the resources be declared using clojure maps and lists and have it automatically resolve the dependencies and create or update the resources