diff --git a/octopusdeploy/schema_deployment_action_container.go b/octopusdeploy/schema_deployment_action_container.go index 1e5730248..5fee50bdd 100644 --- a/octopusdeploy/schema_deployment_action_container.go +++ b/octopusdeploy/schema_deployment_action_container.go @@ -6,6 +6,10 @@ import ( ) func expandDeploymentActionContainer(values interface{}) octopusdeploy.DeploymentActionContainer { + if values == nil { + return octopusdeploy.DeploymentActionContainer{} + } + flattenedValues := values.([]interface{}) if len(flattenedValues) == 0 || flattenedValues[0] == nil { return octopusdeploy.DeploymentActionContainer{} @@ -13,10 +17,17 @@ func expandDeploymentActionContainer(values interface{}) octopusdeploy.Deploymen flattenedMap := flattenedValues[0].(map[string]interface{}) - return octopusdeploy.DeploymentActionContainer{ - FeedID: flattenedMap["feed_id"].(string), - Image: flattenedMap["image"].(string), + deploymentActionContainer := octopusdeploy.DeploymentActionContainer{} + + if feedID := flattenedMap["feed_id"]; feedID != nil { + deploymentActionContainer.FeedID = feedID.(string) } + + if image := flattenedMap["image"]; image != nil { + deploymentActionContainer.Image = image.(string) + } + + return deploymentActionContainer } func flattenDeploymentActionContainer(deploymentActionContainer octopusdeploy.DeploymentActionContainer) []interface{} { diff --git a/octopusdeploy/schema_deployment_action_container_test.go b/octopusdeploy/schema_deployment_action_container_test.go new file mode 100644 index 000000000..31967dcb4 --- /dev/null +++ b/octopusdeploy/schema_deployment_action_container_test.go @@ -0,0 +1,42 @@ +package octopusdeploy + +import ( + "testing" + + "github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy" + "github.com/stretchr/testify/require" +) + +func TestExpandDeploymentActionContainer(t *testing.T) { + expected := octopusdeploy.DeploymentActionContainer{} + actual := expandDeploymentActionContainer(nil) + require.Equal(t, expected, actual) + + var emptyInterface interface{} + actual = expandDeploymentActionContainer(emptyInterface) + require.Equal(t, expected, actual) + + var emptyInterfaceArray []interface{} + actual = expandDeploymentActionContainer(emptyInterfaceArray) + require.Equal(t, expected, actual) + + var testMap []interface{} = make([]interface{}, 1) + actual = expandDeploymentActionContainer(testMap) + require.Equal(t, expected, actual) + + testMap[0] = make(map[string]interface{}, 1) + actual = expandDeploymentActionContainer(testMap) + require.Equal(t, expected, actual) + + testMap[0] = map[string]interface{}{ + "feed_id": "feeds-123", + "image": "image-123", + } + expected = octopusdeploy.DeploymentActionContainer{ + FeedID: "feeds-123", + Image: "image-123", + } + actual = expandDeploymentActionContainer(testMap) + + require.Equal(t, expected, actual) +}