cloud-mu 1.9.0.pre.beta → 2.0.0.pre.alpha

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/Berksfile +16 -54
  3. data/Berksfile.lock +14 -62
  4. data/bin/mu-aws-setup +131 -108
  5. data/bin/mu-configure +311 -74
  6. data/bin/mu-gcp-setup +84 -62
  7. data/bin/mu-load-config.rb +46 -2
  8. data/bin/mu-self-update +11 -9
  9. data/bin/mu-upload-chef-artifacts +4 -4
  10. data/{mu.gemspec → cloud-mu.gemspec} +2 -2
  11. data/cookbooks/awscli/Berksfile +8 -0
  12. data/cookbooks/mu-activedirectory/Berksfile +11 -0
  13. data/cookbooks/mu-firewall/Berksfile +9 -0
  14. data/cookbooks/mu-firewall/metadata.rb +1 -1
  15. data/cookbooks/mu-glusterfs/Berksfile +10 -0
  16. data/cookbooks/mu-jenkins/Berksfile +14 -0
  17. data/cookbooks/mu-master/Berksfile +23 -0
  18. data/cookbooks/mu-master/attributes/default.rb +1 -1
  19. data/cookbooks/mu-master/metadata.rb +2 -2
  20. data/cookbooks/mu-master/recipes/default.rb +1 -1
  21. data/cookbooks/mu-master/recipes/init.rb +7 -3
  22. data/cookbooks/mu-master/recipes/ssl-certs.rb +1 -0
  23. data/cookbooks/mu-mongo/Berksfile +10 -0
  24. data/cookbooks/mu-openvpn/Berksfile +11 -0
  25. data/cookbooks/mu-php54/Berksfile +13 -0
  26. data/cookbooks/mu-splunk/Berksfile +10 -0
  27. data/cookbooks/mu-tools/Berksfile +21 -0
  28. data/cookbooks/mu-tools/files/default/Mu_CA.pem +15 -15
  29. data/cookbooks/mu-utility/Berksfile +9 -0
  30. data/cookbooks/mu-utility/metadata.rb +2 -1
  31. data/cookbooks/nagios/Berksfile +7 -4
  32. data/cookbooks/s3fs/Berksfile +9 -0
  33. data/environments/dev.json +6 -6
  34. data/environments/prod.json +6 -6
  35. data/modules/mu.rb +20 -42
  36. data/modules/mu/cleanup.rb +102 -100
  37. data/modules/mu/cloud.rb +90 -28
  38. data/modules/mu/clouds/aws.rb +449 -218
  39. data/modules/mu/clouds/aws/alarm.rb +29 -17
  40. data/modules/mu/clouds/aws/cache_cluster.rb +78 -64
  41. data/modules/mu/clouds/aws/collection.rb +25 -18
  42. data/modules/mu/clouds/aws/container_cluster.rb +73 -66
  43. data/modules/mu/clouds/aws/database.rb +124 -116
  44. data/modules/mu/clouds/aws/dnszone.rb +27 -20
  45. data/modules/mu/clouds/aws/firewall_rule.rb +30 -22
  46. data/modules/mu/clouds/aws/folder.rb +18 -3
  47. data/modules/mu/clouds/aws/function.rb +77 -23
  48. data/modules/mu/clouds/aws/group.rb +19 -12
  49. data/modules/mu/clouds/aws/habitat.rb +153 -0
  50. data/modules/mu/clouds/aws/loadbalancer.rb +59 -52
  51. data/modules/mu/clouds/aws/log.rb +30 -23
  52. data/modules/mu/clouds/aws/msg_queue.rb +29 -20
  53. data/modules/mu/clouds/aws/notifier.rb +222 -0
  54. data/modules/mu/clouds/aws/role.rb +178 -90
  55. data/modules/mu/clouds/aws/search_domain.rb +40 -24
  56. data/modules/mu/clouds/aws/server.rb +169 -137
  57. data/modules/mu/clouds/aws/server_pool.rb +60 -83
  58. data/modules/mu/clouds/aws/storage_pool.rb +59 -31
  59. data/modules/mu/clouds/aws/user.rb +36 -27
  60. data/modules/mu/clouds/aws/userdata/linux.erb +101 -93
  61. data/modules/mu/clouds/aws/vpc.rb +250 -189
  62. data/modules/mu/clouds/azure.rb +132 -0
  63. data/modules/mu/clouds/cloudformation.rb +65 -1
  64. data/modules/mu/clouds/cloudformation/alarm.rb +8 -0
  65. data/modules/mu/clouds/cloudformation/cache_cluster.rb +7 -0
  66. data/modules/mu/clouds/cloudformation/collection.rb +7 -0
  67. data/modules/mu/clouds/cloudformation/database.rb +7 -0
  68. data/modules/mu/clouds/cloudformation/dnszone.rb +7 -0
  69. data/modules/mu/clouds/cloudformation/firewall_rule.rb +9 -2
  70. data/modules/mu/clouds/cloudformation/loadbalancer.rb +7 -0
  71. data/modules/mu/clouds/cloudformation/log.rb +7 -0
  72. data/modules/mu/clouds/cloudformation/server.rb +7 -0
  73. data/modules/mu/clouds/cloudformation/server_pool.rb +7 -0
  74. data/modules/mu/clouds/cloudformation/vpc.rb +7 -0
  75. data/modules/mu/clouds/google.rb +214 -110
  76. data/modules/mu/clouds/google/container_cluster.rb +42 -24
  77. data/modules/mu/clouds/google/database.rb +15 -6
  78. data/modules/mu/clouds/google/firewall_rule.rb +17 -25
  79. data/modules/mu/clouds/google/group.rb +13 -5
  80. data/modules/mu/clouds/google/habitat.rb +105 -0
  81. data/modules/mu/clouds/google/loadbalancer.rb +28 -20
  82. data/modules/mu/clouds/google/server.rb +93 -354
  83. data/modules/mu/clouds/google/server_pool.rb +18 -10
  84. data/modules/mu/clouds/google/user.rb +22 -14
  85. data/modules/mu/clouds/google/vpc.rb +97 -69
  86. data/modules/mu/config.rb +133 -38
  87. data/modules/mu/config/alarm.rb +25 -0
  88. data/modules/mu/config/cache_cluster.rb +5 -3
  89. data/modules/mu/config/cache_cluster.yml +23 -0
  90. data/modules/mu/config/database.rb +25 -16
  91. data/modules/mu/config/database.yml +3 -3
  92. data/modules/mu/config/function.rb +1 -2
  93. data/modules/mu/config/{project.rb → habitat.rb} +10 -10
  94. data/modules/mu/config/notifier.rb +85 -0
  95. data/modules/mu/config/notifier.yml +9 -0
  96. data/modules/mu/config/role.rb +1 -1
  97. data/modules/mu/config/search_domain.yml +2 -2
  98. data/modules/mu/config/server.rb +13 -1
  99. data/modules/mu/config/server.yml +3 -3
  100. data/modules/mu/config/server_pool.rb +3 -1
  101. data/modules/mu/config/storage_pool.rb +3 -1
  102. data/modules/mu/config/storage_pool.yml +19 -0
  103. data/modules/mu/config/vpc.rb +70 -8
  104. data/modules/mu/groomers/chef.rb +2 -3
  105. data/modules/mu/kittens.rb +500 -122
  106. data/modules/mu/master.rb +5 -5
  107. data/modules/mu/mommacat.rb +151 -91
  108. data/modules/tests/super_complex_bok.yml +12 -0
  109. data/modules/tests/super_simple_bok.yml +12 -0
  110. data/spec/mu/clouds/azure_spec.rb +82 -0
  111. data/spec/spec_helper.rb +105 -0
  112. metadata +26 -5
  113. data/modules/mu/clouds/aws/notification.rb +0 -139
  114. data/modules/mu/config/notification.rb +0 -44
@@ -186,17 +186,17 @@ module MU
186
186
  # @param tag_value [String]: The value of the tag specified by tag_key to match when searching by tag.
187
187
  # @param flags [Hash]: Optional flags
188
188
  # @return [Array<Hash<String,OpenStruct>>]: The cloud provider's complete descriptions of matching Databases
189
- def self.find(cloud_id: nil, region: MU.curRegion, tag_key: "Name", tag_value: nil, flags: {})
189
+ def self.find(cloud_id: nil, region: MU.curRegion, tag_key: "Name", tag_value: nil, credentials: nil, flags: {})
190
190
  map = {}
191
191
  if cloud_id
192
- db = MU::Cloud::AWS::Database.getDatabaseById(cloud_id, region: region)
192
+ db = MU::Cloud::AWS::Database.getDatabaseById(cloud_id, region: region, credentials: credentials)
193
193
  map[cloud_id] = db if db
194
194
  end
195
195
 
196
196
  if tag_value
197
- MU::Cloud::AWS.rds(region).describe_db_instances.db_instances.each { |db|
198
- resp = MU::Cloud::AWS.rds(region).list_tags_for_resource(
199
- resource_name: MU::Cloud::AWS::Database.getARN(db.db_instance_identifier, "db", "rds", region: region)
197
+ MU::Cloud::AWS.rds(credentials: credentials, region: region).describe_db_instances.db_instances.each { |db|
198
+ resp = MU::Cloud::AWS.rds(credentials: credentials, region: region).list_tags_for_resource(
199
+ resource_name: MU::Cloud::AWS::Database.getARN(db.db_instance_identifier, "db", "rds", region: region, credentials: credentials)
200
200
  )
201
201
  if resp && resp.tag_list && !resp.tag_list.empty?
202
202
  resp.tag_list.each { |tag|
@@ -218,7 +218,8 @@ module MU
218
218
  # @param region [String]: The region in which the resource resides.
219
219
  # @param account_number [String]: The account in which the resource resides.
220
220
  # @return [String]
221
- def self.getARN(resource, resource_type, client_type, region: MU.curRegion, account_number: MU.account_number)
221
+ def self.getARN(resource, resource_type, client_type, region: MU.curRegion, account_number: nil, credentials: nil)
222
+ account_number ||= MU::Cloud::AWS.credToAcct(credentials)
222
223
  aws_str = MU::Cloud::AWS.isGovCloud?(region) ? "aws-us-gov" : "aws"
223
224
  "arn:#{aws_str}:#{client_type}:#{region}:#{account_number}:#{resource_type}:#{resource}"
224
225
  end
@@ -246,18 +247,6 @@ module MU
246
247
  return tags
247
248
  end
248
249
 
249
- # Add our standard tag set to an Amazon RDS resource.
250
- # @param resource [String]: The name of the resource
251
- # @param resource_type [String]: The type of the resource (one of `db, es, og, pg, ri, secgrp, snapshot, subgrp`)
252
- # @param region [String]: The cloud provider region
253
- def addStandardTags(resource, resource_type, region: MU.curRegion)
254
- MU.log "Adding tags to RDS resource #{resource}: #{allTags}"
255
- MU::Cloud::AWS.rds(region).add_tags_to_resource(
256
- resource_name: MU::Cloud::AWS::Database.getARN(resource, resource_type, "rds", region: region),
257
- tags: allTags
258
- )
259
- end
260
-
261
250
  # Getting the password for the master user, and saving it in a database / cluster specif vault
262
251
  def getPassword
263
252
  if @config['password'].nil?
@@ -334,10 +323,10 @@ module MU
334
323
  point_in_time_config[:use_latest_restorable_time] = true if @config['restore_time'] == "latest"
335
324
  end
336
325
 
337
- if @config["read_replica_of"] || @config["create_read_replica"]
326
+ if @config["read_replica_of"]# || @config["create_read_replica"]
338
327
  srcdb = @config['source_identifier']
339
328
  if @config["read_replica_of"]["region"] and @config['region'] != @config["read_replica_of"]["region"]
340
- srcdb = MU::Cloud::AWS::Database.getARN(@config['source_identifier'], "db", "rds", region: @config["read_replica_of"]["region"])
329
+ srcdb = MU::Cloud::AWS::Database.getARN(@config['source_identifier'], "db", "rds", region: @config["read_replica_of"]["region"], credentials: @config['credentials'])
341
330
  end
342
331
  read_replica_struct = {
343
332
  db_instance_identifier: @config['identifier'],
@@ -360,22 +349,24 @@ module MU
360
349
  begin
361
350
  if %w{existing_snapshot new_snapshot}.include?(@config["creation_style"])
362
351
  MU.log "Creating database instance #{@config['identifier']} from snapshot #{@config["snapshot_id"]}"
363
- resp = MU::Cloud::AWS.rds(@config['region']).restore_db_instance_from_db_snapshot(config)
352
+ resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).restore_db_instance_from_db_snapshot(config)
364
353
  elsif @config["creation_style"] == "point_in_time"
365
354
  MU.log "Creating database instance #{@config['identifier']} based on point in time backup #{@config['restore_time']} of #{@config['source_identifier']}"
366
- resp = MU::Cloud::AWS.rds(@config['region']).restore_db_instance_to_point_in_time(point_in_time_config)
355
+ resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).restore_db_instance_to_point_in_time(point_in_time_config)
367
356
  elsif @config["read_replica_of"]
368
357
  MU.log "Creating read replica database instance #{@config['identifier']} for #{@config['source_identifier']}"
369
358
  begin
370
- resp = MU::Cloud::AWS.rds(@config['region']).create_db_instance_read_replica(read_replica_struct)
359
+ resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_instance_read_replica(read_replica_struct)
371
360
  rescue Aws::RDS::Errors::DBSubnetGroupNotAllowedFault => e
372
361
  MU.log "Being forced to use source database's subnet group: #{e.message}", MU::WARN
373
362
  read_replica_struct.delete(:db_subnet_group_name)
374
- resp = MU::Cloud::AWS.rds(@config['region']).create_db_instance_read_replica(read_replica_struct)
363
+ resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_instance_read_replica(read_replica_struct)
375
364
  end
376
365
  elsif @config["creation_style"] == "new"
377
- MU.log "Creating database instance #{@config['identifier']}"
378
- resp = MU::Cloud::AWS.rds(@config['region']).create_db_instance(config)
366
+ MU.log "Creating pristine database instance #{@config['identifier']} (#{@config['name']}) in #{@config['region']}"
367
+ puts @config['credentials']
368
+ pp config
369
+ resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_instance(config)
379
370
  end
380
371
  rescue Aws::RDS::Errors::InvalidParameterValue => e
381
372
  if attempts < 5
@@ -392,7 +383,7 @@ module MU
392
383
  retries = 0
393
384
 
394
385
  begin
395
- MU::Cloud::AWS.rds(@config['region']).wait_until(:db_instance_available, db_instance_identifier: @config['identifier']) do |waiter|
386
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).wait_until(:db_instance_available, db_instance_identifier: @config['identifier']) do |waiter|
396
387
  # Does create_db_instance implement wait_until_available ?
397
388
  waiter.max_attempts = nil
398
389
  waiter.before_attempt do |attempts|
@@ -410,10 +401,12 @@ module MU
410
401
  retry
411
402
  end
412
403
 
413
- database = MU::Cloud::AWS::Database.getDatabaseById(@config['identifier'], region: @config['region'])
404
+ database = MU::Cloud::AWS::Database.getDatabaseById(@config['identifier'], region: @config['region'], credentials: @config['credentials'])
414
405
  MU::Cloud::AWS::DNSZone.genericMuDNSEntry(name: database.db_instance_identifier, target: "#{database.endpoint.address}.", cloudclass: MU::Cloud::Database, sync_wait: @config['dns_sync_wait'])
415
406
  MU.log "Database #{@config['name']} is at #{database.endpoint.address}", MU::SUMMARY
416
- MU.log "knife vault show #{@config['auth_vault']['vault']} #{@config['auth_vault']['item']} for Database #{@config['name']} credentials", MU::SUMMARY
407
+ if @config['auth_vault']
408
+ MU.log "knife vault show #{@config['auth_vault']['vault']} #{@config['auth_vault']['item']} for Database #{@config['name']} credentials", MU::SUMMARY
409
+ end
417
410
 
418
411
  # If referencing an existing DB, insert this deploy's DB security group so it can access db
419
412
  if @config["creation_style"] == 'existing'
@@ -432,7 +425,7 @@ module MU
432
425
  mod_config[:vpc_security_group_ids] = vpc_sg_ids
433
426
  mod_config[:db_instance_identifier] = @config["identifier"]
434
427
 
435
- MU::Cloud::AWS.rds(@config['region']).modify_db_instance(mod_config)
428
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).modify_db_instance(mod_config)
436
429
  MU.log "Modified database #{@config['identifier']} with new security groups: #{mod_config}", MU::NOTICE
437
430
  end
438
431
 
@@ -454,12 +447,12 @@ module MU
454
447
  mod_config[:vpc_security_group_ids] = @config["vpc_security_group_ids"]
455
448
  mod_config[:apply_immediately] = true
456
449
 
457
- MU::Cloud::AWS.rds(@config['region']).modify_db_instance(mod_config)
450
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).modify_db_instance(mod_config)
458
451
  wait_start_time = Time.now
459
452
  retries = 0
460
453
 
461
454
  begin
462
- MU::Cloud::AWS.rds(@config['region']).wait_until(:db_instance_available, db_instance_identifier: @config['identifier']) do |waiter|
455
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).wait_until(:db_instance_available, db_instance_identifier: @config['identifier']) do |waiter|
463
456
  # Does create_db_instance implement wait_until_available ?
464
457
  waiter.max_attempts = nil
465
458
  waiter.before_attempt do |attempts|
@@ -481,7 +474,7 @@ module MU
481
474
  # Maybe wait for DB instance to be in available state. DB should still be writeable at this state
482
475
  if @config['allow_major_version_upgrade'] && @config["creation_style"] == "new"
483
476
  MU.log "Setting major database version upgrade on #{@config['identifier']}'"
484
- MU::Cloud::AWS.rds(@config['region']).modify_db_instance(
477
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).modify_db_instance(
485
478
  db_instance_identifier: @config['identifier'],
486
479
  apply_immediately: true,
487
480
  allow_major_version_upgrade: true
@@ -534,13 +527,13 @@ module MU
534
527
  resp =
535
528
  if @config["creation_style"] == "new"
536
529
  MU.log "Creating new database cluster #{@config['identifier']}"
537
- MU::Cloud::AWS.rds(@config['region']).create_db_cluster(cluster_config_struct)
530
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_cluster(cluster_config_struct)
538
531
  elsif %w{existing_snapshot new_snapshot}.include?(@config["creation_style"])
539
532
  MU.log "Creating new database cluster #{@config['identifier']} from snapshot #{@config["snapshot_id"]}"
540
- MU::Cloud::AWS.rds(@config['region']).restore_db_cluster_from_snapshot(cluster_config_struct)
533
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).restore_db_cluster_from_snapshot(cluster_config_struct)
541
534
  elsif @config["creation_style"] == "point_in_time"
542
535
  MU.log "Creating new database cluster #{@config['identifier']} from point in time backup #{@config["restore_time"]} of #{@config["source_identifier"]}"
543
- MU::Cloud::AWS.rds(@config['region']).restore_db_cluster_to_point_in_time(cluster_config_struct)
536
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).restore_db_cluster_to_point_in_time(cluster_config_struct)
544
537
  end
545
538
  rescue Aws::RDS::Errors::InvalidParameterValue => e
546
539
  if attempts < 5
@@ -557,7 +550,7 @@ module MU
557
550
  loop do
558
551
  MU.log "Waiting for #{@config['identifier']} to become available", MU::NOTICE if attempts % 5 == 0
559
552
  attempts += 1
560
- cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(@config['identifier'], region: @config['region'])
553
+ cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(@config['identifier'], region: @config['region'], credentials: @config['credentials'])
561
554
  break unless cluster.status != "available"
562
555
  sleep 30
563
556
  end
@@ -573,19 +566,19 @@ module MU
573
566
  }
574
567
 
575
568
  modify_db_cluster_struct[:preferred_maintenance_window] = @config["preferred_maintenance_window"] if @config["preferred_maintenance_window"]
576
- MU::Cloud::AWS.rds(@config['region']).modify_db_cluster(modify_db_cluster_struct)
569
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).modify_db_cluster(modify_db_cluster_struct)
577
570
 
578
571
  attempts = 0
579
572
  loop do
580
573
  MU.log "Waiting for #{@config['identifier']} to become available", MU::NOTICE if attempts % 5 == 0
581
574
  attempts += 1
582
- cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(@config['identifier'], region: @config['region'])
575
+ cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(@config['identifier'], region: @config['region'], credentials: @config['credentials'])
583
576
  break unless cluster.status != "available"
584
577
  sleep 30
585
578
  end
586
579
  end
587
580
 
588
- cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(@config['identifier'], region: @config['region'])
581
+ cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(@config['identifier'], region: @config['region'], credentials: @config['credentials'])
589
582
  MU::Cloud::AWS::DNSZone.genericMuDNSEntry(name: cluster.db_cluster_identifier, target: "#{cluster.endpoint}.", cloudclass: MU::Cloud::Database, sync_wait: @config['dns_sync_wait'])
590
583
  return cluster.db_cluster_identifier
591
584
  end
@@ -628,10 +621,10 @@ module MU
628
621
  # If we didn't specify a VPC try to figure out if the account has a default VPC
629
622
  vpc_id = nil
630
623
  subnets = []
631
- MU::Cloud::AWS.ec2(@config['region']).describe_vpcs.vpcs.each { |vpc|
624
+ MU::Cloud::AWS.ec2(region: @config['region'], credentials: @config['credentials']).describe_vpcs.vpcs.each { |vpc|
632
625
  if vpc.is_default
633
626
  vpc_id = vpc.vpc_id
634
- subnets = MU::Cloud::AWS.ec2(@config['region']).describe_subnets(
627
+ subnets = MU::Cloud::AWS.ec2(region: @config['region'], credentials: @config['credentials']).describe_subnets(
635
628
  filters: [
636
629
  {
637
630
  name: "vpc-id",
@@ -662,7 +655,7 @@ module MU
662
655
  end
663
656
 
664
657
  if @config['creation_style'] == "existing"
665
- srcdb = MU::Cloud::AWS.rds(@config['region']).describe_db_instances(
658
+ srcdb = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).describe_db_instances(
666
659
  db_instance_identifier: @config['identifier']
667
660
  )
668
661
  srcdb_vpc = srcdb.db_instances.first.db_subnet_group.vpc_id
@@ -676,7 +669,7 @@ module MU
676
669
  raise MuError, "Couldn't find subnets in #{@vpc} to add to #{@config["subnet_group_name"]}. Make sure the subnets are valid and publicly_accessible is set correctly"
677
670
  else
678
671
  # Create subnet group
679
- resp = MU::Cloud::AWS.rds(@config['region']).create_db_subnet_group(
672
+ resp = MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_subnet_group(
680
673
  db_subnet_group_name: @config["subnet_group_name"],
681
674
  db_subnet_group_description: @config["subnet_group_name"],
682
675
  subnet_ids: subnet_ids,
@@ -715,7 +708,7 @@ module MU
715
708
  def createDBClusterParameterGroup
716
709
  MU.log "Creating a cluster parameter group #{@config["parameter_group_name"]}"
717
710
 
718
- MU::Cloud::AWS.rds(@config['region']).create_db_cluster_parameter_group(
711
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_cluster_parameter_group(
719
712
  db_cluster_parameter_group_name: @config["parameter_group_name"],
720
713
  db_parameter_group_family: @config["parameter_group_family"],
721
714
  description: "Parameter group for #{@config["parameter_group_family"]}",
@@ -729,7 +722,7 @@ module MU
729
722
  }
730
723
 
731
724
  MU.log "Modifiying cluster parameter group #{@config["parameter_group_name"]}"
732
- MU::Cloud::AWS.rds(@config['region']).modify_db_cluster_parameter_group(
725
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).modify_db_cluster_parameter_group(
733
726
  db_cluster_parameter_group_name: @config["parameter_group_name"],
734
727
  parameters: params
735
728
  )
@@ -739,7 +732,7 @@ module MU
739
732
  # Create a database parameter group.
740
733
  def createDBParameterGroup
741
734
  MU.log "Creating a database parameter group #{@config["parameter_group_name"]}"
742
- MU::Cloud::AWS.rds(@config['region']).create_db_parameter_group(
735
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_parameter_group(
743
736
  db_parameter_group_name: @config["parameter_group_name"],
744
737
  db_parameter_group_family: @config["parameter_group_family"],
745
738
  description: "Parameter group for #{@config["parameter_group_family"]}",
@@ -753,7 +746,7 @@ module MU
753
746
  }
754
747
 
755
748
  MU.log "Modifiying database parameter group #{@config["parameter_group_name"]}"
756
- MU::Cloud::AWS.rds(@config['region']).modify_db_parameter_group(
749
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).modify_db_parameter_group(
757
750
  db_parameter_group_name: @config["parameter_group_name"],
758
751
  parameters: params
759
752
  )
@@ -765,7 +758,7 @@ module MU
765
758
  # @param region [String]: The cloud provider region
766
759
  # @return [OpenStruct]
767
760
  def self.getDBClusterParameterGroup(param_group_id, region: MU.curRegion)
768
- MU::Cloud::AWS.rds(region).describe_db_cluster_parameter_groups(db_cluster_parameter_group_name: param_group_id).db_cluster_parameter_groups.first
761
+ MU::Cloud::AWS.rds(region: region).describe_db_cluster_parameter_groups(db_cluster_parameter_group_name: param_group_id).db_cluster_parameter_groups.first
769
762
  # rescue DBClusterParameterGroupNotFound => e
770
763
  # Of course the API will return DBParameterGroupNotFound instead of the documented DBClusterParameterGroupNotFound error.
771
764
  rescue Aws::RDS::Errors::DBParameterGroupNotFound => e
@@ -777,7 +770,7 @@ module MU
777
770
  # @param region [String]: The cloud provider region
778
771
  # @return [OpenStruct]
779
772
  def self.getDBParameterGroup(param_group_id, region: MU.curRegion)
780
- MU::Cloud::AWS.rds(region).describe_db_parameter_groups(db_parameter_group_name: param_group_id).db_parameter_groups.first
773
+ MU::Cloud::AWS.rds(region: region).describe_db_parameter_groups(db_parameter_group_name: param_group_id).db_parameter_groups.first
781
774
  rescue Aws::RDS::Errors::DBParameterGroupNotFound => e
782
775
  #we're fine returning nil
783
776
  end
@@ -787,7 +780,7 @@ module MU
787
780
  # @param region [String]: The cloud provider region
788
781
  # @return [OpenStruct]
789
782
  def self.getSubnetGroup(subnet_id, region: MU.curRegion)
790
- MU::Cloud::AWS.rds(region).describe_db_subnet_groups(db_subnet_group_name: subnet_id).db_subnet_groups.first
783
+ MU::Cloud::AWS.rds(region: region).describe_db_subnet_groups(db_subnet_group_name: subnet_id).db_subnet_groups.first
791
784
  rescue Aws::RDS::Errors::DBSubnetGroupNotFoundFault => e
792
785
  #we're fine returning nil
793
786
  end
@@ -795,7 +788,7 @@ module MU
795
788
  # Called automatically by {MU::Deploy#createResources}
796
789
  def groom
797
790
  unless @config["create_cluster"]
798
- database = MU::Cloud::AWS::Database.getDatabaseById(@config['identifier'], region: @config['region'])
791
+ database = MU::Cloud::AWS::Database.getDatabaseById(@config['identifier'], region: @config['region'], credentials: @config['credentials'])
799
792
 
800
793
  # Run SQL on deploy
801
794
  if @config['run_sql_on_deploy']
@@ -885,7 +878,7 @@ module MU
885
878
  MU.log "Setting multi-az on #{@config['identifier']}"
886
879
  attempts = 0
887
880
  begin
888
- MU::Cloud::AWS.rds(@config['region']).modify_db_instance(
881
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).modify_db_instance(
889
882
  db_instance_identifier: @config['identifier'],
890
883
  apply_immediately: true,
891
884
  multi_az: true
@@ -946,7 +939,7 @@ module MU
946
939
  if !cloud_desc.db_security_groups.empty?
947
940
  cloud_desc.db_security_groups.each { |rds_sg|
948
941
  begin
949
- MU::Cloud::AWS.rds(@config['region']).authorize_db_security_group_ingress(
942
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).authorize_db_security_group_ingress(
950
943
  db_security_group_name: rds_sg.db_security_group_name,
951
944
  cidrip: cidr
952
945
  )
@@ -969,9 +962,9 @@ module MU
969
962
  # @param db_id [String]: The cloud provider's identifier for this database.
970
963
  # @param region [String]: The cloud provider region
971
964
  # @return [OpenStruct]
972
- def self.getDatabaseById(db_id, region: MU.curRegion)
965
+ def self.getDatabaseById(db_id, region: MU.curRegion, credentials: nil)
973
966
  raise MuError, "You must provide a db_id" if db_id.nil?
974
- MU::Cloud::AWS.rds(region).describe_db_instances(db_instance_identifier: db_id).db_instances.first
967
+ MU::Cloud::AWS.rds(region: region, credentials: credentials).describe_db_instances(db_instance_identifier: db_id).db_instances.first
975
968
  rescue Aws::RDS::Errors::DBInstanceNotFound => e
976
969
  # We're fine with this returning nil when searching for a database instance the doesn't exist.
977
970
  end
@@ -980,8 +973,8 @@ module MU
980
973
  # @param db_cluster_id [String]: The cloud provider's identifier for this database cluster.
981
974
  # @param region [String]: The cloud provider region
982
975
  # @return [OpenStruct]
983
- def self.getDatabaseClusterById(db_cluster_id, region: MU.curRegion)
984
- MU::Cloud::AWS.rds(region).describe_db_clusters(db_cluster_identifier: db_cluster_id).db_clusters.first
976
+ def self.getDatabaseClusterById(db_cluster_id, region: MU.curRegion, credentials: nil)
977
+ MU::Cloud::AWS.rds(region: region, credentials: credentials).describe_db_clusters(db_cluster_identifier: db_cluster_id).db_clusters.first
985
978
  rescue Aws::RDS::Errors::DBClusterNotFoundFault => e
986
979
  # We're fine with this returning nil when searching for a database cluster the doesn't exist.
987
980
  end
@@ -1002,7 +995,7 @@ module MU
1002
995
  deploy_struct =
1003
996
  if db["create_cluster"]
1004
997
  db["identifier"] = @mu_name.downcase if db["identifier"].nil?
1005
- cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(db["identifier"], region: db['region'])
998
+ cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(db["identifier"], region: db['region'], credentials: @config['credentials'])
1006
999
  # DNS records for the "real" zone should always be registered as late as possible so override_existing only overwrites the records after the resource is ready to use.
1007
1000
  if db['dns_records']
1008
1001
  db['dns_records'].each { |dnsrec|
@@ -1124,13 +1117,13 @@ module MU
1124
1117
  begin
1125
1118
  snapshot =
1126
1119
  if @config["create_cluster"]
1127
- MU::Cloud::AWS.rds(@config['region']).create_db_cluster_snapshot(
1120
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_cluster_snapshot(
1128
1121
  db_cluster_snapshot_identifier: snap_id,
1129
1122
  db_cluster_identifier: @config["identifier"],
1130
1123
  tags: allTags
1131
1124
  )
1132
1125
  else
1133
- MU::Cloud::AWS.rds(@config['region']).create_db_snapshot(
1126
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).create_db_snapshot(
1134
1127
  db_snapshot_identifier: snap_id,
1135
1128
  db_instance_identifier: @config["identifier"],
1136
1129
  tags: allTags
@@ -1149,9 +1142,9 @@ module MU
1149
1142
  MU.log "Waiting for RDS snapshot of #{@config["identifier"]} to be ready...", MU::DEBUG
1150
1143
  snapshot_resp =
1151
1144
  if @config["create_cluster"]
1152
- MU::Cloud::AWS.rds(@config['region']).describe_db_cluster_snapshots(db_cluster_snapshot_identifier: snap_id)
1145
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).describe_db_cluster_snapshots(db_cluster_snapshot_identifier: snap_id)
1153
1146
  else
1154
- MU::Cloud::AWS.rds(@config['region']).describe_db_snapshots(db_snapshot_identifier: snap_id)
1147
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).describe_db_snapshots(db_snapshot_identifier: snap_id)
1155
1148
  end
1156
1149
 
1157
1150
  if @config["create_cluster"]
@@ -1171,9 +1164,9 @@ module MU
1171
1164
  def getExistingSnapshot
1172
1165
  resp =
1173
1166
  if @config["create_cluster"]
1174
- MU::Cloud::AWS.rds(@config['region']).describe_db_cluster_snapshots(db_cluster_snapshot_identifier: @config["identifier"])
1167
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).describe_db_cluster_snapshots(db_cluster_snapshot_identifier: @config["identifier"])
1175
1168
  else
1176
- MU::Cloud::AWS.rds(@config['region']).describe_db_snapshots(db_snapshot_identifier: @config["identifier"])
1169
+ MU::Cloud::AWS.rds(region: @config['region'], credentials: @config['credentials']).describe_db_snapshots(db_snapshot_identifier: @config["identifier"])
1177
1170
  end
1178
1171
 
1179
1172
  snapshots = @config["create_cluster"] ? resp.db_cluster_snapshots : resp.db_snapshots
@@ -1186,20 +1179,29 @@ module MU
1186
1179
  end
1187
1180
  end
1188
1181
 
1182
+ # Does this resource type exist as a global (cloud-wide) artifact, or
1183
+ # is it localized to a region/zone?
1184
+ # @return [Boolean]
1185
+ def self.isGlobal?
1186
+ false
1187
+ end
1188
+
1189
1189
  # Called by {MU::Cleanup}. Locates resources that were created by the
1190
1190
  # currently-loaded deployment, and purges them.
1191
1191
  # @param noop [Boolean]: If true, will only print what would be done
1192
1192
  # @param ignoremaster [Boolean]: If true, will remove resources not flagged as originating from this Mu server
1193
1193
  # @param region [String]: The cloud provider region in which to operate
1194
1194
  # @return [void]
1195
- def self.cleanup(skipsnapshots: false, noop: false, ignoremaster: false, region: MU.curRegion, flags: {})
1196
- resp = MU::Cloud::AWS.rds(region).describe_db_instances
1195
+ def self.cleanup(noop: false, ignoremaster: false, credentials: nil, region: MU.curRegion, flags: {})
1196
+ skipsnapshots = flags["skipsnapshots"]
1197
+
1198
+ resp = MU::Cloud::AWS.rds(credentials: credentials, region: region).describe_db_instances
1197
1199
  threads = []
1198
1200
 
1199
1201
  resp.db_instances.each { |db|
1200
1202
  db_id = db.db_instance_identifier
1201
- arn = MU::Cloud::AWS::Database.getARN(db.db_instance_identifier, "db", "rds", region: region)
1202
- tags = MU::Cloud::AWS.rds(region).list_tags_for_resource(resource_name: arn).tag_list
1203
+ arn = MU::Cloud::AWS::Database.getARN(db.db_instance_identifier, "db", "rds", region: region, credentials: credentials)
1204
+ tags = MU::Cloud::AWS.rds(credentials: credentials, region: region).list_tags_for_resource(resource_name: arn).tag_list
1203
1205
 
1204
1206
  found_muid = false
1205
1207
  found_master = false
@@ -1223,7 +1225,7 @@ module MU
1223
1225
  threads << Thread.new(db) { |mydb|
1224
1226
  MU.dupGlobals(parent_thread_id)
1225
1227
  Thread.abort_on_exception = true
1226
- MU::Cloud::AWS::Database.terminate_rds_instance(mydb, noop: noop, skipsnapshots: skipsnapshots, region: region, deploy_id: MU.deploy_id, cloud_id: db.db_instance_identifier, mu_name: db.db_instance_identifier.upcase)
1228
+ MU::Cloud::AWS::Database.terminate_rds_instance(mydb, noop: noop, skipsnapshots: skipsnapshots, region: region, deploy_id: MU.deploy_id, cloud_id: db.db_instance_identifier, mu_name: db.db_instance_identifier.upcase, credentials: credentials)
1227
1229
  }
1228
1230
  end
1229
1231
  }
@@ -1235,11 +1237,11 @@ module MU
1235
1237
 
1236
1238
  # Cleanup database clusters
1237
1239
  threads = []
1238
- resp = MU::Cloud::AWS.rds(region).describe_db_clusters
1240
+ resp = MU::Cloud::AWS.rds(credentials: credentials, region: region).describe_db_clusters
1239
1241
  resp.db_clusters.each { |cluster|
1240
1242
  cluster_id = cluster.db_cluster_identifier
1241
- arn = MU::Cloud::AWS::Database.getARN(cluster_id, "cluster", "rds", region: region)
1242
- tags = MU::Cloud::AWS.rds(region).list_tags_for_resource(resource_name: arn).tag_list
1243
+ arn = MU::Cloud::AWS::Database.getARN(cluster_id, "cluster", "rds", region: region, credentials: credentials)
1244
+ tags = MU::Cloud::AWS.rds(credentials: credentials, region: region).list_tags_for_resource(resource_name: arn).tag_list
1243
1245
 
1244
1246
  found_muid = false
1245
1247
  found_master = false
@@ -1263,7 +1265,7 @@ module MU
1263
1265
  threads << Thread.new(cluster) { |mydbcluster|
1264
1266
  MU.dupGlobals(parent_thread_id)
1265
1267
  Thread.abort_on_exception = true
1266
- MU::Cloud::AWS::Database.terminate_rds_cluster(mydbcluster, noop: noop, skipsnapshots: skipsnapshots, region: region, deploy_id: MU.deploy_id, cloud_id: cluster_id, mu_name: cluster_id.upcase)
1268
+ MU::Cloud::AWS::Database.terminate_rds_cluster(mydbcluster, noop: noop, skipsnapshots: skipsnapshots, region: region, deploy_id: MU.deploy_id, cloud_id: cluster_id, mu_name: cluster_id.upcase, credentials: credentials)
1267
1269
  }
1268
1270
  end
1269
1271
  }
@@ -1275,10 +1277,10 @@ module MU
1275
1277
 
1276
1278
  threads = []
1277
1279
  # Cleanup database subnet group
1278
- MU::Cloud::AWS.rds(region).describe_db_subnet_groups.db_subnet_groups.each { |sub_group|
1280
+ MU::Cloud::AWS.rds(credentials: credentials, region: region).describe_db_subnet_groups.db_subnet_groups.each { |sub_group|
1279
1281
  sub_group_id = sub_group.db_subnet_group_name
1280
- arn = MU::Cloud::AWS::Database.getARN(sub_group_id, "subgrp", "rds", region: region)
1281
- tags = MU::Cloud::AWS.rds(region).list_tags_for_resource(resource_name: arn).tag_list
1282
+ arn = MU::Cloud::AWS::Database.getARN(sub_group_id, "subgrp", "rds", region: region, credentials: credentials)
1283
+ tags = MU::Cloud::AWS.rds(credentials: credentials, region: region).list_tags_for_resource(resource_name: arn).tag_list
1282
1284
 
1283
1285
  found_muid = false
1284
1286
  found_master = false
@@ -1308,10 +1310,10 @@ module MU
1308
1310
  }
1309
1311
 
1310
1312
  # Cleanup database parameter group
1311
- MU::Cloud::AWS.rds(region).describe_db_parameter_groups.db_parameter_groups.each { |param_group|
1313
+ MU::Cloud::AWS.rds(credentials: credentials, region: region).describe_db_parameter_groups.db_parameter_groups.each { |param_group|
1312
1314
  param_group_id = param_group.db_parameter_group_name
1313
- arn = MU::Cloud::AWS::Database.getARN(param_group_id, "pg", "rds", region: region)
1314
- tags = MU::Cloud::AWS.rds(region).list_tags_for_resource(resource_name: arn).tag_list
1315
+ arn = MU::Cloud::AWS::Database.getARN(param_group_id, "pg", "rds", region: region, credentials: credentials)
1316
+ tags = MU::Cloud::AWS.rds(credentials: credentials, region: region).list_tags_for_resource(resource_name: arn).tag_list
1315
1317
 
1316
1318
  found_muid = false
1317
1319
  found_master = false
@@ -1341,10 +1343,10 @@ module MU
1341
1343
  }
1342
1344
 
1343
1345
  # Cleanup database cluster parameter group
1344
- MU::Cloud::AWS.rds(region).describe_db_cluster_parameter_groups.db_cluster_parameter_groups.each { |param_group|
1346
+ MU::Cloud::AWS.rds(credentials: credentials, region: region).describe_db_cluster_parameter_groups.db_cluster_parameter_groups.each { |param_group|
1345
1347
  param_group_id = param_group.db_cluster_parameter_group_name
1346
- arn = MU::Cloud::AWS::Database.getARN(param_group_id, "cluster-pg", "rds", region: region)
1347
- tags = MU::Cloud::AWS.rds(region).list_tags_for_resource(resource_name: arn).tag_list
1348
+ arn = MU::Cloud::AWS::Database.getARN(param_group_id, "cluster-pg", "rds", region: region, credentials: credentials)
1349
+ tags = MU::Cloud::AWS.rds(credentials: credentials, region: region).list_tags_for_resource(resource_name: arn).tag_list
1348
1350
 
1349
1351
  found_muid = false
1350
1352
  found_master = false
@@ -1447,16 +1449,20 @@ module MU
1447
1449
  def self.validateConfig(db, configurator)
1448
1450
  ok = true
1449
1451
 
1450
- db_cluster_engines = %w{aurora}
1451
- db["create_cluster"] =
1452
- if db_cluster_engines.include?(db["engine"])
1453
- true
1452
+ if db['create_cluster'] or db['engine'] == "aurora" or db["member_of_cluster"]
1453
+ case db['engine']
1454
+ when "mysql", "aurora", "aurora-mysql"
1455
+ db["engine"] = "aurora-mysql"
1456
+ when "postgres", "postgresql", "postgresql-mysql"
1457
+ db["engine"] = "aurora-postgresql"
1454
1458
  else
1455
- false
1459
+ ok = false
1460
+ MU.log "Requested a clustered database, but engine #{db['engine']} is not supported for clustering", MU::ERR
1456
1461
  end
1462
+ end
1457
1463
 
1458
1464
  db["license_model"] ||=
1459
- if db["engine"] == "postgres"
1465
+ if ["postgres", "postgresql", "aurora-postgresql"].include?(db["engine"])
1460
1466
  "postgresql-license"
1461
1467
  elsif db["engine"] == "mysql"
1462
1468
  "general-public-license"
@@ -1465,15 +1471,15 @@ module MU
1465
1471
  end
1466
1472
 
1467
1473
  if db["create_read_replica"] or db['read_replica_of']
1468
- if db["engine"] != "postgres" and db["engine"] != "mysql"
1469
- MU.log "Read replica(s) database instances only supported for postgres and mysql. #{db["engine"]} not supported.", MU::ERR
1474
+ if !["postgres", "postgresql", "mysql", "aurora-mysql", "aurora-postgresql", "mariadb"].include?(db["engine"])
1475
+ MU.log "Read replica(s) database instances not supported for #{db["engine"]}.", MU::ERR
1470
1476
  ok = false
1471
1477
  end
1472
1478
  end
1473
1479
 
1474
1480
  if db["creation_style"] == "existing"
1475
1481
  begin
1476
- MU::Cloud::AWS.rds(db['region']).describe_db_instances(
1482
+ MU::Cloud::AWS.rds(region: db['region']).describe_db_instances(
1477
1483
  db_instance_identifier: db['identifier']
1478
1484
  )
1479
1485
  rescue Aws::RDS::Errors::DBInstanceNotFound => e
@@ -1556,7 +1562,7 @@ module MU
1556
1562
  # Remove an RDS database and associated artifacts
1557
1563
  # @param db [OpenStruct]: The cloud provider's description of the database artifact
1558
1564
  # @return [void]
1559
- def self.terminate_rds_instance(db, noop: false, skipsnapshots: false, region: MU.curRegion, deploy_id: MU.deploy_id, mu_name: nil, cloud_id: nil)
1565
+ def self.terminate_rds_instance(db, noop: false, skipsnapshots: false, region: MU.curRegion, deploy_id: MU.deploy_id, mu_name: nil, cloud_id: nil, credentials: nil)
1560
1566
  raise MuError, "terminate_rds_instance requires a non-nil database descriptor" if db.nil?
1561
1567
  db_id = db.db_instance_identifier
1562
1568
 
@@ -1578,7 +1584,7 @@ module MU
1578
1584
 
1579
1585
  rdssecgroups = Array.new
1580
1586
  begin
1581
- secgroup = MU::Cloud::AWS.rds(region).describe_db_security_groups(db_security_group_name: db_id)
1587
+ secgroup = MU::Cloud::AWS.rds(region: region).describe_db_security_groups(db_security_group_name: db_id)
1582
1588
  rescue Aws::RDS::Errors::DBSecurityGroupNotFound
1583
1589
  # this is normal in VPC world
1584
1590
  end
@@ -1591,6 +1597,7 @@ module MU
1591
1597
  loop do
1592
1598
  MU.log "Waiting for #{db_id} to be in a removable state...", MU::NOTICE
1593
1599
  db = MU::Cloud::AWS::Database.getDatabaseById(db_id, region: region)
1600
+ return if db.nil?
1594
1601
  break unless %w{creating modifying backing-up}.include?(db.db_instance_status)
1595
1602
  sleep 60
1596
1603
  end
@@ -1601,15 +1608,15 @@ module MU
1601
1608
  if %w{deleting deleted}.include?(db.db_instance_status)
1602
1609
  MU.log "#{db_id} has already been terminated", MU::WARN
1603
1610
  else
1604
- def self.dbSkipSnap(db_id, region)
1611
+ def self.dbSkipSnap(db_id, region, credentials)
1605
1612
  # We're calling this several times so lets declare it once
1606
1613
  MU.log "Terminating #{db_id} (not saving final snapshot)"
1607
- MU::Cloud::AWS.rds(region).delete_db_instance(db_instance_identifier: db_id, skip_final_snapshot: true)
1614
+ MU::Cloud::AWS.rds(region: region, credentials: credentials).delete_db_instance(db_instance_identifier: db_id, skip_final_snapshot: true)
1608
1615
  end
1609
1616
 
1610
- def self.dbCreateSnap(db_id, region)
1617
+ def self.dbCreateSnap(db_id, region, credentials)
1611
1618
  MU.log "Terminating #{db_id} (final snapshot: #{db_id}-mufinal)"
1612
- MU::Cloud::AWS.rds(region).delete_db_instance(db_instance_identifier: db_id, final_db_snapshot_identifier: "#{db_id}-mufinal", skip_final_snapshot: false)
1619
+ MU::Cloud::AWS.rds(region: region, credentials: credentials).delete_db_instance(db_instance_identifier: db_id, final_db_snapshot_identifier: "#{db_id}-mufinal", skip_final_snapshot: false)
1613
1620
  end
1614
1621
 
1615
1622
  if !noop
@@ -1617,9 +1624,9 @@ module MU
1617
1624
  begin
1618
1625
  if db.db_cluster_identifier || db.read_replica_source_db_instance_identifier
1619
1626
  # make sure we don't create final snapshot for a database instance that is part of a cluster, or if it's a read replica database instance
1620
- dbSkipSnap(db_id, region)
1627
+ dbSkipSnap(db_id, region, credentials)
1621
1628
  else
1622
- skipsnapshots ? dbSkipSnap(db_id, region) : dbCreateSnap(db_id, region)
1629
+ skipsnapshots ? dbSkipSnap(db_id, region, credentials) : dbCreateSnap(db_id, region, credentials)
1623
1630
  end
1624
1631
  rescue Aws::RDS::Errors::InvalidDBInstanceState => e
1625
1632
  if retries < 5
@@ -1631,10 +1638,10 @@ module MU
1631
1638
  MU.log "#{db_id} is not in a removable state after several retries, giving up. #{e.inspect}", MU::ERR
1632
1639
  end
1633
1640
  rescue Aws::RDS::Errors::DBSnapshotAlreadyExists
1634
- dbSkipSnap(db_id, region)
1641
+ dbSkipSnap(db_id, region, credentials)
1635
1642
  MU.log "Snapshot of #{db_id} already exists", MU::WARN
1636
1643
  rescue Aws::RDS::Errors::SnapshotQuotaExceeded
1637
- dbSkipSnap(db_id, region)
1644
+ dbSkipSnap(db_id, region, credentials)
1638
1645
  MU.log "Snapshot quota exceeded while deleting #{db_id}", MU::ERR
1639
1646
  end
1640
1647
  end
@@ -1657,7 +1664,7 @@ module MU
1657
1664
  begin
1658
1665
  rdssecgroups.each { |sg|
1659
1666
  MU.log "Removing RDS Security Group #{sg}"
1660
- MU::Cloud::AWS.rds(region).delete_db_security_group(db_security_group_name: sg) if !noop
1667
+ MU::Cloud::AWS.rds(region: region).delete_db_security_group(db_security_group_name: sg) if !noop
1661
1668
  }
1662
1669
  rescue Aws::RDS::Errors::DBSecurityGroupNotFound
1663
1670
  MU.log "RDS Security Group #{sg} disappeared before we could remove it", MU::WARN
@@ -1679,7 +1686,7 @@ module MU
1679
1686
  # Remove an RDS database cluster and associated artifacts
1680
1687
  # @param cluster [OpenStruct]: The cloud provider's description of the database artifact
1681
1688
  # @return [void]
1682
- def self.terminate_rds_cluster(cluster, noop: false, skipsnapshots: false, region: MU.curRegion, deploy_id: MU.deploy_id, mu_name: nil, cloud_id: nil)
1689
+ def self.terminate_rds_cluster(cluster, noop: false, skipsnapshots: false, region: MU.curRegion, deploy_id: MU.deploy_id, mu_name: nil, cloud_id: nil, credentials: nil)
1683
1690
  raise MuError, "terminate_rds_cluster requires a non-nil database cluster descriptor" if cluster.nil?
1684
1691
  cluster_id = cluster.db_cluster_identifier
1685
1692
 
@@ -1689,6 +1696,7 @@ module MU
1689
1696
  region: region,
1690
1697
  deploy_id: deploy_id,
1691
1698
  cloud_id: cloud_id,
1699
+ credentials: credentials,
1692
1700
  mu_name: mu_name
1693
1701
  ).first
1694
1702
 
@@ -1699,7 +1707,7 @@ module MU
1699
1707
  unless cluster.status == "available"
1700
1708
  loop do
1701
1709
  MU.log "Waiting for #{cluster_id} to be in a removable state...", MU::NOTICE
1702
- cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(cluster_id, region: region)
1710
+ cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(cluster_id, region: region, credentials: credentials)
1703
1711
  break unless %w{creating modifying backing-up}.include?(cluster.status)
1704
1712
  sleep 60
1705
1713
  end
@@ -1711,20 +1719,20 @@ module MU
1711
1719
  MU.log "#{cluster_id} has already been terminated", MU::WARN
1712
1720
  else
1713
1721
  unless noop
1714
- def self.clusterSkipSnap(cluster_id, region)
1722
+ def self.clusterSkipSnap(cluster_id, region, credentials)
1715
1723
  # We're calling this several times so lets declare it once
1716
1724
  MU.log "Terminating #{cluster_id}. Not saving final snapshot"
1717
- MU::Cloud::AWS.rds(region).delete_db_cluster(db_cluster_identifier: cluster_id, skip_final_snapshot: true)
1725
+ MU::Cloud::AWS.rds(region: region, credentials: credentials).delete_db_cluster(db_cluster_identifier: cluster_id, skip_final_snapshot: true)
1718
1726
  end
1719
1727
 
1720
- def self.clusterCreateSnap(cluster_id, region)
1728
+ def self.clusterCreateSnap(cluster_id, region, credentials)
1721
1729
  MU.log "Terminating #{cluster_id}. Saving final snapshot: #{cluster_id}-mufinal"
1722
- MU::Cloud::AWS.rds(region).delete_db_cluster(db_cluster_identifier: cluster_id, skip_final_snapshot: false, final_db_snapshot_identifier: "#{cluster_id}-mufinal")
1730
+ MU::Cloud::AWS.rds(region: region, credentials: credentials).delete_db_cluster(db_cluster_identifier: cluster_id, skip_final_snapshot: false, final_db_snapshot_identifier: "#{cluster_id}-mufinal")
1723
1731
  end
1724
1732
 
1725
1733
  retries = 0
1726
1734
  begin
1727
- skipsnapshots ? clusterSkipSnap(cluster_id, region) : clusterCreateSnap(cluster_id, region)
1735
+ skipsnapshots ? clusterSkipSnap(cluster_id, region, credentials) : clusterCreateSnap(cluster_id, region, credentials)
1728
1736
  rescue Aws::RDS::Errors::InvalidDBClusterStateFault => e
1729
1737
  if retries < 5
1730
1738
  MU.log "#{cluster_id} is not in a removable state, retrying several times", MU::WARN
@@ -1735,10 +1743,10 @@ module MU
1735
1743
  MU.log "#{cluster_id} is not in a removable state after several retries, giving up. #{e.inspect}", MU::ERR
1736
1744
  end
1737
1745
  rescue Aws::RDS::Errors::DBClusterSnapshotAlreadyExistsFault
1738
- clusterSkipSnap(cluster_id, region)
1746
+ clusterSkipSnap(cluster_id, region, credentials)
1739
1747
  MU.log "Snapshot of #{cluster_id} already exists", MU::WARN
1740
1748
  rescue Aws::RDS::Errors::DBClusterQuotaExceeded
1741
- clusterSkipSnap(cluster_id, region)
1749
+ clusterSkipSnap(cluster_id, region, credentials)
1742
1750
  MU.log "Snapshot quota exceeded while deleting #{cluster_id}", MU::ERR
1743
1751
  end
1744
1752
  end
@@ -1747,7 +1755,7 @@ module MU
1747
1755
  # We're wating until getDatabaseClusterById returns nil. This assumes the database cluster object doesn't linger around in "deleted" state for a while.
1748
1756
  loop do
1749
1757
  MU.log "Waiting for #{cluster_id} to terminate", MU::NOTICE
1750
- cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(cluster_id, region: region)
1758
+ cluster = MU::Cloud::AWS::Database.getDatabaseClusterById(cluster_id, region: region, credentials: credentials)
1751
1759
  break unless cluster
1752
1760
  sleep 30
1753
1761
  end
@@ -1773,7 +1781,7 @@ module MU
1773
1781
  def self.delete_subnet_group(subnet_group_id, region: MU.curRegion)
1774
1782
  retries ||= 0
1775
1783
  MU.log "Deleting DB subnet group #{subnet_group_id}"
1776
- MU::Cloud::AWS.rds(region).delete_db_subnet_group(db_subnet_group_name: subnet_group_id)
1784
+ MU::Cloud::AWS.rds(region: region).delete_db_subnet_group(db_subnet_group_name: subnet_group_id)
1777
1785
  rescue Aws::RDS::Errors::DBSubnetGroupNotFoundFault => e
1778
1786
  MU.log "DB subnet group #{subnet_group_id} disappeared before we could remove it", MU::WARN
1779
1787
  rescue Aws::RDS::Errors::InvalidDBSubnetGroupStateFault=> e
@@ -1794,7 +1802,7 @@ module MU
1794
1802
  def self.delete_db_parameter_group(parameter_group_id, region: MU.curRegion)
1795
1803
  retries ||= 0
1796
1804
  MU.log "Deleting DB parameter group #{parameter_group_id}"
1797
- MU::Cloud::AWS.rds(region).delete_db_parameter_group(db_parameter_group_name: parameter_group_id)
1805
+ MU::Cloud::AWS.rds(region: region).delete_db_parameter_group(db_parameter_group_name: parameter_group_id)
1798
1806
  rescue Aws::RDS::Errors::DBParameterGroupNotFound
1799
1807
  MU.log "DB parameter group #{parameter_group_id} disappeared before we could remove it", MU::WARN
1800
1808
  rescue Aws::RDS::Errors::InvalidDBParameterGroupState => e
@@ -1815,7 +1823,7 @@ module MU
1815
1823
  def self.delete_db_cluster_parameter_group(parameter_group_id, region: MU.curRegion)
1816
1824
  retries ||= 0
1817
1825
  MU.log "Deleting cluster parameter group #{parameter_group_id}"
1818
- MU::Cloud::AWS.rds(region).delete_db_cluster_parameter_group(db_cluster_parameter_group_name: parameter_group_id)
1826
+ MU::Cloud::AWS.rds(region: region).delete_db_cluster_parameter_group(db_cluster_parameter_group_name: parameter_group_id)
1819
1827
  # AWS API sucks. instead of returning the documented error DBClusterParameterGroupNotFoundFault it errors out with DBParameterGroupNotFound.
1820
1828
  rescue Aws::RDS::Errors::DBParameterGroupNotFound
1821
1829
  MU.log "Cluster parameter group #{parameter_group_id} disappeared before we could remove it", MU::WARN