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

ACI - added secure environment variables #2024

Merged
merged 24 commits into from
Oct 18, 2018
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d6b3e8b
Container Groups (ACI) - added secure environment variables
neilpeterson Sep 5, 2018
b8c71a8
Fix incomming merge conflict
neilpeterson Sep 7, 2018
8656731
Fix incomming merge conflict
neilpeterson Sep 7, 2018
a9bee2d
Updated variable / value names per PR review request
neilpeterson Oct 4, 2018
f97dac0
rebase with master
neilpeterson Oct 4, 2018
b9cb42a
Clena up vendor
neilpeterson Oct 4, 2018
882321b
Fixing up vendor.json
neilpeterson Oct 4, 2018
14c598b
Updated ACI documentation
neilpeterson Oct 9, 2018
62e3af4
Updated environmetn variabel append routine
neilpeterson Oct 9, 2018
a6d730f
Added slice capacity, removed tabs from test, and fixed vendor.json
neilpeterson Oct 11, 2018
331f71a
Removed unreachable return
neilpeterson Oct 11, 2018
c67f1ca
Fixing up vendor.json
neilpeterson Oct 11, 2018
692f497
Remove old version pacakge for container instance and clean up other …
metacpp Oct 12, 2018
d779d67
Fix the test case issue and styling issue.
metacpp Oct 16, 2018
aedf836
Code changes to fix test issues
WodansSon Oct 16, 2018
7858db1
Merge branch 'master' into container-group-add-secure-variables
WodansSon Oct 17, 2018
dc92a49
Update test to fix conflict
WodansSon Oct 17, 2018
45f92ba
Fixed casing per comment
WodansSon Oct 17, 2018
6b8e25c
Test: ignore the diffing for secure environment variables.
metacpp Oct 17, 2018
f912946
Add more diffing ignores for secure environment variables.
metacpp Oct 17, 2018
0f66616
Updated env var flatten function
WodansSon Oct 17, 2018
0e6d427
Fixed diff issue
WodansSon Oct 18, 2018
6705ded
Added secure_environment_variables validation to tests
WodansSon Oct 18, 2018
8896274
use name to look up index of old container to pull secure values over
katbyte Oct 18, 2018
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
2 changes: 1 addition & 1 deletion azurerm/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/Azure/azure-sdk-for-go/services/cdn/mgmt/2017-10-12/cdn"
"github.com/Azure/azure-sdk-for-go/services/cognitiveservices/mgmt/2017-04-18/cognitiveservices"
"github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2018-06-01/compute"
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-04-01/containerinstance"
"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-06-01/containerinstance"
"github.com/Azure/azure-sdk-for-go/services/containerregistry/mgmt/2017-10-01/containerregistry"
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2018-03-31/containerservice"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb"
Expand Down
54 changes: 45 additions & 9 deletions azurerm/resource_arm_container_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/containerinstance/mgmt/2018-04-01/containerinstance"
"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/utils"
Expand Down Expand Up @@ -169,6 +169,13 @@ func resourceArmContainerGroup() *schema.Resource {
ForceNew: true,
},

"secure_environment_variables": {
Type: schema.TypeMap,
Optional: true,
ForceNew: true,
Sensitive: true,
},

"command": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -564,10 +571,24 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc
containerGroupPorts = append(containerGroupPorts, containerGroupPort)
}

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

if v, ok := data["environment_variables"]; ok {
container.EnvironmentVariables = expandContainerEnvironmentVariables(v)
envVars = expandContainerEnvironmentVariables(v, false)
}

if v, ok := data["secure_environment_variables"]; ok {
secEnvVars = expandContainerEnvironmentVariables(v, true)
}

for _, v := range *secEnvVars {
*envVars = append(*envVars, v)
}

container.EnvironmentVariables = envVars

if v, ok := data["commands"]; ok {
c := v.([]interface{})
command := make([]string, 0)
Expand Down Expand Up @@ -599,18 +620,33 @@ func expandContainerGroupContainers(d *schema.ResourceData) (*[]containerinstanc
return &containers, &containerGroupPorts, &containerGroupVolumes
}

func expandContainerEnvironmentVariables(input interface{}) *[]containerinstance.EnvironmentVariable {
func expandContainerEnvironmentVariables(input interface{}, secure bool) *[]containerinstance.EnvironmentVariable {

envVars := input.(map[string]interface{})
output := make([]containerinstance.EnvironmentVariable, 0)
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved

for k, v := range envVars {
ev := containerinstance.EnvironmentVariable{
Name: utils.String(k),
Value: utils.String(v.(string)),
if secure == true {

for k, v := range envVars {
ev := containerinstance.EnvironmentVariable{
Name: utils.String(k),
SecureValue: utils.String(v.(string)),
}

output = append(output, ev)
}
output = append(output, ev)
}

} else {

for k, v := range envVars {
ev := containerinstance.EnvironmentVariable{
Name: utils.String(k),
Value: utils.String(v.(string)),
}

output = append(output, ev)
}
}
return &output
}

Expand Down
21 changes: 19 additions & 2 deletions azurerm/resource_arm_container_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func TestAccAzureRMContainerGroup_linuxComplete(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.%", "2"),
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo1", "bar1"),
resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.%", "2"),
resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.foo1", "bar1"),
resource.TestCheckResourceAttr(resourceName, "container.0.volume.#", "1"),
resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.mount_path", "/aci/logs"),
resource.TestCheckResourceAttr(resourceName, "container.0.volume.0.name", "logs"),
Expand Down Expand Up @@ -245,6 +248,9 @@ func TestAccAzureRMContainerGroup_windowsComplete(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.%", "2"),
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "container.0.environment_variables.foo1", "bar1"),
resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.%", "2"),
resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.foo", "bar"),
resource.TestCheckResourceAttr(resourceName, "container.0.secure_environment_variables.foo1", "bar1"),
resource.TestCheckResourceAttr(resourceName, "os_type", "Windows"),
resource.TestCheckResourceAttr(resourceName, "restart_policy", "Never"),
),
Expand Down Expand Up @@ -308,7 +314,7 @@ resource "azurerm_container_group" "test" {
memory = "0.5"
port = "80"
}

image_registry_credential {
server = "hub.docker.com"
username = "yourusername"
Expand Down Expand Up @@ -356,7 +362,7 @@ resource "azurerm_container_group" "test" {
memory = "0.5"
port = "80"
}

image_registry_credential {
server = "hub.docker.com"
username = "updatedusername"
Expand Down Expand Up @@ -469,6 +475,12 @@ resource "azurerm_container_group" "test" {
"foo" = "bar"
"foo1" = "bar1"
}

secure_environment_variables {
"secureFoo" = "secureBar"
"secureFoo1" = "secureBar1"
}
neilpeterson marked this conversation as resolved.
Show resolved Hide resolved

commands = ["cmd.exe", "echo", "hi"]
}

Expand Down Expand Up @@ -536,6 +548,11 @@ resource "azurerm_container_group" "test" {
"foo1" = "bar1"
}

secure_environment_variables {
"secureFoo" = "secureBar"
"secureFoo1" = "secureBar1"
}

commands = ["/bin/bash", "-c", "ls"]
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading