provider/azurerm: check if lb sub resources exist when reading (#11553)
This fixes detection when a sub resource is deleted via the API or Portal
This commit is contained in:
parent
a4687c5b36
commit
c104ce6815
|
@ -140,31 +140,31 @@ func resourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, meta
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
configs := *loadBalancer.LoadBalancerPropertiesFormat.BackendAddressPools
|
config, _, exists := findLoadBalancerBackEndAddressPoolByName(loadBalancer, d.Get("name").(string))
|
||||||
for _, config := range configs {
|
if !exists {
|
||||||
if *config.Name == d.Get("name").(string) {
|
d.SetId("")
|
||||||
d.Set("name", config.Name)
|
log.Printf("[INFO] LoadBalancer Backend Address Pool %q not found. Removing from state", d.Get("name").(string))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if config.BackendAddressPoolPropertiesFormat.BackendIPConfigurations != nil {
|
d.Set("name", config.Name)
|
||||||
backend_ip_configurations := make([]string, 0, len(*config.BackendAddressPoolPropertiesFormat.BackendIPConfigurations))
|
|
||||||
for _, backendConfig := range *config.BackendAddressPoolPropertiesFormat.BackendIPConfigurations {
|
|
||||||
backend_ip_configurations = append(backend_ip_configurations, *backendConfig.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("backend_ip_configurations", backend_ip_configurations)
|
if config.BackendAddressPoolPropertiesFormat.BackendIPConfigurations != nil {
|
||||||
}
|
backend_ip_configurations := make([]string, 0, len(*config.BackendAddressPoolPropertiesFormat.BackendIPConfigurations))
|
||||||
|
for _, backendConfig := range *config.BackendAddressPoolPropertiesFormat.BackendIPConfigurations {
|
||||||
if config.BackendAddressPoolPropertiesFormat.LoadBalancingRules != nil {
|
backend_ip_configurations = append(backend_ip_configurations, *backendConfig.ID)
|
||||||
load_balancing_rules := make([]string, 0, len(*config.BackendAddressPoolPropertiesFormat.LoadBalancingRules))
|
|
||||||
for _, rule := range *config.BackendAddressPoolPropertiesFormat.LoadBalancingRules {
|
|
||||||
load_balancing_rules = append(load_balancing_rules, *rule.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("backend_ip_configurations", load_balancing_rules)
|
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set("backend_ip_configurations", backend_ip_configurations)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.BackendAddressPoolPropertiesFormat.LoadBalancingRules != nil {
|
||||||
|
load_balancing_rules := make([]string, 0, len(*config.BackendAddressPoolPropertiesFormat.LoadBalancingRules))
|
||||||
|
for _, rule := range *config.BackendAddressPoolPropertiesFormat.LoadBalancingRules {
|
||||||
|
load_balancing_rules = append(load_balancing_rules, *rule.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
d.Set("backend_ip_configurations", load_balancing_rules)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -94,6 +94,29 @@ func TestAccAzureRMLoadBalancerBackEndAddressPool_reapply(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMLoadBalancerBackEndAddressPool_disappears(t *testing.T) {
|
||||||
|
var lb network.LoadBalancer
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
addressPoolName := fmt.Sprintf("%d-address-pool", ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMLoadBalancerBackEndAddressPool_basic(ri, addressPoolName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
|
||||||
|
testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName, &lb),
|
||||||
|
testCheckAzureRMLoadBalancerBackEndAddressPoolDisappears(addressPoolName, &lb),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
func testCheckAzureRMLoadBalancerBackEndAddressPoolExists(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
_, _, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName)
|
_, _, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName)
|
||||||
|
@ -116,6 +139,34 @@ func testCheckAzureRMLoadBalancerBackEndAddressPoolNotExists(addressPoolName str
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMLoadBalancerBackEndAddressPoolDisappears(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).loadBalancerClient
|
||||||
|
|
||||||
|
_, i, exists := findLoadBalancerBackEndAddressPoolByName(lb, addressPoolName)
|
||||||
|
if !exists {
|
||||||
|
return fmt.Errorf("A BackEnd Address Pool with name %q cannot be found.", addressPoolName)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPools := *lb.LoadBalancerPropertiesFormat.BackendAddressPools
|
||||||
|
pools := append(currentPools[:i], currentPools[i+1:]...)
|
||||||
|
lb.LoadBalancerPropertiesFormat.BackendAddressPools = &pools
|
||||||
|
|
||||||
|
id, err := parseAzureResourceID(*lb.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.CreateOrUpdate(id.ResourceGroup, *lb.Name, *lb, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error Creating/Updating LoadBalancer %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Get(id.ResourceGroup, *lb.Name, "")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAzureRMLoadBalancerBackEndAddressPool_basic(rInt int, addressPoolName string) string {
|
func testAccAzureRMLoadBalancerBackEndAddressPool_basic(rInt int, addressPoolName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
|
|
|
@ -163,22 +163,21 @@ func resourceArmLoadBalancerNatPoolRead(d *schema.ResourceData, meta interface{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
configs := *loadBalancer.LoadBalancerPropertiesFormat.InboundNatPools
|
config, _, exists := findLoadBalancerNatPoolByName(loadBalancer, d.Get("name").(string))
|
||||||
for _, config := range configs {
|
if !exists {
|
||||||
if *config.Name == d.Get("name").(string) {
|
d.SetId("")
|
||||||
d.Set("name", config.Name)
|
log.Printf("[INFO] LoadBalancer Nat Pool %q not found. Removing from state", d.Get("name").(string))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
d.Set("protocol", config.InboundNatPoolPropertiesFormat.Protocol)
|
d.Set("name", config.Name)
|
||||||
d.Set("frontend_port_start", config.InboundNatPoolPropertiesFormat.FrontendPortRangeStart)
|
d.Set("protocol", config.InboundNatPoolPropertiesFormat.Protocol)
|
||||||
d.Set("frontend_port_end", config.InboundNatPoolPropertiesFormat.FrontendPortRangeEnd)
|
d.Set("frontend_port_start", config.InboundNatPoolPropertiesFormat.FrontendPortRangeStart)
|
||||||
d.Set("backend_port", config.InboundNatPoolPropertiesFormat.BackendPort)
|
d.Set("frontend_port_end", config.InboundNatPoolPropertiesFormat.FrontendPortRangeEnd)
|
||||||
|
d.Set("backend_port", config.InboundNatPoolPropertiesFormat.BackendPort)
|
||||||
|
|
||||||
if config.InboundNatPoolPropertiesFormat.FrontendIPConfiguration != nil {
|
if config.InboundNatPoolPropertiesFormat.FrontendIPConfiguration != nil {
|
||||||
d.Set("frontend_ip_configuration_id", config.InboundNatPoolPropertiesFormat.FrontendIPConfiguration.ID)
|
d.Set("frontend_ip_configuration_id", config.InboundNatPoolPropertiesFormat.FrontendIPConfiguration.ID)
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -134,6 +134,29 @@ func TestAccAzureRMLoadBalancerNatPool_reapply(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMLoadBalancerNatPool_disappears(t *testing.T) {
|
||||||
|
var lb network.LoadBalancer
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
natPoolName := fmt.Sprintf("NatPool-%d", ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMLoadBalancerNatPool_basic(ri, natPoolName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
|
||||||
|
testCheckAzureRMLoadBalancerNatPoolExists(natPoolName, &lb),
|
||||||
|
testCheckAzureRMLoadBalancerNatPoolDisappears(natPoolName, &lb),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMLoadBalancerNatPoolExists(natPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
func testCheckAzureRMLoadBalancerNatPoolExists(natPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
_, _, exists := findLoadBalancerNatPoolByName(lb, natPoolName)
|
_, _, exists := findLoadBalancerNatPoolByName(lb, natPoolName)
|
||||||
|
@ -156,6 +179,34 @@ func testCheckAzureRMLoadBalancerNatPoolNotExists(natPoolName string, lb *networ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMLoadBalancerNatPoolDisappears(natPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).loadBalancerClient
|
||||||
|
|
||||||
|
_, i, exists := findLoadBalancerNatPoolByName(lb, natPoolName)
|
||||||
|
if !exists {
|
||||||
|
return fmt.Errorf("A Nat Pool with name %q cannot be found.", natPoolName)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentPools := *lb.LoadBalancerPropertiesFormat.InboundNatPools
|
||||||
|
pools := append(currentPools[:i], currentPools[i+1:]...)
|
||||||
|
lb.LoadBalancerPropertiesFormat.InboundNatPools = &pools
|
||||||
|
|
||||||
|
id, err := parseAzureResourceID(*lb.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.CreateOrUpdate(id.ResourceGroup, *lb.Name, *lb, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error Creating/Updating LoadBalancer %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Get(id.ResourceGroup, *lb.Name, "")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAzureRMLoadBalancerNatPool_basic(rInt int, natPoolName string) string {
|
func testAccAzureRMLoadBalancerNatPool_basic(rInt int, natPoolName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
|
|
|
@ -163,25 +163,24 @@ func resourceArmLoadBalancerNatRuleRead(d *schema.ResourceData, meta interface{}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
configs := *loadBalancer.LoadBalancerPropertiesFormat.InboundNatRules
|
config, _, exists := findLoadBalancerNatRuleByName(loadBalancer, d.Get("name").(string))
|
||||||
for _, config := range configs {
|
if !exists {
|
||||||
if *config.Name == d.Get("name").(string) {
|
d.SetId("")
|
||||||
d.Set("name", config.Name)
|
log.Printf("[INFO] LoadBalancer Nat Rule %q not found. Removing from state", d.Get("name").(string))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
d.Set("protocol", config.InboundNatRulePropertiesFormat.Protocol)
|
d.Set("name", config.Name)
|
||||||
d.Set("frontend_port", config.InboundNatRulePropertiesFormat.FrontendPort)
|
d.Set("protocol", config.InboundNatRulePropertiesFormat.Protocol)
|
||||||
d.Set("backend_port", config.InboundNatRulePropertiesFormat.BackendPort)
|
d.Set("frontend_port", config.InboundNatRulePropertiesFormat.FrontendPort)
|
||||||
|
d.Set("backend_port", config.InboundNatRulePropertiesFormat.BackendPort)
|
||||||
|
|
||||||
if config.InboundNatRulePropertiesFormat.FrontendIPConfiguration != nil {
|
if config.InboundNatRulePropertiesFormat.FrontendIPConfiguration != nil {
|
||||||
d.Set("frontend_ip_configuration_id", config.InboundNatRulePropertiesFormat.FrontendIPConfiguration.ID)
|
d.Set("frontend_ip_configuration_id", config.InboundNatRulePropertiesFormat.FrontendIPConfiguration.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.InboundNatRulePropertiesFormat.BackendIPConfiguration != nil {
|
if config.InboundNatRulePropertiesFormat.BackendIPConfiguration != nil {
|
||||||
d.Set("backend_ip_configuration_id", config.InboundNatRulePropertiesFormat.BackendIPConfiguration.ID)
|
d.Set("backend_ip_configuration_id", config.InboundNatRulePropertiesFormat.BackendIPConfiguration.ID)
|
||||||
}
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -136,6 +136,29 @@ func TestAccAzureRMLoadBalancerNatRule_reapply(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMLoadBalancerNatRule_disappears(t *testing.T) {
|
||||||
|
var lb network.LoadBalancer
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
natRuleName := fmt.Sprintf("NatRule-%d", ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMLoadBalancerNatRule_basic(ri, natRuleName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
|
||||||
|
testCheckAzureRMLoadBalancerNatRuleExists(natRuleName, &lb),
|
||||||
|
testCheckAzureRMLoadBalancerNatRuleDisappears(natRuleName, &lb),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMLoadBalancerNatRuleExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
func testCheckAzureRMLoadBalancerNatRuleExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
_, _, exists := findLoadBalancerNatRuleByName(lb, natRuleName)
|
_, _, exists := findLoadBalancerNatRuleByName(lb, natRuleName)
|
||||||
|
@ -158,6 +181,34 @@ func testCheckAzureRMLoadBalancerNatRuleNotExists(natRuleName string, lb *networ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMLoadBalancerNatRuleDisappears(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).loadBalancerClient
|
||||||
|
|
||||||
|
_, i, exists := findLoadBalancerNatRuleByName(lb, natRuleName)
|
||||||
|
if !exists {
|
||||||
|
return fmt.Errorf("A Nat Rule with name %q cannot be found.", natRuleName)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentRules := *lb.LoadBalancerPropertiesFormat.InboundNatRules
|
||||||
|
rules := append(currentRules[:i], currentRules[i+1:]...)
|
||||||
|
lb.LoadBalancerPropertiesFormat.InboundNatRules = &rules
|
||||||
|
|
||||||
|
id, err := parseAzureResourceID(*lb.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.CreateOrUpdate(id.ResourceGroup, *lb.Name, *lb, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error Creating/Updating LoadBalancer %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Get(id.ResourceGroup, *lb.Name, "")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAzureRMLoadBalancerNatRule_basic(rInt int, natRuleName string) string {
|
func testAccAzureRMLoadBalancerNatRule_basic(rInt int, natRuleName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
|
|
|
@ -168,21 +168,20 @@ func resourceArmLoadBalancerProbeRead(d *schema.ResourceData, meta interface{})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
configs := *loadBalancer.LoadBalancerPropertiesFormat.Probes
|
config, _, exists := findLoadBalancerProbeByName(loadBalancer, d.Get("name").(string))
|
||||||
for _, config := range configs {
|
if !exists {
|
||||||
if *config.Name == d.Get("name").(string) {
|
d.SetId("")
|
||||||
d.Set("name", config.Name)
|
log.Printf("[INFO] LoadBalancer Probe %q not found. Removing from state", d.Get("name").(string))
|
||||||
|
return nil
|
||||||
d.Set("protocol", config.ProbePropertiesFormat.Protocol)
|
|
||||||
d.Set("interval_in_seconds", config.ProbePropertiesFormat.IntervalInSeconds)
|
|
||||||
d.Set("number_of_probes", config.ProbePropertiesFormat.NumberOfProbes)
|
|
||||||
d.Set("port", config.ProbePropertiesFormat.Port)
|
|
||||||
d.Set("request_path", config.ProbePropertiesFormat.RequestPath)
|
|
||||||
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set("name", config.Name)
|
||||||
|
d.Set("protocol", config.ProbePropertiesFormat.Protocol)
|
||||||
|
d.Set("interval_in_seconds", config.ProbePropertiesFormat.IntervalInSeconds)
|
||||||
|
d.Set("number_of_probes", config.ProbePropertiesFormat.NumberOfProbes)
|
||||||
|
d.Set("port", config.ProbePropertiesFormat.Port)
|
||||||
|
d.Set("request_path", config.ProbePropertiesFormat.RequestPath)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,6 +164,29 @@ func TestAccAzureRMLoadBalancerProbe_reapply(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMLoadBalancerProbe_disappears(t *testing.T) {
|
||||||
|
var lb network.LoadBalancer
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
probeName := fmt.Sprintf("probe-%d", ri)
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMLoadBalancerProbe_basic(ri, probeName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
|
||||||
|
testCheckAzureRMLoadBalancerProbeExists(probeName, &lb),
|
||||||
|
testCheckAzureRMLoadBalancerProbeDisappears(probeName, &lb),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMLoadBalancerProbeExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
func testCheckAzureRMLoadBalancerProbeExists(natRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
_, _, exists := findLoadBalancerProbeByName(lb, natRuleName)
|
_, _, exists := findLoadBalancerProbeByName(lb, natRuleName)
|
||||||
|
@ -186,6 +209,34 @@ func testCheckAzureRMLoadBalancerProbeNotExists(natRuleName string, lb *network.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMLoadBalancerProbeDisappears(addressPoolName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).loadBalancerClient
|
||||||
|
|
||||||
|
_, i, exists := findLoadBalancerProbeByName(lb, addressPoolName)
|
||||||
|
if !exists {
|
||||||
|
return fmt.Errorf("A Probe with name %q cannot be found.", addressPoolName)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentProbes := *lb.LoadBalancerPropertiesFormat.Probes
|
||||||
|
probes := append(currentProbes[:i], currentProbes[i+1:]...)
|
||||||
|
lb.LoadBalancerPropertiesFormat.Probes = &probes
|
||||||
|
|
||||||
|
id, err := parseAzureResourceID(*lb.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.CreateOrUpdate(id.ResourceGroup, *lb.Name, *lb, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error Creating/Updating LoadBalancer %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Get(id.ResourceGroup, *lb.Name, "")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAzureRMLoadBalancerProbe_basic(rInt int, probeName string) string {
|
func testAccAzureRMLoadBalancerProbe_basic(rInt int, probeName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
|
|
|
@ -190,39 +190,41 @@ func resourceArmLoadBalancerRuleRead(d *schema.ResourceData, meta interface{}) e
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
configs := *loadBalancer.LoadBalancerPropertiesFormat.LoadBalancingRules
|
config, _, exists := findLoadBalancerRuleByName(loadBalancer, d.Get("name").(string))
|
||||||
for _, config := range configs {
|
if !exists {
|
||||||
if *config.Name == d.Get("name").(string) {
|
d.SetId("")
|
||||||
d.Set("name", config.Name)
|
log.Printf("[INFO] LoadBalancer Rule %q not found. Removing from state", d.Get("name").(string))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
d.Set("protocol", config.LoadBalancingRulePropertiesFormat.Protocol)
|
d.Set("name", config.Name)
|
||||||
d.Set("frontend_port", config.LoadBalancingRulePropertiesFormat.FrontendPort)
|
|
||||||
d.Set("backend_port", config.LoadBalancingRulePropertiesFormat.BackendPort)
|
|
||||||
|
|
||||||
if config.LoadBalancingRulePropertiesFormat.EnableFloatingIP != nil {
|
d.Set("protocol", config.LoadBalancingRulePropertiesFormat.Protocol)
|
||||||
d.Set("enable_floating_ip", config.LoadBalancingRulePropertiesFormat.EnableFloatingIP)
|
d.Set("frontend_port", config.LoadBalancingRulePropertiesFormat.FrontendPort)
|
||||||
}
|
d.Set("backend_port", config.LoadBalancingRulePropertiesFormat.BackendPort)
|
||||||
|
|
||||||
if config.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes != nil {
|
if config.LoadBalancingRulePropertiesFormat.EnableFloatingIP != nil {
|
||||||
d.Set("idle_timeout_in_minutes", config.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes)
|
d.Set("enable_floating_ip", config.LoadBalancingRulePropertiesFormat.EnableFloatingIP)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.LoadBalancingRulePropertiesFormat.FrontendIPConfiguration != nil {
|
if config.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes != nil {
|
||||||
d.Set("frontend_ip_configuration_id", config.LoadBalancingRulePropertiesFormat.FrontendIPConfiguration.ID)
|
d.Set("idle_timeout_in_minutes", config.LoadBalancingRulePropertiesFormat.IdleTimeoutInMinutes)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.LoadBalancingRulePropertiesFormat.BackendAddressPool != nil {
|
if config.LoadBalancingRulePropertiesFormat.FrontendIPConfiguration != nil {
|
||||||
d.Set("backend_address_pool_id", config.LoadBalancingRulePropertiesFormat.BackendAddressPool.ID)
|
d.Set("frontend_ip_configuration_id", config.LoadBalancingRulePropertiesFormat.FrontendIPConfiguration.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.LoadBalancingRulePropertiesFormat.Probe != nil {
|
if config.LoadBalancingRulePropertiesFormat.BackendAddressPool != nil {
|
||||||
d.Set("probe_id", config.LoadBalancingRulePropertiesFormat.Probe.ID)
|
d.Set("backend_address_pool_id", config.LoadBalancingRulePropertiesFormat.BackendAddressPool.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.LoadBalancingRulePropertiesFormat.LoadDistribution != "" {
|
if config.LoadBalancingRulePropertiesFormat.Probe != nil {
|
||||||
d.Set("load_distribution", config.LoadBalancingRulePropertiesFormat.LoadDistribution)
|
d.Set("probe_id", config.LoadBalancingRulePropertiesFormat.Probe.ID)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if config.LoadBalancingRulePropertiesFormat.LoadDistribution != "" {
|
||||||
|
d.Set("load_distribution", config.LoadBalancingRulePropertiesFormat.LoadDistribution)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -231,6 +231,29 @@ func TestAccAzureRMLoadBalancerRule_reapply(t *testing.T) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAccAzureRMLoadBalancerRule_disappears(t *testing.T) {
|
||||||
|
var lb network.LoadBalancer
|
||||||
|
ri := acctest.RandInt()
|
||||||
|
lbRuleName := fmt.Sprintf("LbRule-%s", acctest.RandStringFromCharSet(8, acctest.CharSetAlpha))
|
||||||
|
|
||||||
|
resource.Test(t, resource.TestCase{
|
||||||
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
|
Providers: testAccProviders,
|
||||||
|
CheckDestroy: testCheckAzureRMLoadBalancerDestroy,
|
||||||
|
Steps: []resource.TestStep{
|
||||||
|
{
|
||||||
|
Config: testAccAzureRMLoadBalancerRule_basic(ri, lbRuleName),
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testCheckAzureRMLoadBalancerExists("azurerm_lb.test", &lb),
|
||||||
|
testCheckAzureRMLoadBalancerRuleExists(lbRuleName, &lb),
|
||||||
|
testCheckAzureRMLoadBalancerRuleDisappears(lbRuleName, &lb),
|
||||||
|
),
|
||||||
|
ExpectNonEmptyPlan: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func testCheckAzureRMLoadBalancerRuleExists(lbRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
func testCheckAzureRMLoadBalancerRuleExists(lbRuleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
return func(s *terraform.State) error {
|
return func(s *terraform.State) error {
|
||||||
_, _, exists := findLoadBalancerRuleByName(lb, lbRuleName)
|
_, _, exists := findLoadBalancerRuleByName(lb, lbRuleName)
|
||||||
|
@ -253,6 +276,34 @@ func testCheckAzureRMLoadBalancerRuleNotExists(lbRuleName string, lb *network.Lo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testCheckAzureRMLoadBalancerRuleDisappears(ruleName string, lb *network.LoadBalancer) resource.TestCheckFunc {
|
||||||
|
return func(s *terraform.State) error {
|
||||||
|
conn := testAccProvider.Meta().(*ArmClient).loadBalancerClient
|
||||||
|
|
||||||
|
_, i, exists := findLoadBalancerRuleByName(lb, ruleName)
|
||||||
|
if !exists {
|
||||||
|
return fmt.Errorf("A Rule with name %q cannot be found.", ruleName)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentRules := *lb.LoadBalancerPropertiesFormat.LoadBalancingRules
|
||||||
|
rules := append(currentRules[:i], currentRules[i+1:]...)
|
||||||
|
lb.LoadBalancerPropertiesFormat.LoadBalancingRules = &rules
|
||||||
|
|
||||||
|
id, err := parseAzureResourceID(*lb.ID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.CreateOrUpdate(id.ResourceGroup, *lb.Name, *lb, make(chan struct{}))
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Error Creating/Updating LoadBalancer %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = conn.Get(id.ResourceGroup, *lb.Name, "")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func testAccAzureRMLoadBalancerRule_basic(rInt int, lbRuleName string) string {
|
func testAccAzureRMLoadBalancerRule_basic(rInt int, lbRuleName string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "azurerm_resource_group" "test" {
|
resource "azurerm_resource_group" "test" {
|
||||||
|
|
Loading…
Reference in New Issue