modules/mu/clouds/aws.rb in cloud-mu-3.0.0beta vs modules/mu/clouds/aws.rb in cloud-mu-3.0.0

- old
+ new

@@ -162,10 +162,11 @@ # Given an AWS region, check the API to make sure it's a valid one # @param r [String] # @return [String] def self.validate_region(r, credentials: nil) + require "aws-sdk-core" begin MU::Cloud::AWS.ec2(region: r, credentials: credentials).describe_availability_zones.availability_zones.first.region_name rescue ::Aws::EC2::Errors::UnauthorizedOperation => e MU.log "Got '#{e.message}' trying to validate region #{r} (hosted: #{hosted?.to_s})", MU::ERR, details: loadCredentials(credentials) raise MuError, "Got '#{e.message}' trying to validate region #{r} with credentials #{credentials ? credentials : "<default>"} (hosted: #{hosted?.to_s})" @@ -205,19 +206,23 @@ end end MU.log "Created standard tags for resource #{resource}", MU::DEBUG, details: caller end + @@myVPCObj = nil + # If we reside in this cloud, return the VPC in which we, the Mu Master, reside. # @return [MU::Cloud::VPC] def self.myVPCObj + return @@myVPCObj if @@myVPCObj return nil if !hosted? instance = MU.myCloudDescriptor return nil if !instance or !instance.vpc_id - vpc = MU::MommaCat.findStray("AWS", "vpc", cloud_id: instance.vpc_id, dummy_ok: true) + vpc = MU::MommaCat.findStray("AWS", "vpc", cloud_id: instance.vpc_id, dummy_ok: true, no_deploy_search: true) return nil if vpc.nil? or vpc.size == 0 - vpc.first + @@myVPCObj = vpc.first + @@myVPCObj end # If we've configured AWS as a provider, or are simply hosted in AWS, # decide what our default region is. def self.myRegion(credentials = nil) @@ -1332,11 +1337,11 @@ # Create an AWS API client # @param region [String]: Amazon region so we know what endpoint to use # @param api [String]: Which API are we wrapping? def initialize(region: MU.curRegion, api: "EC2", credentials: nil) - @cred_obj = MU::Cloud::AWS.loadCredentials(credentials) @credentials = MU::Cloud::AWS.credConfig(credentials, name_only: true) + @cred_obj = MU::Cloud::AWS.loadCredentials(credentials) if !@cred_obj raise MuError, "Unable to locate valid AWS credentials for #{api} API. #{credentials ? "Credentials requested were '#{credentials}'": ""}" end