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

Adding Ports To Container Groups #1930

Merged
merged 19 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
58 changes: 54 additions & 4 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-06-01/containerinstance"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

Expand Down Expand Up @@ -146,16 +147,48 @@ func resourceArmContainerGroup() *schema.Resource {
},

"port": {
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
ValidateFunc: validation.IntBetween(1, 65535),
Type: schema.TypeInt,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"container.0.ports"},
Deprecated: "Use `ports` instead.",
ValidateFunc: validate.PortNumber,
},
katbyte marked this conversation as resolved.
Show resolved Hide resolved

"ports": {
Type: schema.TypeList,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use a TypeSet here as order doesn't matter? at we shouldn't allow duplicates.

Optional: true,
ForceNew: true,
ConflictsWith: []string{"container.0.port", "container.0.protocol"},
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"protocol": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
Default: string("TCP"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Default: string("TCP"),
Default: string(containerinstance.TCP),

ValidateFunc: validation.StringInSlice([]string{
"tcp",
nathanjsweet marked this conversation as resolved.
Show resolved Hide resolved
"udp",
}, true),
},
"port": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
ValidateFunc: validate.PortNumber,
},
},
},
},
katbyte marked this conversation as resolved.
Show resolved Hide resolved

"protocol": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ConflictsWith: []string{"container.0.ports"},
Deprecated: "Use `ports` instead.",
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
ValidateFunc: validation.StringInSlice([]string{
string(containerinstance.TCP),
Expand Down Expand Up @@ -421,6 +454,23 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc
containerGroupPorts = append(containerGroupPorts, containerGroupPort)
}

if v, ok := data["ports"]; ok {
p := v.([]interface{})
var ports []containerinstance.ContainerPort
for _, v := range p {
portObj := v.(map[string]interface{})
portI := portObj["port"]
port := int32(portI.(int))
protoI := portObj["protocol"]
proto := protoI.(string)
nathanjsweet marked this conversation as resolved.
Show resolved Hide resolved
ports = append(ports, containerinstance.ContainerPort{
Protocol: containerinstance.ContainerNetworkProtocol(strings.ToUpper(proto)),
Port: &port,
})
}
container.Ports = &ports
}

// Set both sensitive and non-secure environment variables
var envVars *[]containerinstance.EnvironmentVariable
var secEnvVars *[]containerinstance.EnvironmentVariable
Expand Down
Loading