Module: GClouder::Resources::Project::Local
Class Method Summary
collapse
check, #cli_args, cli_args, included, load, valid_resources
Methods included from GCloud
#gcloud, included, #verify
load, #project, project
Methods included from Helpers
#hash_to_args, included, #module_exists?, #to_arg, #to_deep_merge_hash, #valid_json?
Methods included from Logging
#add, #bad, #change, #debug, #error, #fatal, #good, included, #info, log, loggers, #remove, report, #resource_state, setup, #warn, #warning
Methods included from Shell
included, #shell
Class Method Details
.account_id ⇒ Object
79
80
81
|
# File 'lib/gclouder/resources/project.rb', line 79
def self.account_id
project["account_id"]
end
|
.create_project ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/gclouder/resources/project.rb', line 37
def self.create_project
if exists?
good project_id, indent: 2
return
end
add project_id, indent: 2
gcloud("alpha projects create #{project_id} --enable-cloud-apis --name=#{project_id}")
end
|
.ensure ⇒ Object
32
33
34
35
|
# File 'lib/gclouder/resources/project.rb', line 32
def self.ensure
create_project
link_project_to_billing_account
end
|
67
68
69
|
# File 'lib/gclouder/resources/project.rb', line 67
def self.exists?
! project_data(project_id).empty?
end
|
.link_project_to_billing_account ⇒ Object
53
54
55
56
57
58
59
60
61
|
# File 'lib/gclouder/resources/project.rb', line 53
def self.link_project_to_billing_account
if linked_to_billing_account?
good "linked to billing account: #{account_id}", indent: 3
return
end
add "link to billing account: #{account_id}", indent: 3
gcloud("alpha billing accounts projects link #{project_id} --account-id=#{account_id}")
end
|
.linked_to_billing_account? ⇒ Boolean
63
64
65
|
# File 'lib/gclouder/resources/project.rb', line 63
def self.linked_to_billing_account?
project_data(project_id)["billingEnabled"]
end
|
.project_data(project) ⇒ Object
71
72
73
|
# 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 ⇒ Object
75
76
77
|
# File 'lib/gclouder/resources/project.rb', line 75
def self.project_id
project["project_id"]
end
|