cloud-mu 3.2.0 → 3.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +1 -1
  3. data/ansible/roles/mu-nat/tasks/main.yml +3 -0
  4. data/bin/mu-adopt +12 -1
  5. data/bin/mu-aws-setup +41 -7
  6. data/bin/mu-azure-setup +34 -0
  7. data/bin/mu-configure +214 -119
  8. data/bin/mu-gcp-setup +37 -2
  9. data/bin/mu-load-config.rb +2 -1
  10. data/bin/mu-node-manage +3 -0
  11. data/bin/mu-refresh-ssl +67 -0
  12. data/bin/mu-run-tests +28 -6
  13. data/bin/mu-self-update +30 -10
  14. data/bin/mu-upload-chef-artifacts +30 -26
  15. data/cloud-mu.gemspec +10 -8
  16. data/cookbooks/mu-master/attributes/default.rb +5 -1
  17. data/cookbooks/mu-master/metadata.rb +2 -2
  18. data/cookbooks/mu-master/recipes/default.rb +81 -26
  19. data/cookbooks/mu-master/recipes/init.rb +197 -62
  20. data/cookbooks/mu-master/recipes/update_nagios_only.rb +1 -1
  21. data/cookbooks/mu-master/recipes/vault.rb +78 -77
  22. data/cookbooks/mu-master/templates/default/mods/rewrite.conf.erb +1 -0
  23. data/cookbooks/mu-master/templates/default/nagios.conf.erb +103 -0
  24. data/cookbooks/mu-master/templates/default/web_app.conf.erb +14 -30
  25. data/cookbooks/mu-tools/attributes/default.rb +12 -0
  26. data/cookbooks/mu-tools/files/centos-6/CentOS-Base.repo +47 -0
  27. data/cookbooks/mu-tools/libraries/helper.rb +98 -4
  28. data/cookbooks/mu-tools/libraries/monkey.rb +1 -1
  29. data/cookbooks/mu-tools/recipes/apply_security.rb +31 -9
  30. data/cookbooks/mu-tools/recipes/aws_api.rb +8 -2
  31. data/cookbooks/mu-tools/recipes/base_repositories.rb +1 -1
  32. data/cookbooks/mu-tools/recipes/gcloud.rb +2 -9
  33. data/cookbooks/mu-tools/recipes/google_api.rb +7 -0
  34. data/cookbooks/mu-tools/recipes/rsyslog.rb +8 -1
  35. data/cookbooks/mu-tools/resources/disk.rb +113 -42
  36. data/cookbooks/mu-tools/resources/mommacat_request.rb +1 -2
  37. data/cookbooks/mu-tools/templates/centos-8/sshd_config.erb +215 -0
  38. data/extras/Gemfile.lock.bootstrap +394 -0
  39. data/extras/bucketstubs/error.html +0 -0
  40. data/extras/bucketstubs/index.html +0 -0
  41. data/extras/clean-stock-amis +11 -3
  42. data/extras/generate-stock-images +6 -3
  43. data/extras/git_rpm/build.sh +20 -0
  44. data/extras/git_rpm/mugit.spec +53 -0
  45. data/extras/image-generators/AWS/centos7.yaml +19 -16
  46. data/extras/image-generators/AWS/{rhel7.yaml → rhel71.yaml} +0 -0
  47. data/extras/image-generators/AWS/{win2k12.yaml → win2k12r2.yaml} +0 -0
  48. data/extras/image-generators/VMWare/centos8.yaml +15 -0
  49. data/extras/openssl_rpm/build.sh +19 -0
  50. data/extras/openssl_rpm/mussl.spec +46 -0
  51. data/extras/python_rpm/muthon.spec +14 -4
  52. data/extras/ruby_rpm/muby.spec +9 -5
  53. data/extras/sqlite_rpm/build.sh +19 -0
  54. data/extras/sqlite_rpm/muqlite.spec +47 -0
  55. data/install/installer +7 -5
  56. data/modules/mommacat.ru +2 -2
  57. data/modules/mu.rb +14 -7
  58. data/modules/mu/adoption.rb +5 -5
  59. data/modules/mu/cleanup.rb +47 -25
  60. data/modules/mu/cloud.rb +29 -1
  61. data/modules/mu/cloud/dnszone.rb +0 -2
  62. data/modules/mu/cloud/machine_images.rb +1 -1
  63. data/modules/mu/cloud/providers.rb +6 -1
  64. data/modules/mu/cloud/resource_base.rb +16 -7
  65. data/modules/mu/cloud/ssh_sessions.rb +5 -1
  66. data/modules/mu/cloud/wrappers.rb +20 -7
  67. data/modules/mu/config.rb +28 -12
  68. data/modules/mu/config/bucket.rb +31 -2
  69. data/modules/mu/config/cache_cluster.rb +1 -1
  70. data/modules/mu/config/cdn.rb +100 -0
  71. data/modules/mu/config/container_cluster.rb +1 -1
  72. data/modules/mu/config/database.rb +3 -3
  73. data/modules/mu/config/dnszone.rb +4 -3
  74. data/modules/mu/config/endpoint.rb +1 -0
  75. data/modules/mu/config/firewall_rule.rb +1 -1
  76. data/modules/mu/config/function.rb +16 -7
  77. data/modules/mu/config/job.rb +89 -0
  78. data/modules/mu/config/notifier.rb +7 -18
  79. data/modules/mu/config/ref.rb +55 -9
  80. data/modules/mu/config/schema_helpers.rb +12 -3
  81. data/modules/mu/config/server.rb +11 -5
  82. data/modules/mu/config/server_pool.rb +2 -2
  83. data/modules/mu/config/vpc.rb +11 -10
  84. data/modules/mu/defaults/AWS.yaml +106 -106
  85. data/modules/mu/deploy.rb +40 -14
  86. data/modules/mu/groomers/chef.rb +2 -2
  87. data/modules/mu/master.rb +70 -3
  88. data/modules/mu/mommacat.rb +28 -9
  89. data/modules/mu/mommacat/daemon.rb +13 -7
  90. data/modules/mu/mommacat/naming.rb +2 -2
  91. data/modules/mu/mommacat/search.rb +16 -5
  92. data/modules/mu/mommacat/storage.rb +67 -32
  93. data/modules/mu/providers/aws.rb +298 -85
  94. data/modules/mu/providers/aws/alarm.rb +5 -5
  95. data/modules/mu/providers/aws/bucket.rb +284 -50
  96. data/modules/mu/providers/aws/cache_cluster.rb +26 -26
  97. data/modules/mu/providers/aws/cdn.rb +782 -0
  98. data/modules/mu/providers/aws/collection.rb +16 -16
  99. data/modules/mu/providers/aws/container_cluster.rb +84 -64
  100. data/modules/mu/providers/aws/database.rb +59 -55
  101. data/modules/mu/providers/aws/dnszone.rb +29 -12
  102. data/modules/mu/providers/aws/endpoint.rb +535 -50
  103. data/modules/mu/providers/aws/firewall_rule.rb +32 -26
  104. data/modules/mu/providers/aws/folder.rb +1 -1
  105. data/modules/mu/providers/aws/function.rb +300 -134
  106. data/modules/mu/providers/aws/group.rb +16 -14
  107. data/modules/mu/providers/aws/habitat.rb +4 -4
  108. data/modules/mu/providers/aws/job.rb +469 -0
  109. data/modules/mu/providers/aws/loadbalancer.rb +67 -45
  110. data/modules/mu/providers/aws/log.rb +17 -17
  111. data/modules/mu/providers/aws/msg_queue.rb +22 -13
  112. data/modules/mu/providers/aws/nosqldb.rb +99 -8
  113. data/modules/mu/providers/aws/notifier.rb +137 -65
  114. data/modules/mu/providers/aws/role.rb +119 -83
  115. data/modules/mu/providers/aws/search_domain.rb +166 -30
  116. data/modules/mu/providers/aws/server.rb +209 -118
  117. data/modules/mu/providers/aws/server_pool.rb +95 -130
  118. data/modules/mu/providers/aws/storage_pool.rb +19 -11
  119. data/modules/mu/providers/aws/user.rb +5 -5
  120. data/modules/mu/providers/aws/userdata/linux.erb +5 -4
  121. data/modules/mu/providers/aws/vpc.rb +109 -54
  122. data/modules/mu/providers/aws/vpc_subnet.rb +43 -39
  123. data/modules/mu/providers/azure.rb +78 -12
  124. data/modules/mu/providers/azure/server.rb +20 -4
  125. data/modules/mu/providers/cloudformation/server.rb +1 -1
  126. data/modules/mu/providers/google.rb +21 -5
  127. data/modules/mu/providers/google/bucket.rb +1 -1
  128. data/modules/mu/providers/google/container_cluster.rb +1 -1
  129. data/modules/mu/providers/google/database.rb +1 -1
  130. data/modules/mu/providers/google/firewall_rule.rb +1 -1
  131. data/modules/mu/providers/google/folder.rb +7 -3
  132. data/modules/mu/providers/google/function.rb +66 -31
  133. data/modules/mu/providers/google/group.rb +1 -1
  134. data/modules/mu/providers/google/habitat.rb +1 -1
  135. data/modules/mu/providers/google/loadbalancer.rb +1 -1
  136. data/modules/mu/providers/google/role.rb +6 -3
  137. data/modules/mu/providers/google/server.rb +1 -1
  138. data/modules/mu/providers/google/server_pool.rb +1 -1
  139. data/modules/mu/providers/google/user.rb +1 -1
  140. data/modules/mu/providers/google/vpc.rb +28 -3
  141. data/modules/tests/aws-jobs-functions.yaml +46 -0
  142. data/modules/tests/aws-servers-with-handrolled-iam.yaml +37 -0
  143. data/modules/tests/centos6.yaml +4 -0
  144. data/modules/tests/centos7.yaml +4 -0
  145. data/modules/tests/ecs.yaml +2 -2
  146. data/modules/tests/eks.yaml +1 -1
  147. data/modules/tests/functions/node-function/lambda_function.js +10 -0
  148. data/modules/tests/functions/python-function/lambda_function.py +12 -0
  149. data/modules/tests/k8s.yaml +1 -1
  150. data/modules/tests/microservice_app.yaml +288 -0
  151. data/modules/tests/rds.yaml +5 -5
  152. data/modules/tests/regrooms/rds.yaml +5 -5
  153. data/modules/tests/server-with-scrub-muisms.yaml +1 -1
  154. data/modules/tests/super_complex_bok.yml +2 -2
  155. data/modules/tests/super_simple_bok.yml +2 -2
  156. metadata +42 -17
@@ -144,7 +144,7 @@ module MU
144
144
  # @param noop [Boolean]: If true, will only print what would be done
145
145
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
146
146
  # @return [void]
147
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
147
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
148
148
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
149
149
 
150
150
  resp = MU::Cloud::Google.storage(credentials: credentials).list_buckets(flags['habitat'])
@@ -744,7 +744,7 @@ module MU
744
744
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
745
745
  # @param region [String]: The cloud provider region in which to operate
746
746
  # @return [void]
747
- def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
747
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
748
748
 
749
749
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
750
750
  return if !MU::Cloud.resourceClass("Google", "Habitat").isLive?(flags["habitat"], credentials)
@@ -100,7 +100,7 @@ module MU
100
100
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
101
101
  # @param region [String]: The cloud provider region in which to operate
102
102
  # @return [void]
103
- def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
103
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
104
104
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
105
105
 
106
106
  # instances = MU::Cloud::Google.sql(credentials: credentials).list_instances(flags['habitat'], filter: %Q{userLabels.mu-id:"#{MU.deploy_id.downcase}"})
@@ -207,7 +207,7 @@ end
207
207
  # @param noop [Boolean]: If true, will only print what would be done
208
208
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
209
209
  # @return [void]
210
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
210
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
211
211
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
212
212
  return if !MU::Cloud.resourceClass("Google", "Habitat").isLive?(flags["habitat"], credentials)
213
213
  filter = %Q{(labels.mu-id = "#{MU.deploy_id.downcase}")}
@@ -162,7 +162,7 @@ module MU
162
162
  # @param noop [Boolean]: If true, will only print what would be done
163
163
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
164
164
  # @return [void]
165
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
165
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
166
166
  filter = %Q{(labels.mu-id = "#{MU.deploy_id.downcase}")}
167
167
  if !ignoremaster and MU.mu_public_ip
168
168
  filter += %Q{ AND (labels.mu-master-ip = "#{MU.mu_public_ip.gsub(/\./, "_")}")}
@@ -265,8 +265,12 @@ module MU
265
265
 
266
266
  if args[:cloud_id]
267
267
  raw_id = args[:cloud_id].sub(/^folders\//, "")
268
- resp = MU::Cloud::Google.folder(credentials: args[:credentials]).get_folder("folders/"+raw_id)
269
- found[resp.name] = resp if resp
268
+ begin
269
+ resp = MU::Cloud::Google.folder(credentials: args[:credentials]).get_folder("folders/"+raw_id)
270
+ found[resp.name] = resp if resp
271
+ rescue ::Google::Apis::ClientError => e
272
+ raise e if e.message !~ /forbidden: /
273
+ end
270
274
 
271
275
  elsif args[:flags] and args[:flags]['display_name']
272
276
 
@@ -119,6 +119,9 @@ module example.com/cloudfunction
119
119
  # Called automatically by {MU::Deploy#createResources}
120
120
  def groom
121
121
  desc = {}
122
+
123
+ func_obj = buildDesc
124
+
122
125
  labels = Hash[@tags.keys.map { |k|
123
126
  [k.downcase, @tags[k].downcase.gsub(/[^-_a-z0-9]/, '-')] }
124
127
  ]
@@ -140,6 +143,10 @@ module example.com/cloudfunction
140
143
  if cloud_desc.available_memory_mb != @config['memory']
141
144
  need_update = true
142
145
  end
146
+ if cloud_desc.service_account_email != func_obj.service_account_email
147
+ need_update = true
148
+ end
149
+
143
150
  if @config['environment_variable']
144
151
  @config['environment_variable'].each { |var|
145
152
  if !cloud_desc.environment_variables or
@@ -161,7 +168,17 @@ module example.com/cloudfunction
161
168
  File.read("#{dir}/current.zip")
162
169
  }
163
170
 
164
- new = if @config['code']['zip_file']
171
+ tempfile = nil
172
+ new = if @config['code']['zip_file'] or @config['code']['path']
173
+ if @config['code']['path']
174
+ tempfile = Tempfile.new(["function", ".zip"])
175
+ MU.log "#{@mu_name} using code at #{@config['code']['path']}"
176
+ MU::Master.zipDir(@config['code']['path'], tempfile.path)
177
+ @config['code']['zip_file'] = tempfile.path
178
+ else
179
+ MU.log "#{@mu_name} using code packaged at #{@config['code']['zip_file']}"
180
+ end
181
+ # @code_sha256 = Base64.encode64(Digest::SHA256.digest(zip)).chomp
165
182
  File.read(@config['code']['zip_file'])
166
183
  elsif @config['code']['gs_url']
167
184
  @config['code']['gs_url'].match(/^gs:\/\/([^\/]+)\/(.*)/)
@@ -172,25 +189,31 @@ module example.com/cloudfunction
172
189
  File.read(dir+"/new.zip")
173
190
  }
174
191
  end
192
+
175
193
  if @config['code']['gs_url'] and
176
194
  (@config['code']['gs_url'] != cloud_desc.source_archive_url or
177
195
  current != new)
178
196
  need_update = true
179
- elsif @config['code']['zip_file'] and current != new
197
+ elsif (@config['code']['zip_file'] or @config['code']['path']) and current != new
180
198
  need_update = true
181
- desc[:source_archive_url] = MU::Cloud::Google::Function.uploadPackage(@config['code']['zip_file'], @mu_name+"-cloudfunction.zip", credentials: @credentials)
199
+ end
200
+
201
+ if @config['vpc_connector']
202
+ if cloud_desc.vpc_connector != @config['vpc_connector'] or
203
+ cloud_desc.vpc_connector_egress_settings != (@config['vpc_connector_allow_all_egress'] ? "ALL_TRAFFIC" : "PRIVATE_RANGES_ONLY")
204
+ need_update = true
205
+ end
182
206
  end
183
207
 
184
208
  if need_update
185
- func_obj = buildDesc
186
- MU.log "Updating Cloud Function #{@mu_name}", MU::NOTICE, details: func_obj
209
+ MU.log "Updating Cloud Function #{@cloud_id}", MU::NOTICE, details: func_obj
187
210
  begin
188
- # MU::Cloud::Google.function(credentials: @credentials).patch_project_location_function(
189
- # @cloud_id,
190
- # func_obj
191
- # )
192
- rescue ::Google::Apis::ClientError
193
- MU.log "Error updating Cloud Function #{@mu_name}.", MU::ERR
211
+ MU::Cloud::Google.function(credentials: @credentials).patch_project_location_function(
212
+ @cloud_id,
213
+ func_obj
214
+ )
215
+ rescue ::Google::Apis::ClientError => e
216
+ MU.log "Error updating Cloud Function #{@mu_name}.", MU::ERR, e.message
194
217
  if desc[:source_archive_url]
195
218
  main_file = nil
196
219
  HELLO_WORLDS.each_pair { |runtime, code|
@@ -207,6 +230,11 @@ module example.com/cloudfunction
207
230
  # service_account_email: sa.kitten.cloud_desc.email,
208
231
  # labels: labels,
209
232
 
233
+ if tempfile
234
+ tempfile.close
235
+ tempfile.unlink
236
+ end
237
+
210
238
  end
211
239
 
212
240
  # Return the metadata for this project's configuration
@@ -233,7 +261,7 @@ module example.com/cloudfunction
233
261
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
234
262
  # @param region [String]: The cloud provider region
235
263
  # @return [void]
236
- def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
264
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
237
265
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
238
266
  return if !MU::Cloud.resourceClass("Google", "Habitat").isLive?(flags["habitat"], credentials)
239
267
  # Make sure we catch regional *and* zone functions
@@ -354,6 +382,7 @@ module example.com/cloudfunction
354
382
  def self.schema(config)
355
383
  toplevel_required = ["runtime"]
356
384
  schema = {
385
+ "roles" => MU::Cloud.resourceClass("Google", "User").schema(config)[1]["roles"],
357
386
  "triggers" => {
358
387
  "type" => "array",
359
388
  "items" => {
@@ -448,6 +477,7 @@ module example.com/cloudfunction
448
477
  content_type: "application/zip",
449
478
  name: filename
450
479
  )
480
+
451
481
  MU::Cloud::Google.storage(credentials: credentials).insert_object(
452
482
  bucket,
453
483
  obj_obj,
@@ -487,7 +517,7 @@ module example.com/cloudfunction
487
517
  end
488
518
  # XXX list_project_locations
489
519
 
490
- if !function['code'] or (!function['code']['zip_file'] and !function['code']['gs_url'])
520
+ if !function['code'] or (!function['code']['zip_file'] and !function['code']['gs_url'] and !function['code']['path'])
491
521
  MU.log "Must specify a code source in Cloud Function #{function['name']}", MU::ERR
492
522
  ok = false
493
523
  elsif function['code']['zip_file']
@@ -557,22 +587,14 @@ module example.com/cloudfunction
557
587
 
558
588
  location = "projects/"+@config['project']+"/locations/"+@config['region']
559
589
  sa = nil
560
- retries = 0
561
- begin
562
- sa_ref = MU::Config::Ref.get(@config['service_account'])
563
- sa = @deploy.findLitterMate(name: sa_ref.name, type: "users")
564
- if !sa or !sa.cloud_desc
565
- sleep 10
566
- end
567
- rescue ::Google::Apis::ClientError => e
568
- if e.message.match(/notFound:/)
569
- sleep 10
570
- retries += 1
571
- retry
572
- end
573
- end while !sa or !sa.cloud_desc and retries < 5
590
+ need_sa = Proc.new {
591
+ !sa or !sa.kitten or !sa.kitten.cloud_desc
592
+ }
593
+ MU.retrier(loop_if: need_sa, wait: 10, max: 6) { |retries, _wait|
594
+ sa = MU::Config::Ref.get(@config['service_account'])
595
+ }
574
596
 
575
- if !sa or !sa.cloud_desc
597
+ if need_sa.call()
576
598
  raise MuError, "Failed to get service account cloud id from #{@config['service_account'].to_s}"
577
599
  end
578
600
 
@@ -583,7 +605,7 @@ module example.com/cloudfunction
583
605
  # entry_point: "hello_world",
584
606
  entry_point: @config['handler'],
585
607
  description: @deploy.deploy_id,
586
- service_account_email: sa.cloud_desc.email,
608
+ service_account_email: sa.kitten.cloud_desc.email,
587
609
  labels: labels,
588
610
  available_memory_mb: @config['memory']
589
611
  }
@@ -596,7 +618,6 @@ module example.com/cloudfunction
596
618
  if @config['vpc_connector']
597
619
  desc[:vpc_connector] = @config['vpc_connector']
598
620
  desc[:vpc_connector_egress_settings] = @config['vpc_connector_allow_all_egress'] ? "ALL_TRAFFIC" : "PRIVATE_RANGES_ONLY"
599
- pp desc
600
621
  elsif @vpc
601
622
  desc[:network] = @vpc.url.sub(/^.*?\/projects\//, 'projects/')
602
623
  end
@@ -627,8 +648,22 @@ module example.com/cloudfunction
627
648
  # }
628
649
  if @config['code']['gs_url']
629
650
  desc[:source_archive_url] = @config['code']['gs_url']
630
- elsif @config['code']['zip_file']
651
+ elsif @config['code']['zip_file'] or @config['code']['path']
652
+ tempfile = nil
653
+ if @config['code']['path']
654
+ tempfile = Tempfile.new(["function", ".zip"])
655
+ MU.log "#{@mu_name} using code at #{@config['code']['path']}"
656
+ MU::Master.zipDir(@config['code']['path'], tempfile.path)
657
+ @config['code']['zip_file'] = tempfile.path
658
+ else
659
+ MU.log "#{@mu_name} using code packaged at #{@config['code']['zip_file']}"
660
+ end
631
661
  desc[:source_archive_url] = MU::Cloud::Google::Function.uploadPackage(@config['code']['zip_file'], @mu_name+"-cloudfunction.zip", credentials: @credentials)
662
+
663
+ if tempfile
664
+ tempfile.close
665
+ tempfile.unlink
666
+ end
632
667
  end
633
668
 
634
669
  # Dir.mktmpdir(@mu_name) { |dir|
@@ -140,7 +140,7 @@ module MU
140
140
  # @param noop [Boolean]: If true, will only print what would be done
141
141
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
142
142
  # @return [void]
143
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
143
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
144
144
  MU::Cloud::Google.getDomains(credentials)
145
145
  my_org = MU::Cloud::Google.getOrg(credentials)
146
146
 
@@ -222,7 +222,7 @@ module MU
222
222
  # @param noop [Boolean]: If true, will only print what would be done
223
223
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
224
224
  # @return [void]
225
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
225
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
226
226
  resp = MU::Cloud::Google.resource_manager(credentials: credentials).list_projects
227
227
 
228
228
  if resp and resp.projects
@@ -146,7 +146,7 @@ module MU
146
146
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
147
147
  # @param region [String]: The cloud provider region
148
148
  # @return [void]
149
- def self.cleanup(noop: false, ignoremaster: false, region: nil, credentials: nil, flags: {})
149
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: nil, credentials: nil, flags: {})
150
150
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
151
151
  return if !MU::Cloud.resourceClass("Google", "Habitat").isLive?(flags["habitat"], credentials)
152
152
  filter = %Q{(labels.mu-id = "#{MU.deploy_id.downcase}")}
@@ -465,7 +465,7 @@ module MU
465
465
  # @param noop [Boolean]: If true, will only print what would be done
466
466
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
467
467
  # @return [void]
468
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
468
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
469
469
  customer = MU::Cloud::Google.customerID(credentials)
470
470
  my_org = MU::Cloud::Google.getOrg(credentials)
471
471
 
@@ -581,7 +581,7 @@ module MU
581
581
  }
582
582
  end
583
583
  if args[:cloud_id]
584
- found.reject! { |k, _v| k != role.name }
584
+ found.reject! { |k, _v| k != args[:cloud_id] }
585
585
  end
586
586
 
587
587
  # Now go get everything that's bound here
@@ -745,6 +745,7 @@ module MU
745
745
  end
746
746
 
747
747
  entity_types.each_pair { |entity_type, entities|
748
+ next if entity_type == "deleted"
748
749
  mu_entitytype = (entity_type == "serviceAccount" ? "user" : entity_type)+"s"
749
750
  entities.each { |entity|
750
751
  next if entity.nil?
@@ -925,7 +926,9 @@ module MU
925
926
  }
926
927
 
927
928
  MU::Cloud.resourceClass("Google", "Folder").find(credentials: credentials).keys.each { |folder|
928
- MU::Cloud.resourceClass("Google", "Folder").bindings(folder, credentials: credentials).each { |binding|
929
+ folder_bindings = MU::Cloud.resourceClass("Google", "Folder").bindings(folder, credentials: credentials)
930
+ next if !folder_bindings
931
+ folder_bindings.each { |binding|
929
932
  insertBinding("folders", folder, binding)
930
933
  }
931
934
  }
@@ -1290,7 +1290,7 @@ next if !create
1290
1290
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
1291
1291
  # @param region [String]: The cloud provider region
1292
1292
  # @return [void]
1293
- def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
1293
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
1294
1294
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
1295
1295
  return if !MU::Cloud.resourceClass("Google", "Habitat").isLive?(flags["habitat"], credentials)
1296
1296
 
@@ -431,7 +431,7 @@ end
431
431
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
432
432
  # @param region [String]: The cloud provider region
433
433
  # @return [void]
434
- def self.cleanup(noop: false, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
434
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, region: MU.curRegion, credentials: nil, flags: {})
435
435
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
436
436
  return if !MU::Cloud.resourceClass("Google", "Habitat").isLive?(flags["habitat"], credentials)
437
437
  filter = %Q{(labels.mu-id = "#{MU.deploy_id.downcase}")}
@@ -254,7 +254,7 @@ module MU
254
254
  # @param noop [Boolean]: If true, will only print what would be done
255
255
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
256
256
  # @return [void]
257
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
257
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
258
258
  MU::Cloud::Google.getDomains(credentials)
259
259
  my_org = MU::Cloud::Google.getOrg(credentials)
260
260
 
@@ -364,6 +364,12 @@ end
364
364
  }
365
365
  end
366
366
 
367
+
368
+ # The API is filled with lies
369
+ @subnets.reject! { |s|
370
+ !MU::Cloud::Google.listRegions(credentials: @credentials).include?(s.az)
371
+ }
372
+
367
373
  return @subnets
368
374
  end
369
375
 
@@ -442,14 +448,19 @@ end
442
448
 
443
449
  # Check for a subnet in this VPC matching one or more of the specified
444
450
  # criteria, and return it if found.
445
- def getSubnet(cloud_id: nil, name: nil, tag_key: nil, tag_value: nil, ip_block: nil, region: nil)
451
+ def getSubnet(cloud_id: nil, name: nil, tag_key: nil, tag_value: nil, ip_block: nil, region: nil, subnet_mu_name: nil)
446
452
  if !cloud_id.nil? and cloud_id.match(/^https:\/\//)
447
453
  cloud_id.match(/\/regions\/([^\/]+)\/subnetworks\/([^\/]+)$/)
448
454
  region = Regexp.last_match[1]
449
455
  cloud_id = Regexp.last_match[2]
450
456
  cloud_id.gsub!(/.*?\//, "")
451
457
  end
452
- MU.log "getSubnet(cloud_id: #{cloud_id}, name: #{name}, tag_key: #{tag_key}, tag_value: #{tag_value}, ip_block: #{ip_block}, region: #{region})", MU::DEBUG, details: caller[0]
458
+
459
+ if name
460
+ subnet_mu_name ||= @config['scrub_mu_isms'] ? @cloud_id+name.downcase : MU::Cloud::Google.nameStr(@deploy.getResourceName(name, max_length: 61))
461
+ end
462
+
463
+ MU.log "getSubnet(cloud_id: #{cloud_id}, name: #{name}, tag_key: #{tag_key}, tag_value: #{tag_value}, ip_block: #{ip_block}, region: #{region}, subnet_mu_name: #{subnet_mu_name})", MU::DEBUG, details: caller[0]
453
464
  subnets.each { |subnet|
454
465
  next if region and subnet.az != region
455
466
  if !cloud_id.nil? and !subnet.cloud_id.nil? and subnet.cloud_id.to_s == cloud_id.to_s
@@ -457,6 +468,9 @@ end
457
468
  elsif !name.nil? and !subnet.name.nil? and
458
469
  subnet.name.downcase.to_s == name.downcase.to_s
459
470
  return subnet
471
+ elsif !subnet_mu_name.nil? and !subnet.name.nil? and
472
+ subnet.name.downcase.to_s == subnet_mu_name.downcase.to_s
473
+ return subnet
460
474
  end
461
475
  }
462
476
  return nil
@@ -537,7 +551,7 @@ MU.log "ROUTES TO #{target_instance.name}", MU::WARN, details: resp
537
551
  # @param noop [Boolean]: If true, will only print what would be done
538
552
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
539
553
  # @return [void]
540
- def self.cleanup(noop: false, ignoremaster: false, credentials: nil, flags: {})
554
+ def self.cleanup(noop: false, deploy_id: MU.deploy_id, ignoremaster: false, credentials: nil, flags: {})
541
555
  flags["habitat"] ||= MU::Cloud::Google.defaultProject(credentials)
542
556
  return if !MU::Cloud.resourceClass("Google", "Habitat").isLive?(flags["habitat"], credentials)
543
557
  filter = %Q{(labels.mu-id = "#{MU.deploy_id.downcase}")}
@@ -931,6 +945,14 @@ MU.log "ROUTES TO #{target_instance.name}", MU::WARN, details: resp
931
945
  else
932
946
  route['nat_host_name'] = nat['name']
933
947
  route['priority'] = 100
948
+ MU::Config.addDependency(vpc, nat['name'], "server", their_phase: "groom", my_phase: "groom")
949
+ vpc["bastion"] = MU::Config::Ref.get(
950
+ name: nat['name'],
951
+ cloud: vpc['cloud'],
952
+ credentials: vpc['credentials'],
953
+ type: "servers"
954
+ )
955
+
934
956
  end
935
957
  end
936
958
  }
@@ -1172,6 +1194,9 @@ MU.log "ROUTES TO #{target_instance.name}", MU::WARN, details: resp
1172
1194
  if e.message.match(/notFound: /)
1173
1195
  MU.log "Failed to fetch cloud description for Google subnet #{@cloud_id}", MU::WARN, details: { "project" => @parent.habitat_id, "region" => @az, "name" => @cloud_id }
1174
1196
  return nil
1197
+ elsif e.message.match(/Unknown region\. /)
1198
+ MU.log "Google subnet #{@cloud_id} seems like it should live in #{@az}, but that's not a valid region", MU::WARN, details: { "project" => @parent.habitat_id, "region" => @az, "name" => @cloud_id }
1199
+ return nil
1175
1200
  else
1176
1201
  raise e
1177
1202
  end
@@ -0,0 +1,46 @@
1
+ # clouds: AWS
2
+ ---
3
+ appname: smoketest
4
+ jobs:
5
+ - name: event1
6
+ schedule:
7
+ minute: '0'
8
+ hour: '1'
9
+ day_of_month: '1'
10
+ month: "*"
11
+ day_of_week: "?"
12
+ year: "*"
13
+ targets:
14
+ - type: functions
15
+ name: python-function
16
+ - name: event2
17
+ disabled: true
18
+ schedule:
19
+ minute: '0'
20
+ hour: '2'
21
+ day_of_month: '1'
22
+ month: "*"
23
+ day_of_week: "?"
24
+ year: "*"
25
+ targets:
26
+ - type: functions
27
+ name: node-function
28
+
29
+ functions:
30
+ - name: python-function
31
+ handler: lambda_function.lambda_handler
32
+ memory: 128
33
+ runtime: python3.6
34
+ timeout: 300
35
+ code:
36
+ path: functions/python-function
37
+ environment_variable:
38
+ - key: foo
39
+ value: bar
40
+ - name: node-function
41
+ runtime: nodejs12.x
42
+ handler: lambda_function.lambda_handler
43
+ memory: 256
44
+ timeout: 60
45
+ code:
46
+ path: functions/node-function