Skip to content

Commit

Permalink
WIP Container groups resource
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijeet Gaiha committed Sep 6, 2017
1 parent 51356a4 commit b95a618
Showing 1 changed file with 30 additions and 38 deletions.
68 changes: 30 additions & 38 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func resourceArmContainerGroup() *schema.Resource {
return &schema.Resource{
Create: resourceArmContainerGroupCreate,
Read: resourceArmContainerGroupRead,
Update: resourceArmContainerGroupCreate,
Delete: resourceArmContainerGroupDelete,

Schema: map[string]*schema.Schema{
Expand All @@ -31,18 +30,20 @@ func resourceArmContainerGroup() *schema.Resource {
},

"ip_address_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"os_type": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: ignoreCaseDiffSuppressFunc,
},

"tags": tagsSchema(),
"tags": tagsForceNewSchema(),

"ip_address": {
Type: schema.TypeString,
Expand Down Expand Up @@ -107,13 +108,7 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e
name := d.Get("name").(string)
location := d.Get("location").(string)
OSType := d.Get("os_type").(string)
if OSType == "" {
OSType = "linux"
}
IPAddressType := d.Get("ip_address_type").(string)
if IPAddressType == "" {
IPAddressType = "public"
}
tags := d.Get("tags").(map[string]interface{})

containersConfig := d.Get("container").([]interface{})
Expand Down Expand Up @@ -164,27 +159,6 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e
containers[index] = container
}

// type ContainerGroupProperties struct {
// ProvisioningState *string `json:"provisioningState,omitempty"`
// Containers *[]Container `json:"containers,omitempty"`
// ImageRegistryCredentials *[]ImageRegistryCredential `json:"imageRegistryCredentials,omitempty"`
// RestartPolicy ContainerRestartPolicy `json:"restartPolicy,omitempty"`
// IPAddress *IPAddress `json:"ipAddress,omitempty"`
// OsType OperatingSystemTypes `json:"osType,omitempty"`
// State *string `json:"state,omitempty"`
// Volumes *[]Volume `json:"volumes,omitempty"`
// }

// type ContainerProperties struct {
// Image *string `json:"image,omitempty"`
// Command *[]string `json:"command,omitempty"`
// Ports *[]ContainerPort `json:"ports,omitempty"`
// EnvironmentVariables *[]EnvironmentVariable `json:"environmentVariables,omitempty"`
// InstanceView *ContainerPropertiesInstanceView `json:"instanceView,omitempty"`
// Resources *ResourceRequirements `json:"resources,omitempty"`
// VolumeMounts *[]VolumeMount `json:"volumeMounts,omitempty"`
// }

containerGroup := containerinstance.ContainerGroup{
Name: &name,
Location: &location,
Expand Down Expand Up @@ -215,7 +189,7 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e

d.SetId(*read.ID)

return nil
return resourceArmContainerGroupRead(d, meta)
}
func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*ArmClient)
Expand Down Expand Up @@ -245,8 +219,26 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err
d.Set("ip_address_type", *resp.IPAddress.Type)
d.Set("ip_address", *resp.IPAddress.IP)

// ports := *resp.IPAddress.Ports
// containers := *resp.Containers
ports := *resp.IPAddress.Ports
containers := *resp.Containers

containerConfigs := make([]interface{}, 0, len(containers))
for index, container := range containers {
containerConfig := make(map[string]interface{})
containerConfig["name"] = *container.Name
containerConfig["image"] = *container.Image

resourceRequests := *(*container.Resources).Requests
containerConfig["cpu"] = *resourceRequests.CPU
containerConfig["memory"] = *resourceRequests.MemoryInGB

containerConfig["port"] = *(*container.Ports)[0].Port
containerConfig["protocol"] = string(ports[index].Protocol)

containerConfigs = append(containerConfigs, containerConfig)
}

d.Set("container", containerConfigs)

return nil
}
Expand Down

0 comments on commit b95a618

Please sign in to comment.