From 2858cdb318a38a3924f5216d070d472ed37e0a66 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 11 Feb 2019 19:21:57 -0800 Subject: [PATCH 1/3] correctly list containers --- azurerm/resource_arm_storage_container.go | 26 ++++++++++++++++------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/azurerm/resource_arm_storage_container.go b/azurerm/resource_arm_storage_container.go index d3984c4f1ed9..e3f271a5151a 100644 --- a/azurerm/resource_arm_storage_container.go +++ b/azurerm/resource_arm_storage_container.go @@ -174,20 +174,30 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e return nil } - containers, err := blobClient.ListContainers(storage.ListContainersParameters{ + var container *storage.Container + listParams := storage.ListContainersParameters{ Prefix: id.containerName, Timeout: 90, - }) - if err != nil { - return fmt.Errorf("Failed to retrieve storage containers in account %q: %s", id.containerName, err) } - var container *storage.Container - for _, cont := range containers.Containers { - if cont.Name == id.containerName { - container = &cont + for { + resp, err := blobClient.ListContainers(listParams) + if err != nil { + return fmt.Errorf("Failed to retrieve storage resp in account %q: %s", id.containerName, err) + } + + for _, c := range resp.Containers { + if c.Name == id.containerName { + container = &c + break + } + } + + if resp.NextMarker == "" { break } + + listParams.Marker = resp.NextMarker } if container == nil { From a79f8eb992d3c5dbfd3e09917ff3368c002407e7 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 11 Feb 2019 19:23:41 -0800 Subject: [PATCH 2/3] correctly list containers --- azurerm/resource_arm_storage_container.go | 38 ++++++----------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/azurerm/resource_arm_storage_container.go b/azurerm/resource_arm_storage_container.go index e3f271a5151a..d1a0b8202767 100644 --- a/azurerm/resource_arm_storage_container.go +++ b/azurerm/resource_arm_storage_container.go @@ -174,30 +174,10 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e return nil } - var container *storage.Container - listParams := storage.ListContainersParameters{ - Prefix: id.containerName, - Timeout: 90, - } - - for { - resp, err := blobClient.ListContainers(listParams) - if err != nil { - return fmt.Errorf("Failed to retrieve storage resp in account %q: %s", id.containerName, err) - } - - for _, c := range resp.Containers { - if c.Name == id.containerName { - container = &c - break - } - } - - if resp.NextMarker == "" { - break - } - listParams.Marker = resp.NextMarker + resp := blobClient.GetContainerReference(id.containerName) + if err != nil { + return fmt.Errorf("Failed to retrieve storage resp in account %q: %s", id.containerName, err) } if container == nil { @@ -211,18 +191,18 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e d.Set("resource_group_name", resourceGroup) // for historical reasons, "private" above is an empty string in the API - if container.Properties.PublicAccess == storage.ContainerAccessTypePrivate { + if resp.Properties.PublicAccess == storage.ContainerAccessTypePrivate { d.Set("container_access_type", "private") } else { - d.Set("container_access_type", string(container.Properties.PublicAccess)) + d.Set("container_access_type", string(resp.Properties.PublicAccess)) } output := make(map[string]interface{}) - output["last_modified"] = container.Properties.LastModified - output["lease_status"] = container.Properties.LeaseStatus - output["lease_state"] = container.Properties.LeaseState - output["lease_duration"] = container.Properties.LeaseDuration + output["last_modified"] = resp.Properties.LastModified + output["lease_status"] = resp.Properties.LeaseStatus + output["lease_state"] = resp.Properties.LeaseState + output["lease_duration"] = resp.Properties.LeaseDuration if err := d.Set("properties", output); err != nil { return fmt.Errorf("Error setting `properties`: %+v", err) From 27fea31db86ecbd721f20232b43062ae316f9311 Mon Sep 17 00:00:00 2001 From: kt Date: Mon, 11 Feb 2019 21:23:33 -0800 Subject: [PATCH 3/3] make fmt --- azurerm/resource_arm_storage_container.go | 38 +++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/azurerm/resource_arm_storage_container.go b/azurerm/resource_arm_storage_container.go index d1a0b8202767..e3f271a5151a 100644 --- a/azurerm/resource_arm_storage_container.go +++ b/azurerm/resource_arm_storage_container.go @@ -174,10 +174,30 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e return nil } + var container *storage.Container + listParams := storage.ListContainersParameters{ + Prefix: id.containerName, + Timeout: 90, + } - resp := blobClient.GetContainerReference(id.containerName) - if err != nil { - return fmt.Errorf("Failed to retrieve storage resp in account %q: %s", id.containerName, err) + for { + resp, err := blobClient.ListContainers(listParams) + if err != nil { + return fmt.Errorf("Failed to retrieve storage resp in account %q: %s", id.containerName, err) + } + + for _, c := range resp.Containers { + if c.Name == id.containerName { + container = &c + break + } + } + + if resp.NextMarker == "" { + break + } + + listParams.Marker = resp.NextMarker } if container == nil { @@ -191,18 +211,18 @@ func resourceArmStorageContainerRead(d *schema.ResourceData, meta interface{}) e d.Set("resource_group_name", resourceGroup) // for historical reasons, "private" above is an empty string in the API - if resp.Properties.PublicAccess == storage.ContainerAccessTypePrivate { + if container.Properties.PublicAccess == storage.ContainerAccessTypePrivate { d.Set("container_access_type", "private") } else { - d.Set("container_access_type", string(resp.Properties.PublicAccess)) + d.Set("container_access_type", string(container.Properties.PublicAccess)) } output := make(map[string]interface{}) - output["last_modified"] = resp.Properties.LastModified - output["lease_status"] = resp.Properties.LeaseStatus - output["lease_state"] = resp.Properties.LeaseState - output["lease_duration"] = resp.Properties.LeaseDuration + output["last_modified"] = container.Properties.LastModified + output["lease_status"] = container.Properties.LeaseStatus + output["lease_state"] = container.Properties.LeaseState + output["lease_duration"] = container.Properties.LeaseDuration if err := d.Set("properties", output); err != nil { return fmt.Errorf("Error setting `properties`: %+v", err)