mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2025-12-20 22:59:42 -05:00
fix: Add ForceTrue to docker_image name attribute. (#421)
* fix: Add ForceTrue to docker_image name attribute. * fix: Test for docker_image name attribute change does not need to check for specific sha sums.
This commit is contained in:
parent
8bf3f88190
commit
fdd628e915
3 changed files with 39 additions and 0 deletions
|
|
@ -18,6 +18,7 @@ func resourceDockerImage() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Description: "The name of the Docker image, including any tags or SHA256 repo digests.",
|
||||
Required: true,
|
||||
ForceNew: true,
|
||||
},
|
||||
|
||||
"latest": {
|
||||
|
|
|
|||
|
|
@ -233,6 +233,32 @@ func TestAccDockerImage_data_private_config_file_content(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
// Changing the name attribute should also force a change of the dependent docker container
|
||||
// This test fails, if we remove the ForceTrue: true from the name attribute
|
||||
func TestAccDockerImage_name_attr_change(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
ProviderFactories: providerFactories,
|
||||
PreventPostDestroyRefresh: true,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: fmt.Sprintf(loadTestConfiguration(t, RESOURCE, "docker_image", "testAccDockerImageName"), "ubuntu:precise@sha256:18305429afa14ea462f810146ba44d4363ae76e4c8dfc38288cf73aa07485005"),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestMatchResourceAttr("docker_image.ubuntu", "latest", contentDigestRegexp),
|
||||
resource.TestMatchResourceAttr("docker_image.ubuntu", "repo_digest", imageRepoDigestRegexp),
|
||||
),
|
||||
},
|
||||
{
|
||||
Config: fmt.Sprintf(loadTestConfiguration(t, RESOURCE, "docker_image", "testAccDockerImageName"), "ubuntu:jammy@sha256:b6b83d3c331794420340093eb706a6f152d9c1fa51b262d9bf34594887c2c7ac"),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestMatchResourceAttr("docker_image.ubuntu", "latest", contentDigestRegexp),
|
||||
resource.TestMatchResourceAttr("docker_image.ubuntu", "repo_digest", imageRepoDigestRegexp),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccDockerImage_sha265(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
resource.Test(t, resource.TestCase{
|
||||
|
|
|
|||
12
testdata/resources/docker_image/testAccDockerImageName.tf
vendored
Normal file
12
testdata/resources/docker_image/testAccDockerImageName.tf
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
resource "docker_image" "ubuntu" {
|
||||
name = "%s"
|
||||
}
|
||||
|
||||
resource "docker_container" "foo" {
|
||||
depends_on = [
|
||||
docker_image.ubuntu
|
||||
]
|
||||
image = docker_image.ubuntu.latest
|
||||
name = "foobar"
|
||||
command = ["sh", "-c", "while true ;do wait ;done"]
|
||||
}
|
||||
Loading…
Reference in a new issue