Skip to content

Commit

Permalink
Fix id of azurerm_lb_backend_address_pool, azurerm_lb_rule, azurerm_l…
Browse files Browse the repository at this point in the history
…b_nat_rule, azurerm_lb_nat_pool.
  • Loading branch information
Andreas Kyrris committed Oct 18, 2016
1 parent 4a22fa0 commit 7b133ad
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
Expand Down
15 changes: 13 additions & 2 deletions builtin/providers/azurerm/resource_arm_loadbalancer_nat_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
Expand Down
15 changes: 13 additions & 2 deletions builtin/providers/azurerm/resource_arm_loadbalancer_nat_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
Expand Down
15 changes: 13 additions & 2 deletions builtin/providers/azurerm/resource_arm_loadbalancer_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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)
}
Expand Down

0 comments on commit 7b133ad

Please sign in to comment.