Ensuring that specifying allowed inbound IP and VNet are mutually exclusive (#2)

This commit is contained in:
Sumit Kalra 2019-09-26 15:35:55 -07:00 committed by GitHub
parent 0f4d81e091
commit 45840ffc3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 4 deletions

View File

@ -676,8 +676,12 @@ func assertRequiredParametersSet(c *Config, errs *packer.MultiError) {
} }
if c.AllowedInboundIpAddresses != nil && len(c.AllowedInboundIpAddresses) >= 1 { if c.AllowedInboundIpAddresses != nil && len(c.AllowedInboundIpAddresses) >= 1 {
if ok, err := assertAllowedInboundIpAddresses(c.AllowedInboundIpAddresses, "allowed_inbound_ip_addresses"); !ok { if c.VirtualNetworkName != "" {
errs = packer.MultiErrorAppend(errs, err) errs = packer.MultiErrorAppend(errs, fmt.Errorf("If virtual_network_name is specified, allowed_inbound_ip_addresses cannot be specified"))
} else {
if ok, err := assertAllowedInboundIpAddresses(c.AllowedInboundIpAddresses, "allowed_inbound_ip_addresses"); !ok {
errs = packer.MultiErrorAppend(errs, err)
}
} }
} }

View File

@ -308,7 +308,6 @@ func TestConfigShouldAcceptCorrectInboundIpAddresses(t *testing.T) {
"subscription_id": "ignore", "subscription_id": "ignore",
"os_type": constants.Target_Linux, "os_type": constants.Target_Linux,
"communicator": "none", "communicator": "none",
"virtual_network_name": "MyVirtualNetwork",
} }
config["allowed_inbound_ip_addresses"] = ipValue0 config["allowed_inbound_ip_addresses"] = ipValue0
@ -355,7 +354,6 @@ func TestConfigShouldRejectIncorrectInboundIpAddresses(t *testing.T) {
"subscription_id": "ignore", "subscription_id": "ignore",
"os_type": constants.Target_Linux, "os_type": constants.Target_Linux,
"communicator": "none", "communicator": "none",
"virtual_network_name": "MyVirtualNetwork",
} }
config["allowed_inbound_ip_addresses"] = []string{"127.0.0.1", "127.0.0.two"} config["allowed_inbound_ip_addresses"] = []string{"127.0.0.1", "127.0.0.two"}
@ -372,6 +370,32 @@ func TestConfigShouldRejectIncorrectInboundIpAddresses(t *testing.T) {
} }
} }
func TestConfigShouldRejectInboundIpAddressesWithVirtualNetwork(t *testing.T) {
config := map[string]interface{}{
"capture_name_prefix": "ignore",
"capture_container_name": "ignore",
"location": "ignore",
"image_url": "ignore",
"storage_account": "ignore",
"resource_group_name": "ignore",
"subscription_id": "ignore",
"os_type": constants.Target_Linux,
"communicator": "none",
"allowed_inbound_ip_addresses": "127.0.0.1",
}
_, _, err := newConfig(config, getPackerConfiguration())
if err != nil {
t.Fatal(err)
}
config["virtual_network_name"] = "some_vnet_name"
_, _, err = newConfig(config, getPackerConfiguration())
if err == nil {
t.Errorf("Expected configuration creation to fail, but it succeeded with allowed_inbound_ip_addresses and virtual_network_name both specified")
}
}
func TestConfigShouldDefaultToPublicCloud(t *testing.T) { func TestConfigShouldDefaultToPublicCloud(t *testing.T) {
c, _, _ := newConfig(getArmBuilderConfiguration(), getPackerConfiguration()) c, _, _ := newConfig(getArmBuilderConfiguration(), getPackerConfiguration())

View File

@ -341,6 +341,9 @@ Providing `temp_resource_group_name` or `location` in combination with
Network Security Group will be created with corresponding rules and be bound Network Security Group will be created with corresponding rules and be bound
to the NIC attached to the VM. to the NIC attached to the VM.
Providing `allowed_inbound_ip_addresses` in combination with
`virtual_network_name` is not allowed.
- `virtual_network_subnet_name` (string) If virtual\_network\_name is set, - `virtual_network_subnet_name` (string) If virtual\_network\_name is set,
this value **may** also be set. If virtual\_network\_name is set, and this this value **may** also be set. If virtual\_network\_name is set, and this
value is not set the builder attempts to determine the subnet to use with value is not set the builder attempts to determine the subnet to use with