Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(clouddriver/aws): Allow finding SG vpc IDs by name #1784

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@ interface MortService {
String account

static VPC findForRegionAndAccount(Collection<MortService.VPC> allVPCs,
String sourceVpcId,
String sourceVpcIdOrName,
String region,
String account) {
def sourceVpc = allVPCs.find { it.id == sourceVpcId }
def sourceVpc = allVPCs.find { it.id == sourceVpcIdOrName || (it.name.equalsIgnoreCase(sourceVpcIdOrName) && it.region == region && it.account == account) }
def targetVpc = allVPCs.find { it.name == sourceVpc?.name && it.region == region && it.account == account }

if (!targetVpc) {
throw new IllegalStateException("No matching VPC found (vpcId: ${sourceVpcId}, region: ${region}, account: ${account}")
throw new IllegalStateException("No matching VPC found (vpcId: ${sourceVpcIdOrName}, region: ${region}, account: ${account}")
}

return targetVpc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@

package com.netflix.spinnaker.orca.clouddriver

import com.netflix.spinnaker.orca.clouddriver.MortService
import spock.lang.Specification
import spock.lang.Unroll

import static com.netflix.spinnaker.orca.clouddriver.MortService.VPC.*
import static com.netflix.spinnaker.orca.clouddriver.MortService.SecurityGroup.*
import static com.netflix.spinnaker.orca.clouddriver.MortService.SecurityGroup.SecurityGroupIngress
import static com.netflix.spinnaker.orca.clouddriver.MortService.SecurityGroup.applyMappings
import static com.netflix.spinnaker.orca.clouddriver.MortService.SecurityGroup.filterForSecurityGroupIngress
import static com.netflix.spinnaker.orca.clouddriver.MortService.SecurityGroup.findById
import static com.netflix.spinnaker.orca.clouddriver.MortService.VPC.findForRegionAndAccount

class MortServiceSpec extends Specification {
void "should extract only the security group ingress rules from SecurityGroup"() {
Expand Down Expand Up @@ -98,6 +100,19 @@ class MortServiceSpec extends Specification {
findForRegionAndAccount(allVPCs, "vpc1-0", "us-east-1", "test") == allVPCs[1]
}

void "should find VPC for region and account given name"() {
given:
def allVPCs = [
new MortService.VPC(id: "vpc1-0", name: "vpc1", region: "us-west-1", account: "test"),
new MortService.VPC(id: "vpc1-1", name: "vpc1", region: "us-east-1", account: "test"),
]

expect:
findForRegionAndAccount(allVPCs, "vpc1", "us-west-1", "test") == allVPCs[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth a negative case that the name matches but region or account do not?

findForRegionAndAccount(allVPCs, "vpc1", "us-east-1", "test") == allVPCs[1]
findForRegionAndAccount(allVPCs, "VPC1", "us-east-1", "test") == allVPCs[1]
}

@Unroll
void "should throw exception if VPC cannot be found"() {
given:
Expand Down