Provider Docker: (#6376)
- Add option keep_locally - Add unit test - Add documentation
This commit is contained in:
parent
813f2ca708
commit
e4a1d21a4b
|
@ -26,6 +26,11 @@ func resourceDockerImage() *schema.Resource {
|
|||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
|
||||
"keep_locally": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,6 +63,11 @@ func searchLocalImages(data Data, imageName string) *dc.APIImages {
|
|||
|
||||
func removeImage(d *schema.ResourceData, client *dc.Client) error {
|
||||
var data Data
|
||||
|
||||
if keepLocally := d.Get("keep_locally").(bool); keepLocally {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := fetchLocalImages(&data, client); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -44,9 +44,36 @@ func TestAccDockerImage_private(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func testAccDockerImageDestroy(s *terraform.State) error {
|
||||
//client := testAccProvider.Meta().(*dc.Client)
|
||||
func TestAccDockerImage_destroy(t *testing.T) {
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: func(s *terraform.State) error {
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "docker_image" {
|
||||
continue
|
||||
}
|
||||
|
||||
client := testAccProvider.Meta().(*dc.Client)
|
||||
_, err := client.InspectImage(rs.Primary.Attributes["latest"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
},
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: testAccDockerImageKeepLocallyConfig,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestMatchResourceAttr("docker_image.foobarzoo", "latest", contentDigestRegexp),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func testAccDockerImageDestroy(s *terraform.State) error {
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "docker_image" {
|
||||
continue
|
||||
|
@ -76,3 +103,10 @@ resource "docker_image" "foobar" {
|
|||
keep_updated = true
|
||||
}
|
||||
`
|
||||
|
||||
const testAccDockerImageKeepLocallyConfig = `
|
||||
resource "docker_image" "foobarzoo" {
|
||||
name = "crux:3.1"
|
||||
keep_locally = true
|
||||
}
|
||||
`
|
||||
|
|
|
@ -33,6 +33,9 @@ The following arguments are supported:
|
|||
always be updated on the host to the latest. If this is false, as long as an
|
||||
image is downloaded with the correct tag, it won't be redownloaded if
|
||||
there is a newer image.
|
||||
* `keep_locally` - (Optional, boolean) If true, then the Docker image won't be
|
||||
deleted on destroy operation. If this is false, it will delete the image from
|
||||
the docker local storage on destroy operation.
|
||||
|
||||
## Attributes Reference
|
||||
|
||||
|
|
Loading…
Reference in New Issue