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

Container Service Api server authorized ip ranges #3262

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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 @@ -19,7 +19,7 @@ import (
"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-10-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/containerservice/mgmt/2019-02-01/containerservice"
"github.com/Azure/azure-sdk-for-go/services/cosmos-db/mgmt/2015-04-08/documentdb"
"github.com/Azure/azure-sdk-for-go/services/databricks/mgmt/2018-04-01/databricks"
"github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory"
Expand Down
4 changes: 2 additions & 2 deletions azurerm/data_source_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2018-03-31/containerservice"
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-02-01/containerservice"
"github.com/hashicorp/terraform/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/kubernetes"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
Expand Down Expand Up @@ -612,7 +612,7 @@ func flattenKubernetesClusterDataSourceLinuxProfile(input *containerservice.Linu
return []interface{}{values}
}

func flattenKubernetesClusterDataSourceNetworkProfile(profile *containerservice.NetworkProfile) []interface{} {
func flattenKubernetesClusterDataSourceNetworkProfile(profile *containerservice.NetworkProfileType) []interface{} {
values := make(map[string]interface{})

values["network_plugin"] = profile.NetworkPlugin
Expand Down
2 changes: 1 addition & 1 deletion azurerm/resource_arm_container_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"bytes"

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2018-03-31/containerservice"
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-02-01/containerservice"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema"
Expand Down
69 changes: 69 additions & 0 deletions azurerm/resource_arm_container_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,26 @@ func TestAccAzureRMContainerService_swarmBasic(t *testing.T) {
},
})
}
func TestAccAzureRMContainerService_apiServerAuthorizedIpRanges(t *testing.T) {
ri := tf.AccRandTimeInt()
clientId := os.Getenv("ARM_CLIENT_ID")
clientSecret := os.Getenv("ARM_CLIENT_SECRET")
config := testAccAzureRMContainerService_apiServerAuthorizedIpRanges(ri, clientId, clientSecret, testLocation())

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testCheckAzureRMContainerServiceDestroy,
Steps: []resource.TestStep{
{
Config: config,
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMContainerServiceExists("azurerm_container_service.test"),
),
katbyte marked this conversation as resolved.
Show resolved Hide resolved
},
},
})
}

func testAccAzureRMContainerService_dcosBasic(rInt int, location string) string {
return fmt.Sprintf(`
Expand Down Expand Up @@ -396,6 +416,55 @@ resource "azurerm_container_service" "test" {
`, rInt, location, rInt, rInt, rInt, rInt)
}

func testAccAzureRMContainerService_apiServerAuthorizedIpRanges(rInt int, clientId string, clientSecret string, location string) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}

resource "azurerm_container_service" "test" {
name = "acctestcontservice%d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
orchestration_platform = "Kubernetes"

master_profile {
count = 1
dns_prefix = "acctestmaster%d"
}

linux_profile {
admin_username = "acctestuser%d"

ssh_key {
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCqaZoyiz1qbdOQ8xEf6uEu1cCwYowo5FHtsBhqLoDnnp7KUTEBN+L2NxRIfQ781rxV6Iq5jSav6b2Q8z5KiseOlvKA/RF2wqU0UPYqQviQhLmW6THTpmrv/YkUCuzxDpsH7DUDhZcwySLKVVe0Qm3+5N2Ta6UYH3lsDf9R9wTP2K/+vAnflKebuypNlmocIvakFWoZda18FOmsOoIVXQ8HWFNCuw9ZCunMSN62QGamCe3dL5cXlkgHYv7ekJE15IA9aOJcM7e90oeTqo+7HTcWfdu0qQqPWY5ujyMw/llas8tsXY85LFqRnr3gJ02bAscjc477+X+j/gkpFoN1QEmt [email protected]"
}
}

agent_pool_profile {
name = "default"
count = 1
dns_prefix = "acctestagent%d"
vm_size = "Standard_F2"
}

service_principal {
client_id = "%s"
client_secret = "%s"
}

diagnostics_profile {
enabled = false
}

api_server_authorized_ip_ranges = [
"8.8.8.8/32",
]
}
`, rInt, location, rInt, rInt, rInt, rInt, clientId, clientSecret)
}

func testCheckAzureRMContainerServiceExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
// Ensure we have enough information in state to look up in API
Expand Down
69 changes: 48 additions & 21 deletions azurerm/resource_arm_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"strings"

"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2018-03-31/containerservice"
"github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2019-02-01/containerservice"
"github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/helper/validation"
Expand Down Expand Up @@ -319,8 +319,7 @@ func resourceArmKubernetesCluster() *schema.Resource {
Computed: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
string(containerservice.Calico),
string(containerservice.Azure),
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
string(containerservice.NetworkPolicyCalico),
}, false),
},

Expand Down Expand Up @@ -512,6 +511,15 @@ func resourceArmKubernetesCluster() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"api_server_authorized_ip_ranges": {
Type: schema.TypeList,
katbyte marked this conversation as resolved.
Show resolved Hide resolved
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validate.CIDR,
},
},
},
}
}
Expand Down Expand Up @@ -566,19 +574,22 @@ func resourceArmKubernetesClusterCreateUpdate(d *schema.ResourceData, meta inter
rbacRaw := d.Get("role_based_access_control").([]interface{})
rbacEnabled, azureADProfile := expandKubernetesClusterRoleBasedAccessControl(rbacRaw, tenantId)

apiServerAuthorizedIPRanges := expandApiServerAuthorizedIPRangeInterfaces(d)

parameters := containerservice.ManagedCluster{
Name: &name,
Location: &location,
ManagedClusterProperties: &containerservice.ManagedClusterProperties{
AadProfile: azureADProfile,
AddonProfiles: addonProfiles,
AgentPoolProfiles: &agentProfiles,
DNSPrefix: utils.String(dnsPrefix),
EnableRBAC: utils.Bool(rbacEnabled),
KubernetesVersion: utils.String(kubernetesVersion),
LinuxProfile: linuxProfile,
NetworkProfile: networkProfile,
ServicePrincipalProfile: servicePrincipalProfile,
APIServerAuthorizedIPRanges: apiServerAuthorizedIPRanges,
AadProfile: azureADProfile,
AddonProfiles: addonProfiles,
AgentPoolProfiles: &agentProfiles,
DNSPrefix: utils.String(dnsPrefix),
EnableRBAC: utils.Bool(rbacEnabled),
KubernetesVersion: utils.String(kubernetesVersion),
LinuxProfile: linuxProfile,
NetworkProfile: networkProfile,
ServicePrincipalProfile: servicePrincipalProfile,
},
Tags: expandTags(tags),
}
Expand Down Expand Up @@ -885,12 +896,11 @@ func expandKubernetesClusterAgentPoolProfiles(d *schema.ResourceData) []containe
osType := config["os_type"].(string)

profile := containerservice.ManagedClusterAgentPoolProfile{
Name: utils.String(name),
Count: utils.Int32(count),
VMSize: containerservice.VMSizeTypes(vmSize),
OsDiskSizeGB: utils.Int32(osDiskSizeGB),
StorageProfile: containerservice.ManagedDisks,
OsType: containerservice.OSType(osType),
Name: utils.String(name),
Count: utils.Int32(count),
VMSize: containerservice.VMSizeTypes(vmSize),
OsDiskSizeGB: utils.Int32(osDiskSizeGB),
OsType: containerservice.OSType(osType),
}

if maxPods := int32(config["max_pods"].(int)); maxPods > 0 {
Expand Down Expand Up @@ -1015,7 +1025,7 @@ func flattenKubernetesClusterLinuxProfile(profile *containerservice.LinuxProfile
return []interface{}{values}
}

func expandKubernetesClusterNetworkProfile(d *schema.ResourceData) *containerservice.NetworkProfile {
func expandKubernetesClusterNetworkProfile(d *schema.ResourceData) *containerservice.NetworkProfileType {
configs := d.Get("network_profile").([]interface{})
if len(configs) == 0 {
return nil
Expand All @@ -1027,7 +1037,7 @@ func expandKubernetesClusterNetworkProfile(d *schema.ResourceData) *containerser

networkPolicy := config["network_policy"].(string)

networkProfile := containerservice.NetworkProfile{
networkProfile := containerservice.NetworkProfileType{
NetworkPlugin: containerservice.NetworkPlugin(networkPlugin),
NetworkPolicy: containerservice.NetworkPolicy(networkPolicy),
}
Expand Down Expand Up @@ -1055,7 +1065,7 @@ func expandKubernetesClusterNetworkProfile(d *schema.ResourceData) *containerser
return &networkProfile
}

func flattenKubernetesClusterNetworkProfile(profile *containerservice.NetworkProfile) []interface{} {
func flattenKubernetesClusterNetworkProfile(profile *containerservice.NetworkProfileType) []interface{} {
if profile == nil {
return []interface{}{}
}
Expand Down Expand Up @@ -1261,3 +1271,20 @@ func flattenKubernetesClusterKubeConfigAAD(config kubernetes.KubeConfigAAD) []in

return []interface{}{values}
}

func expandApiServerAuthorizedIPRangeInterfaces(d *schema.ResourceData) *[]string {
tombuildsstuff marked this conversation as resolved.
Show resolved Hide resolved
value, exists := d.GetOk("api_server_authorized_ip_ranges")

if !exists {
return nil
}

apiServerAuthorizedIPRangeConfigs := value.([]interface{})
apiServerAuthorizedIPRanges := make([]string, 0)

for _, element := range apiServerAuthorizedIPRangeConfigs {
apiServerAuthorizedIPRanges = append(apiServerAuthorizedIPRanges, element.(string))
}

return &apiServerAuthorizedIPRanges
}
Loading