Skip to content

Commit

Permalink
Fixing the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Jul 25, 2018
1 parent a72f105 commit 8e8f39e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion azurerm/data_source_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func TestAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenet(t *test
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
location := testLocation()
config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingAzure(ri, clientId, clientSecret, location)
config := testAccDataSourceAzureRMKubernetesCluster_advancedNetworkingKubenet(ri, clientId, clientSecret, location)

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
32 changes: 14 additions & 18 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ func resourceArmKubernetesCluster() *schema.Resource {
return nil
}

// ensure all Agent Pool Profiles are attached to a network
if rawAgentPools, exists := diff.GetOk("agent_pool_profile"); exists {
attachedToASubnet := false
for _, ap := range rawAgentPools.([]interface{}) {
agentPool := ap.(map[string]interface{})
if subnetId, ok := agentPool["vnet_subnet_id"]; ok && subnetId != "" {
attachedToASubnet = true
break
}
}

if !attachedToASubnet {
return fmt.Errorf("If a `network_profile` block is specified, the Agent Pools must be attached to a Subnet")
}
}

// then ensure the conditionally-required fields are set
profile := rawProfiles[0].(map[string]interface{})
networkPlugin := profile["network_plugin"].(string)
Expand Down Expand Up @@ -262,8 +246,8 @@ func resourceArmKubernetesCluster() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"azure",
"kubenet",
string(containerservice.Azure),
string(containerservice.Kubenet),
}, false),
},

Expand Down Expand Up @@ -322,6 +306,18 @@ func resourceArmKubernetesClusterCreate(d *schema.ResourceData, meta interface{}

tags := d.Get("tags").(map[string]interface{})

// we can't do this in the CustomizeDiff since the interpolations aren't evaluated at that point
if networkProfile != nil {
// ensure there's a Subnet ID attached
if networkProfile.NetworkPlugin == containerservice.Azure {
for _, profile := range agentProfiles {
if profile.VnetSubnetID == nil {
return fmt.Errorf("A `vnet_subnet_id` must be specified when the `network_plugin` is set to `azure`.")
}
}
}
}

parameters := containerservice.ManagedCluster{
Name: &name,
Location: &location,
Expand Down
4 changes: 2 additions & 2 deletions azurerm/resource_arm_kubernetes_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func TestAccAzureRMKubernetesCluster_advancedNetworkingKubenet(t *testing.T) {
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"),
resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "kubenet"),
),
},
},
Expand All @@ -217,7 +217,7 @@ func TestAccAzureRMKubernetesCluster_advancedNetworkingKubenetComplete(t *testin
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMKubernetesClusterExists(resourceName),
resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "azure"),
resource.TestCheckResourceAttr(resourceName, "network_profile.0.network_plugin", "kubenet"),
),
},
},
Expand Down

0 comments on commit 8e8f39e

Please sign in to comment.