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

bugfix/deploy-volumes-uri-port-missing-from-read #30

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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![CircleCI](https://circleci.com/gh/packetloop/terraform-provider-singularity.svg?style=svg)](https://circleci.com/gh/packetloop/terraform-provider-singularity)
[![GitHub release](https://img.shields.io/github/release/packetloop/terraform-provider-singularity.svg)](https://github.com/packetloop/terraform-provider-singularity/releases/)
[![All Contributors](https://img.shields.io/github/contributors/packetloop/terraform-provider-singularity.svg?longCache=true&style=flat-square&colorB=orange&label=all%20contributors)](#contributors)
[![Github All Releases](https://img.shields.io/github/downloads/packetloop/terraform-provider-singularity/total.svg)]()

Expand Down
74 changes: 71 additions & 3 deletions mesos_singularity/resource_docker_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,39 @@ func resourceDockerDeployRead(d *schema.ResourceData, m interface{}) error {
d.Set("num_ports", r.Body.PendingDeploy.NumPorts)
d.Set("command", r.Body.PendingDeploy.Command)
d.Set("envs", r.Body.PendingDeploy.TaskEnv)
if r.Body.PendingDeploy.Uris != nil {
mapURI := make([]map[string]interface{}, 0)
for _, a := range r.Body.PendingDeploy.Uris {
m := make(map[string]interface{})
m["cache"] = a.Cache
m["path"] = a.URI
m["extract"] = a.Extract
m["executable"] = a.Executable
mapURI = append(mapURI, m)
}
}
if r.Body.PendingDeploy.ContainerInfo.PortMappings != nil {
mapPort := make([]map[string]interface{}, 0)
for _, a := range r.Body.PendingDeploy.ContainerInfo.PortMappings {
m := make(map[string]interface{})
m["container_port"] = a.ContainerPort
m["container_port_type"] = a.ContainerPortType
m["host_port"] = a.HostPort
m["host_port_type"] = a.HostPortType
m["protocol"] = a.Protocol
mapPort = append(mapPort, m)
}
}
if r.Body.PendingDeploy.ContainerInfo.Volumes != nil {
mapVolumes := make([]map[string]interface{}, 0)
for _, a := range r.Body.PendingDeploy.ContainerInfo.Volumes {
m := make(map[string]interface{})
m["host_path"] = a.HostPath
m["container_path"] = a.ContainerPath
m["mode"] = a.Mode
mapVolumes = append(mapVolumes, m)
}
}
d.Set("port_mapping", r.Body.PendingDeploy.ContainerInfo.DockerInfo.PortMappings)
d.Set("volume", r.Body.PendingDeploy.ContainerInfo.Volumes)
d.Set("uri", r.Body.PendingDeploy.Uris)
Expand All @@ -395,9 +428,44 @@ func resourceDockerDeployRead(d *schema.ResourceData, m interface{}) error {
d.Set("num_ports", r.Body.ActiveDeploy.NumPorts)
d.Set("command", r.Body.ActiveDeploy.Command)
d.Set("envs", r.Body.ActiveDeploy.Env)
d.Set("port_mapping", r.Body.ActiveDeploy.ContainerInfo.DockerInfo.PortMappings)
d.Set("volume", r.Body.ActiveDeploy.ContainerInfo.Volumes)
d.Set("uri", r.Body.ActiveDeploy.Uris)

if r.Body.ActiveDeploy.Uris != nil {
mapURI := make([]map[string]interface{}, 0)
for _, a := range r.Body.ActiveDeploy.Uris {
m := make(map[string]interface{})
m["cache"] = a.Cache
m["path"] = a.URI
m["extract"] = a.Extract
m["executable"] = a.Executable
mapURI = append(mapURI, m)
}
d.Set("uri", mapURI)
}
if r.Body.ActiveDeploy.ContainerInfo.PortMappings != nil {
mapPort := make([]map[string]interface{}, 0)
for _, a := range r.Body.ActiveDeploy.ContainerInfo.PortMappings {
m := make(map[string]interface{})
m["container_port"] = a.ContainerPort
m["container_port_type"] = a.ContainerPortType
m["host_port"] = a.HostPort
m["host_port_type"] = a.HostPortType
m["protocol"] = a.Protocol
mapPort = append(mapPort, m)
}
d.Set("port_mapping", mapPort)
}
if r.Body.ActiveDeploy.ContainerInfo.Volumes != nil {
mapVolumes := make([]map[string]interface{}, 0)
for _, a := range r.Body.ActiveDeploy.ContainerInfo.Volumes {
m := make(map[string]interface{})
m["host_path"] = a.HostPath
m["container_path"] = a.ContainerPath
m["mode"] = a.Mode
mapVolumes = append(mapVolumes, m)
}
d.Set("volume", mapVolumes)
}

d.Set("force_pull_image", r.Body.ActiveDeploy.ContainerInfo.DockerInfo.ForcePullImage)
d.Set("metadata", r.Body.ActiveDeploy.Metadata)
}
Expand Down
5 changes: 2 additions & 3 deletions mesos_singularity/resource_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func resourceRequest() *schema.Resource {
"num_retries_on_failure": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Default: 3,
ForceNew: true,
},
"schedule": &schema.Schema{
Expand Down Expand Up @@ -196,8 +195,8 @@ func resourceRequestRead(d *schema.ResourceData, m interface{}) error {
d.Set("request_type", r.Body.SingularityRequest.RequestType)
d.Set("slave_placement", r.Body.SingularityRequest.SlavePlacement)

// These two types of request does not expect instance number set.
if checkRequestTypeMatch(r.Body, "ON_DEMAND", "RUN_ONCE") {
// Only these three types of request expects instance number set.
if checkRequestTypeMatch(r.Body, "ON_DEMAND", "WORKER", "SERVICE") {
d.Set("instances", r.Body.SingularityRequest.Instances)
}
// Only a scheuled type service expect below parameters.
Expand Down