diff --git a/kubernetes/resource_kubernetes_secret.go b/kubernetes/resource_kubernetes_secret.go index a543eaadd8..1bb72dcd32 100644 --- a/kubernetes/resource_kubernetes_secret.go +++ b/kubernetes/resource_kubernetes_secret.go @@ -49,7 +49,7 @@ func resourceKubernetesSecretCreate(d *schema.ResourceData, meta interface{}) er metadata := expandMetadata(d.Get("metadata").([]interface{})) secret := api.Secret{ ObjectMeta: metadata, - StringData: expandStringMap(d.Get("data").(map[string]interface{})), + Data: expandStringMapToByteMap(d.Get("data").(map[string]interface{})), } if v, ok := d.GetOk("type"); ok { diff --git a/kubernetes/resource_kubernetes_secret_test.go b/kubernetes/resource_kubernetes_secret_test.go index 43cbb7c0b3..ae73d1053d 100644 --- a/kubernetes/resource_kubernetes_secret_test.go +++ b/kubernetes/resource_kubernetes_secret_test.go @@ -189,6 +189,34 @@ func TestAccKubernetesSecret_importGeneratedName(t *testing.T) { }) } +func TestAccKubernetesSecret_binaryData(t *testing.T) { + var conf api.Secret + prefix := "tf-acc-test-gen-" + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + IDRefreshName: "kubernetes_secret.test", + Providers: testAccProviders, + CheckDestroy: testAccCheckKubernetesSecretDestroy, + Steps: []resource.TestStep{ + { + Config: testAccKubernetesSecretConfig_binaryData(prefix), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesSecretExists("kubernetes_secret.test", &conf), + resource.TestCheckResourceAttr("kubernetes_secret.test", "data.%", "1"), + ), + }, + { + Config: testAccKubernetesSecretConfig_binaryData2(prefix), + Check: resource.ComposeAggregateTestCheckFunc( + testAccCheckKubernetesSecretExists("kubernetes_secret.test", &conf), + resource.TestCheckResourceAttr("kubernetes_secret.test", "data.%", "2"), + ), + }, + }, + }) +} + func testAccCheckSecretData(m *api.Secret, expected map[string]string) resource.TestCheckFunc { return func(s *terraform.State) error { if len(expected) == 0 && len(m.Data) == 0 { @@ -329,3 +357,28 @@ resource "kubernetes_secret" "test" { } }`, prefix) } + +func testAccKubernetesSecretConfig_binaryData(prefix string) string { + return fmt.Sprintf(` +resource "kubernetes_secret" "test" { + metadata { + generate_name = "%s" + } + data { + one = "${file("./test-fixtures/binary.data")}" + } +}`, prefix) +} + +func testAccKubernetesSecretConfig_binaryData2(prefix string) string { + return fmt.Sprintf(` +resource "kubernetes_secret" "test" { + metadata { + generate_name = "%s" + } + data { + one = "${file("./test-fixtures/binary2.data")}" + two = "${file("./test-fixtures/binary.data")}" + } +}`, prefix) +} diff --git a/kubernetes/structures.go b/kubernetes/structures.go index 1905b24034..6e3627c637 100644 --- a/kubernetes/structures.go +++ b/kubernetes/structures.go @@ -72,6 +72,14 @@ func expandStringMap(m map[string]interface{}) map[string]string { return result } +func expandStringMapToByteMap(m map[string]interface{}) map[string][]byte { + result := make(map[string][]byte) + for k, v := range m { + result[k] = []byte(v.(string)) + } + return result +} + func expandStringSlice(s []interface{}) []string { result := make([]string, len(s), len(s)) for k, v := range s { diff --git a/kubernetes/test-fixtures/binary.data b/kubernetes/test-fixtures/binary.data new file mode 100644 index 0000000000..60d1233756 Binary files /dev/null and b/kubernetes/test-fixtures/binary.data differ diff --git a/kubernetes/test-fixtures/binary2.data b/kubernetes/test-fixtures/binary2.data new file mode 100644 index 0000000000..e896830136 Binary files /dev/null and b/kubernetes/test-fixtures/binary2.data differ