Skip to content

Commit

Permalink
Clean up in master branch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhijeet Gaiha committed Oct 4, 2017
1 parent 0a3091d commit 0dd53df
Showing 1 changed file with 3 additions and 83 deletions.
86 changes: 3 additions & 83 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,6 @@ func resourceArmContainerGroup() *schema.Resource {
Computed: true,
},

"image_registry_credential": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"server": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"username": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
"password": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
},
},
},
},

"container": {
Type: schema.TypeList,
Required: true,
Expand Down Expand Up @@ -210,8 +185,6 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e
tags := d.Get("tags").(map[string]interface{})

containers, containerGroupPorts, containerGroupVolumes := expandContainerGroupContainers(d)
credentials := expandContainerGroupImageRegistryCredentials(d)

containerGroup := containerinstance.ContainerGroup{
Name: &name,
Location: &location,
Expand All @@ -222,9 +195,8 @@ func resourceArmContainerGroupCreate(d *schema.ResourceData, meta interface{}) e
Type: &IPAddressType,
Ports: containerGroupPorts,
},
OsType: containerinstance.OperatingSystemTypes(OSType),
Volumes: containerGroupVolumes,
ImageRegistryCredentials: credentials,
OsType: containerinstance.OperatingSystemTypes(OSType),
Volumes: containerGroupVolumes,
},
}

Expand Down Expand Up @@ -280,14 +252,8 @@ func resourceArmContainerGroupRead(d *schema.ResourceData, meta interface{}) err
d.Set("ip_address_type", address.Type)
d.Set("ip_address", address.IP)
}

imageRegistryCredentials := flattenContainerGroupImageRegistryCredentials(d, resp.ImageRegistryCredentials)
err = d.Set("image_registry_credential", imageRegistryCredentials)
if err != nil {
return fmt.Errorf("Error setting `image_registry_credential`: %+v", err)
}

if props := resp.ContainerGroupProperties; props != nil {
if props := resp.ContainerGroupProperties; props != nil {
containerConfigs := flattenContainerGroupContainers(d, resp.Containers, props.IPAddress.Ports, props.Volumes)
err = d.Set("container", containerConfigs)
if err != nil {
Expand Down Expand Up @@ -323,29 +289,6 @@ func resourceArmContainerGroupDelete(d *schema.ResourceData, meta interface{}) e
return nil
}

func flattenContainerGroupImageRegistryCredentials(d *schema.ResourceData, credentials *[]containerinstance.ImageRegistryCredential) *[]interface{} {
ircConfigs := make([]interface{}, 0, len(*credentials))
ircConfigsOld := d.Get("image_registry_credential").([]interface{})

for _, irc := range *credentials {
ircConfig := make(map[string]interface{})
ircConfig["server"] = *irc.Server
ircConfig["username"] = *irc.Username
// search for password in the old configs
for _, oldIrcConfig := range ircConfigsOld {
data := oldIrcConfig.(map[string]interface{})
oldServer := data["server"].(string)
if *irc.Server == oldServer {
ircConfig["password"] = data["password"].(string)
}
}

ircConfigs = append(ircConfigs, ircConfig)
}

return &ircConfigs
}

func flattenContainerGroupContainers(d *schema.ResourceData, containers *[]containerinstance.Container, containerGroupPorts *[]containerinstance.Port, containerGroupVolumes *[]containerinstance.Volume) []interface{} {

containerConfigs := make([]interface{}, 0, len(*containers))
Expand Down Expand Up @@ -466,29 +409,6 @@ func flattenContainerVolumes(volumeMounts *[]containerinstance.VolumeMount, cont
return volumeConfigs
}

func expandContainerGroupImageRegistryCredentials(d *schema.ResourceData) *[]containerinstance.ImageRegistryCredential {
credentialsConfig := d.Get("image_registry_credential").([]interface{})
credentials := make([]containerinstance.ImageRegistryCredential, 0, len(credentialsConfig))

for _, credentialConfig := range credentialsConfig {
data := credentialConfig.(map[string]interface{})

server := data["server"].(string)
username := data["username"].(string)
password := data["password"].(string)

credential := containerinstance.ImageRegistryCredential{
Server: &server,
Username: &username,
Password: &password,
}

credentials = append(credentials, credential)
}

return &credentials
}

func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstance.Container, *[]containerinstance.Port, *[]containerinstance.Volume) {
containersConfig := d.Get("container").([]interface{})
containers := make([]containerinstance.Container, 0, len(containersConfig))
Expand Down

0 comments on commit 0dd53df

Please sign in to comment.