module GClouder::Resources::Project::Local

Public Class Methods

account_id() click to toggle source
# File lib/gclouder/resources/project.rb, line 79
def self.account_id
  project["account_id"]
end
create_project() click to toggle source
# File lib/gclouder/resources/project.rb, line 37
def self.create_project
  if exists?
    good project_id, indent: 2
    return
  end

  # FIXME: wait for project to exist and apis be enabled before continuing..
  # FIXME: enable compute engine api..

  add project_id, indent: 2
  gcloud("alpha projects create #{project_id} --enable-cloud-apis --name=#{project_id}")

  # FIXME: billing account isn't listed until linked..
  #sleep 0.5 until exists? unless cli_args[:dry_run]
end
ensure() click to toggle source
# File lib/gclouder/resources/project.rb, line 32
def self.ensure
  create_project
  link_project_to_billing_account
end
exists?() click to toggle source
# File lib/gclouder/resources/project.rb, line 67
def self.exists?
  ! project_data(project_id).empty?
end
linked_to_billing_account?() click to toggle source
# File lib/gclouder/resources/project.rb, line 63
def self.linked_to_billing_account?
  project_data(project_id)["billingEnabled"]
end
project_data(project) click to toggle source
# File lib/gclouder/resources/project.rb, line 71
def self.project_data(project)
  shell("gcloud --format json alpha billing accounts projects list #{account_id} | jq '.[] | select(.projectId == \"#{project}\")'")
end
project_id() click to toggle source
# File lib/gclouder/resources/project.rb, line 75
def self.project_id
  project["project_id"]
end