@@ -494,6 +494,40 @@ func TestAccKubernetesProvider_config_path(t *testing.T) {
494494 PlanOnly : true ,
495495 ExpectNonEmptyPlan : true ,
496496 },
497+ {
498+ Config : testAccKubernetesProviderConfig (
499+ providerConfig_config_path ("./missing/file" ),
500+ ),
501+ ExpectError : regexp .MustCompile ("could not open kubeconfig" ),
502+ PlanOnly : true ,
503+ ExpectNonEmptyPlan : true ,
504+ },
505+ {
506+ Config : testAccKubernetesProviderConfig (
507+ providerConfig_config_path ("./testdata/kubeconfig" ) +
508+ providerConfig_token ("test-token" ),
509+ ),
510+ ExpectError : regexp .MustCompile (`"config_path": conflicts with token` ),
511+ PlanOnly : true ,
512+ ExpectNonEmptyPlan : true ,
513+ },
514+ {
515+ Config : testAccKubernetesProviderConfig (
516+ providerConfig_config_path ("./testdata/kubeconfig" ) +
517+ providerConfig_host ("test-host" ),
518+ ),
519+ ExpectError : regexp .MustCompile (`"config_path": conflicts with host` ),
520+ PlanOnly : true ,
521+ ExpectNonEmptyPlan : true ,
522+ },
523+ {
524+ Config : testAccKubernetesProviderConfig (
525+ providerConfig_config_path ("./testdata/kubeconfig" ) +
526+ providerConfig_config_context ("test-context" ),
527+ ),
528+ PlanOnly : true ,
529+ ExpectNonEmptyPlan : true ,
530+ },
497531 },
498532 })
499533}
@@ -503,6 +537,21 @@ func TestAccKubernetesProvider_config_paths(t *testing.T) {
503537 PreCheck : func () { testAccPreCheckInternal (t ) },
504538 ProviderFactories : testAccProviderFactoriesInternal ,
505539 Steps : []resource.TestStep {
540+ {
541+ Config : testAccKubernetesProviderConfig (
542+ providerConfig_config_paths (`["./testdata/kubeconfig"]` ),
543+ ),
544+ PlanOnly : true ,
545+ ExpectNonEmptyPlan : true ,
546+ },
547+ {
548+ Config : testAccKubernetesProviderConfig (
549+ providerConfig_config_paths (`["./testdata/kubeconfig"]` ) +
550+ providerConfig_config_context ("test-context" ),
551+ ),
552+ PlanOnly : true ,
553+ ExpectNonEmptyPlan : true ,
554+ },
506555 {
507556 Config : testAccKubernetesProviderConfig (
508557 providerConfig_config_paths (`["./missing/file", "./testdata/kubeconfig"]` ),
@@ -583,6 +632,31 @@ func TestAccKubernetesProvider_config_paths_env_wantError(t *testing.T) {
583632 })
584633}
585634
635+ func TestAccKubernetesProvider_config_paths_host_env_wantError (t * testing.T ) {
636+ wantError := `"config_paths": conflicts with host`
637+
638+ resource .Test (t , resource.TestCase {
639+ PreCheck : func () {
640+ testAccPreCheckInternal_setEnv (t , map [string ]string {
641+ "KUBE_CONFIG_PATHS" : strings .Join ([]string {
642+ "./testdata/kubeconfig" ,
643+ "./testdata/kubeconfig" ,
644+ }, string (os .PathListSeparator )),
645+ "KUBE_HOST" : "test-host" ,
646+ })
647+ },
648+ ProviderFactories : testAccProviderFactoriesInternal ,
649+ Steps : []resource.TestStep {
650+ {
651+ Config : testAccKubernetesProviderConfig ("# empty" ),
652+ ExpectError : regexp .MustCompile (wantError ),
653+ PlanOnly : true ,
654+ ExpectNonEmptyPlan : true ,
655+ },
656+ },
657+ })
658+ }
659+
586660// testAccKubernetesProviderConfig is used together with the providerConfig_* functions
587661// to assemble a Kubernetes provider configuration with interchangeable options.
588662func testAccKubernetesProviderConfig (providerConfig string ) string {
@@ -605,43 +679,49 @@ func providerConfig_config_path(path string) string {
605679` , path )
606680}
607681
682+ func providerConfig_config_context (context string ) string {
683+ return fmt .Sprintf (`
684+ config_context = "%s"
685+ ` , context )
686+ }
687+
608688func providerConfig_config_paths (paths string ) string {
609689 return fmt .Sprintf (`
610690 config_paths = %s
611691` , paths )
612692}
613693
614- func testAccKubernetesProviderConfig_token (token string ) string {
694+ func providerConfig_token (token string ) string {
615695 return fmt .Sprintf (`
616- token = %s
696+ token = "%s"
617697` , token )
618698}
619699
620- func testAccKubernetesProviderConfig_ca_cert (ca_cert string ) string {
700+ func providerConfig_ca_cert (ca_cert string ) string {
621701 return fmt .Sprintf (`
622- cluster_ca_certificate = %s
702+ cluster_ca_certificate = "%s"
623703` , ca_cert )
624704}
625705
626- func testAccKubernetesProviderConfig_client_cert (client_cert string ) string {
706+ func providerConfig_client_cert (client_cert string ) string {
627707 return fmt .Sprintf (`
628- client_certificate = %s
708+ client_certificate = "%s"
629709` , client_cert )
630710}
631711
632- func testAccKubernetesProviderConfig_client_key (client_key string ) string {
712+ func providerConfig_client_key (client_key string ) string {
633713 return fmt .Sprintf (`
634- client_key = %s
714+ client_key = "%s"
635715` , client_key )
636716}
637717
638- func testAccKubernetesProviderConfig_host (host string ) string {
718+ func providerConfig_host (host string ) string {
639719 return fmt .Sprintf (`
640- host = %s
720+ host = "%s"
641721` , host )
642722}
643723
644- func testAccKubernetesProvider_exec (clusterName string ) string {
724+ func provider_exec (clusterName string ) string {
645725 return fmt .Sprintf (`
646726 exec {
647727 api_version = "client.authentication.k8s.io/v1alpha1"
0 commit comments