mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-02-03 20:29:30 -05:00
Fix a serious problem when using links.
Links cause there to be more than one name for a container to be returned. As a result, only looking at the first element of the container names could cause a container to not be found, leading Terraform to remove it from state and attempt to recreate it.
This commit is contained in:
parent
40fed60ec4
commit
fc6ef37d95
1 changed files with 11 additions and 9 deletions
|
|
@ -211,15 +211,17 @@ func fetchDockerContainer(name string, client *dc.Client) (*dc.APIContainers, er
|
|||
// Sometimes the Docker API prefixes container names with /
|
||||
// like it does in these commands. But if there's no
|
||||
// set name, it just uses the ID without a /...ugh.
|
||||
var dockerContainerName string
|
||||
if len(apiContainer.Names) > 0 {
|
||||
dockerContainerName = strings.TrimLeft(apiContainer.Names[0], "/")
|
||||
} else {
|
||||
dockerContainerName = apiContainer.ID
|
||||
}
|
||||
|
||||
if dockerContainerName == name {
|
||||
return &apiContainer, nil
|
||||
switch len(apiContainer.Names) {
|
||||
case 0:
|
||||
if apiContainer.ID == name {
|
||||
return &apiContainer, nil
|
||||
}
|
||||
default:
|
||||
for _, containerName := range apiContainer.Names {
|
||||
if strings.TrimLeft(containerName, "/") == name {
|
||||
return &apiContainer, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue