Skip to content

Commit

Permalink
Add an option to filter out preview aks releases when fetching versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Isaacs committed Feb 10, 2020
1 parent b7f7eb7 commit 6c56d41
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ func dataSourceArmKubernetesServiceVersions() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"allow_preview": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
},
}
}
Expand All @@ -66,6 +72,7 @@ func dataSourceArmKubernetesServiceVersionsRead(d *schema.ResourceData, meta int

var versions []string
versionPrefix := d.Get("version_prefix").(string)
allowPreview := d.Get("allow_preview").(bool)

if props := listResp.OrchestratorVersionProfileProperties; props != nil {
if orchestrators := props.Orchestrators; orchestrators != nil {
Expand All @@ -74,9 +81,17 @@ func dataSourceArmKubernetesServiceVersionsRead(d *schema.ResourceData, meta int
continue
}

isPreview := false
orchestratorType := *rawV.OrchestratorType
kubeVersion := *rawV.OrchestratorVersion

if rawV.IsPreview == nil {
log.Printf("[DEBUG] IsPreview is nil")
} else {
isPreview = *rawV.IsPreview
log.Printf("[DEBUG] IsPreview is %t", isPreview)
}

if !strings.EqualFold(orchestratorType, "Kubernetes") {
log.Printf("[DEBUG] Orchestrator %q was not Kubernetes", orchestratorType)
continue
Expand All @@ -87,6 +102,11 @@ func dataSourceArmKubernetesServiceVersionsRead(d *schema.ResourceData, meta int
continue
}

if (isPreview) && (allowPreview == false) {
log.Printf("[DEBUG] Orchestrator %q is a preview release, ignoring", kubeVersion)
continue
}

versions = append(versions, kubeVersion)
v, err := version.NewVersion(kubeVersion)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,27 @@ func TestAccDataSourceAzureRMKubernetesServiceVersions_filtered(t *testing.T) {
})
}

func TestAccDataSourceAzureRMKubernetesServiceVersions_nopreview(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_service_versions", "test")
kvrx := regexp.MustCompile(k8sVersionRX)

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceAzureRMKubernetesServiceVersions_nopreview(data),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(data.ResourceName, "versions.#"),
resource.TestMatchResourceAttr(data.ResourceName, "versions.0", kvrx),
resource.TestCheckResourceAttrSet(data.ResourceName, "latest_version"),
resource.TestMatchResourceAttr(data.ResourceName, "latest_version", kvrx),
),
},
},
})
}

func testAccDataSourceAzureRMKubernetesServiceVersions_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
data "azurerm_kubernetes_service_versions" "test" {
Expand All @@ -69,3 +90,12 @@ data "azurerm_kubernetes_service_versions" "test" {
}
`, data.Locations.Primary)
}

func testAccDataSourceAzureRMKubernetesServiceVersions_nopreview(data acceptance.TestData) string {
return fmt.Sprintf(`
data "azurerm_kubernetes_service_versions" "test" {
location = "%s"
allow_preview = false
}
`, data.Locations.Primary)
}

0 comments on commit 6c56d41

Please sign in to comment.