From 7b133ad356a553c573a9675af0c0493ba76873f4 Mon Sep 17 00:00:00 2001 From: Andreas Kyrris Date: Mon, 17 Oct 2016 18:21:30 +0100 Subject: [PATCH] Fix id of azurerm_lb_backend_address_pool, azurerm_lb_rule, azurerm_lb_nat_rule, azurerm_lb_nat_pool. --- ...ource_arm_loadbalancer_backend_address_pool.go | 15 +++++++++++++-- .../azurerm/resource_arm_loadbalancer_nat_pool.go | 15 +++++++++++++-- .../azurerm/resource_arm_loadbalancer_nat_rule.go | 15 +++++++++++++-- .../azurerm/resource_arm_loadbalancer_rule.go | 15 +++++++++++++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go b/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go index 84ca293f71e4..7109c4d3b484 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_backend_address_pool.go @@ -100,7 +100,18 @@ func resourceArmLoadBalancerBackendAddressPoolCreate(d *schema.ResourceData, met return fmt.Errorf("Cannot read LoadBalancer %s (resource group %s) ID", loadBalancerName, resGroup) } - d.SetId(*read.ID) + var pool_id string + for _, element := range *(*read.Properties).BackendAddressPools { + if *element.Name == d.Get("name").(string) { + pool_id = *element.ID + } + } + + if pool_id != "" { + d.SetId(pool_id) + } else { + return fmt.Errorf("Error can not find created loadbalacner backend address pool id %s", pool_id) + } log.Printf("[DEBUG] Waiting for LoadBalancer (%s) to become available", loadBalancerName) stateConf := &resource.StateChangeConf{ @@ -117,7 +128,7 @@ func resourceArmLoadBalancerBackendAddressPoolCreate(d *schema.ResourceData, met } func resourceArmLoadBalancerBackendAddressPoolRead(d *schema.ResourceData, meta interface{}) error { - loadBalancer, exists, err := retrieveLoadBalancerById(d.Id(), meta) + loadBalancer, exists, err := retrieveLoadBalancerById(d.Get("loadbalancer_id").(string), meta) if err != nil { return errwrap.Wrapf("Error Getting LoadBalancer By ID {{err}}", err) } diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go index 50868624b4c6..3b563b63422c 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go @@ -122,7 +122,18 @@ func resourceArmLoadBalancerNatPoolCreate(d *schema.ResourceData, meta interface return fmt.Errorf("Cannot read LoadBalancer %s (resource group %s) ID", loadBalancerName, resGroup) } - d.SetId(*read.ID) + var natPool_id string + for _, element := range *(*read.Properties).InboundNatPools { + if *element.Name == d.Get("name").(string) { + natPool_id = *element.ID + } + } + + if natPool_id != "" { + d.SetId(natPool_id) + } else { + return fmt.Errorf("Error can not find created loadbalancer nat pool id %s", natPool_id) + } log.Printf("[DEBUG] Waiting for LoadBalancer (%s) to become available", loadBalancerName) stateConf := &resource.StateChangeConf{ @@ -139,7 +150,7 @@ func resourceArmLoadBalancerNatPoolCreate(d *schema.ResourceData, meta interface } func resourceArmLoadBalancerNatPoolRead(d *schema.ResourceData, meta interface{}) error { - loadBalancer, exists, err := retrieveLoadBalancerById(d.Id(), meta) + loadBalancer, exists, err := retrieveLoadBalancerById(d.Get("loadbalancer_id").(string), meta) if err != nil { return errwrap.Wrapf("Error Getting LoadBalancer By ID {{err}}", err) } diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go index 717dd1d33d7d..58a74c43281a 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go @@ -122,7 +122,18 @@ func resourceArmLoadBalancerNatRuleCreate(d *schema.ResourceData, meta interface return fmt.Errorf("Cannot read LoadBalancer %s (resource group %s) ID", loadBalancerName, resGroup) } - d.SetId(*read.ID) + var natRule_id string + for _, element := range *(*read.Properties).InboundNatRules { + if *element.Name == d.Get("name").(string) { + natRule_id = *element.ID + } + } + + if natRule_id != "" { + d.SetId(natRule_id) + } else { + return fmt.Errorf("Error can not find created loadbalancer nat rule id %s", natRule_id) + } log.Printf("[DEBUG] Waiting for LoadBalancer (%s) to become available", loadBalancerName) stateConf := &resource.StateChangeConf{ @@ -139,7 +150,7 @@ func resourceArmLoadBalancerNatRuleCreate(d *schema.ResourceData, meta interface } func resourceArmLoadBalancerNatRuleRead(d *schema.ResourceData, meta interface{}) error { - loadBalancer, exists, err := retrieveLoadBalancerById(d.Id(), meta) + loadBalancer, exists, err := retrieveLoadBalancerById(d.Get("loadbalancer_id").(string), meta) if err != nil { return errwrap.Wrapf("Error Getting LoadBalancer By ID {{err}}", err) } diff --git a/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go b/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go index edb8f3df5a03..e6e7e34d6053 100644 --- a/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go +++ b/builtin/providers/azurerm/resource_arm_loadbalancer_rule.go @@ -149,7 +149,18 @@ func resourceArmLoadBalancerRuleCreate(d *schema.ResourceData, meta interface{}) return fmt.Errorf("Cannot read LoadBalancer %s (resource group %s) ID", loadBalancerName, resGroup) } - d.SetId(*read.ID) + var rule_id string + for _, element := range *(*read.Properties).LoadBalancingRules { + if *element.Name == d.Get("name").(string) { + rule_id = *element.ID + } + } + + if rule_id != "" { + d.SetId(rule_id) + } else { + return fmt.Errorf("Error can not find created loadbalancer rule id %s", rule_id) + } log.Printf("[DEBUG] Waiting for LoadBalancer (%s) to become available", loadBalancerName) stateConf := &resource.StateChangeConf{ @@ -166,7 +177,7 @@ func resourceArmLoadBalancerRuleCreate(d *schema.ResourceData, meta interface{}) } func resourceArmLoadBalancerRuleRead(d *schema.ResourceData, meta interface{}) error { - loadBalancer, exists, err := retrieveLoadBalancerById(d.Id(), meta) + loadBalancer, exists, err := retrieveLoadBalancerById(d.Get("loadbalancer_id").(string), meta) if err != nil { return errwrap.Wrapf("Error Getting LoadBalancer By ID {{err}}", err) }