Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_container_group - adding restart_policy #827

Merged
merged 7 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/automation/mgmt/2015-10-31/automation"
"github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2017-04-02/cdn"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2017-12-01/compute"
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2017-08-01-preview/containerinstance"
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-02-01-preview/containerinstance"
"github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry"
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2017-09-30/containerservice"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb"
Expand Down
20 changes: 18 additions & 2 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2017-08-01-preview/containerinstance"
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-02-01-preview/containerinstance"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -55,6 +55,19 @@ func resourceArmContainerGroup() *schema.Resource {

"tags": tagsForceNewSchema(),

"restart_policy": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Default: string(containerinstance.Always),
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
ValidateFunc: validation.StringInSlice([]string{
string(containerinstance.Always),
string(containerinstance.Never),
string(containerinstance.OnFailure),
}, true),
},

"ip_address": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -184,14 +197,16 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e
OSType := d.Get("os_type").(string)
IPAddressType := d.Get("ip_address_type").(string)
tags := d.Get("tags").(map[string]interface{})
restartPolicy := d.Get("restart_policy").(string)

containers, containerGroupPorts, containerGroupVolumes := expandContainerGroupContainers(d)
containerGroup := containerinstance.ContainerGroup{
Name: &name,
Location: &location,
Tags: expandTags(tags),
ContainerGroupProperties: &containerinstance.ContainerGroupProperties{
Containers: containers,
Containers: containers,
RestartPolicy: containerinstance.ContainerGroupRestartPolicy(restartPolicy),
IPAddress: &containerinstance.IPAddress{
Type: &IPAddressType,
Ports: containerGroupPorts,
Expand Down Expand Up @@ -254,6 +269,7 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err
d.Set("ip_address_type", address.Type)
d.Set("ip_address", address.IP)
}
d.Set("restart_policy", string(resp.RestartPolicy))

if props := resp.ContainerGroupProperties; props != nil {
containerConfigs := flattenContainerGroupContainers(d, resp.Containers, props.IPAddress.Ports, props.Volumes)
Expand Down
4 changes: 4 additions & 0 deletions azurerm/resource_arm_container_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.name", "logs"),
resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.read_only", "false"),
resource.TestCheckResourceAttr(resourceName, "os_type", "Linux"),
resource.TestCheckResourceAttr(resourceName, "restart_policy", "OnFailure"),
),
},
},
Expand Down Expand Up @@ -139,6 +140,7 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo1", "bar1"),
resource.TestCheckResourceAttr(resourceName, "os_type", "Windows"),
resource.TestCheckResourceAttr(resourceName, "restart_policy", "Never"),
),
},
},
Expand Down Expand Up @@ -252,6 +254,7 @@ resource "azurerm_container_group" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
ip_address_type = "public"
os_type = "windows"
restart_policy = "Never"

container {
name = "windowsservercore"
Expand Down Expand Up @@ -303,6 +306,7 @@ resource "azurerm_container_group" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
ip_address_type = "public"
os_type = "linux"
restart_policy = "OnFailure"

container {
name = "hf"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading