modules/mu/providers/google/vpc.rb in cloud-mu-3.4.0 vs modules/mu/providers/google/vpc.rb in cloud-mu-3.5.0
- old
+ new
@@ -362,10 +362,16 @@
}
end
}
end
+
+ # The API is filled with lies
+ @subnets.reject! { |s|
+ !MU::Cloud::Google.listRegions(credentials: @credentials).include?(s.az)
+ }
+
return @subnets
end
# Given some search criteria try locating a NAT Gaateway in this VPC.
# @param nat_cloud_id [String]: The cloud provider's identifier for this NAT.
@@ -440,25 +446,33 @@
return nil
end
# Check for a subnet in this VPC matching one or more of the specified
# criteria, and return it if found.
- def getSubnet(cloud_id: nil, name: nil, tag_key: nil, tag_value: nil, ip_block: nil, region: nil)
+ def getSubnet(cloud_id: nil, name: nil, tag_key: nil, tag_value: nil, ip_block: nil, region: nil, subnet_mu_name: nil)
if !cloud_id.nil? and cloud_id.match(/^https:\/\//)
cloud_id.match(/\/regions\/([^\/]+)\/subnetworks\/([^\/]+)$/)
region = Regexp.last_match[1]
cloud_id = Regexp.last_match[2]
cloud_id.gsub!(/.*?\//, "")
end
- 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]
+
+ if name
+ subnet_mu_name ||= @config['scrub_mu_isms'] ? @cloud_id+name.downcase : MU::Cloud::Google.nameStr(@deploy.getResourceName(name, max_length: 61))
+ end
+
+ 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]
subnets.each { |subnet|
next if region and subnet.az != region
if !cloud_id.nil? and !subnet.cloud_id.nil? and subnet.cloud_id.to_s == cloud_id.to_s
return subnet
elsif !name.nil? and !subnet.name.nil? and
subnet.name.downcase.to_s == name.downcase.to_s
return subnet
+ elsif !subnet_mu_name.nil? and !subnet.name.nil? and
+ subnet.name.downcase.to_s == subnet_mu_name.downcase.to_s
+ return subnet
end
}
return nil
end
@@ -929,10 +943,18 @@
MU.log "Google VPC #{vpc['name']} declared a #NAT route, but I don't see an upstream NAT host I can use. Do I even have public subnets?", MU::ERR
ok = false
else
route['nat_host_name'] = nat['name']
route['priority'] = 100
+ MU::Config.addDependency(vpc, nat['name'], "server", their_phase: "groom", my_phase: "groom")
+ vpc["bastion"] = MU::Config::Ref.get(
+ name: nat['name'],
+ cloud: vpc['cloud'],
+ credentials: vpc['credentials'],
+ type: "servers"
+ )
+
end
end
}
end
@@ -1169,9 +1191,12 @@
begin
@cloud_desc_cache = MU::Cloud::Google.compute(credentials: @parent.config['credentials']).get_subnetwork(@parent.habitat_id, @az, @cloud_id)
rescue ::Google::Apis::ClientError => e
if e.message.match(/notFound: /)
MU.log "Failed to fetch cloud description for Google subnet #{@cloud_id}", MU::WARN, details: { "project" => @parent.habitat_id, "region" => @az, "name" => @cloud_id }
+ return nil
+ elsif e.message.match(/Unknown region\. /)
+ 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 }
return nil
else
raise e
end
end