From cea3d284dcabc74c18c2b121a23e5d4063a126ff Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Mon, 14 Feb 2022 11:10:35 +0800 Subject: [PATCH 01/11] add code --- .teamcity/components/generated/services.kt | 1 + internal/clients/client.go | 3 + internal/provider/services.go | 2 + internal/services/kubernetes/client/client.go | 20 ++ .../kubernetes_connected_cluster_resource.go | 206 +++++++++++++ ...ernetes_connected_cluster_resource_test.go | 192 ++++++++++++ internal/services/kubernetes/registration.go | 29 ++ internal/services/kubernetes/resourceids.go | 3 + .../sdk/2021-10-01/kubernetes/client.go | 15 + .../sdk/2021-10-01/kubernetes/constants.go | 176 +++++++++++ .../kubernetes/id_connectedcluster.go | 124 ++++++++ .../kubernetes/id_connectedcluster_test.go | 279 ++++++++++++++++++ .../method_connectedclustercreate_autorest.go | 75 +++++ .../method_connectedclusterdelete_autorest.go | 74 +++++ .../method_connectedclusterget_autorest.go | 64 ++++ ...ctedclusterlistbyresourcegroup_autorest.go | 184 ++++++++++++ ...ectedclusterlistbysubscription_autorest.go | 184 ++++++++++++ ...usterlistclusterusercredential_autorest.go | 66 +++++ .../method_connectedclusterupdate_autorest.go | 65 ++++ .../kubernetes/model_connectedcluster.go | 16 + .../kubernetes/model_connectedclusterpatch.go | 6 + .../model_connectedclusterproperties.go | 46 +++ .../kubernetes/model_credentialresult.go | 6 + .../kubernetes/model_credentialresults.go | 6 + .../model_hybridconnectionconfig.go | 8 + ...del_listclusterusercredentialproperties.go | 6 + .../2021-10-01/kubernetes/model_systemdata.go | 40 +++ .../sdk/2021-10-01/kubernetes/predicates.go | 29 ++ .../sdk/2021-10-01/kubernetes/version.go | 9 + website/allowed-subcategories | 1 + ...kubernetes_connected_cluster.html.markdown | 98 ++++++ 31 files changed, 2033 insertions(+) create mode 100644 internal/services/kubernetes/client/client.go create mode 100644 internal/services/kubernetes/kubernetes_connected_cluster_resource.go create mode 100644 internal/services/kubernetes/kubernetes_connected_cluster_resource_test.go create mode 100644 internal/services/kubernetes/registration.go create mode 100644 internal/services/kubernetes/resourceids.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/constants.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster_test.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclustercreate_autorest.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterdelete_autorest.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterget_autorest.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbyresourcegroup_autorest.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbysubscription_autorest.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistclusterusercredential_autorest.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterupdate_autorest.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedcluster.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterpatch.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterproperties.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresult.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresults.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_hybridconnectionconfig.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_listclusterusercredentialproperties.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_systemdata.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/predicates.go create mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go create mode 100644 website/docs/r/kubernetes_connected_cluster.html.markdown diff --git a/.teamcity/components/generated/services.kt b/.teamcity/components/generated/services.kt index 0119bb49002b..57dcfe9c2a02 100644 --- a/.teamcity/components/generated/services.kt +++ b/.teamcity/components/generated/services.kt @@ -49,6 +49,7 @@ var services = mapOf( "iotcentral" to "IoT Central", "iothub" to "IoT Hub", "keyvault" to "KeyVault", + "kubernetes" to "Kubernetes", "kusto" to "Kusto", "lighthouse" to "Lighthouse", "loadbalancer" to "Load Balancer", diff --git a/internal/clients/client.go b/internal/clients/client.go index 0dfed7662fe5..cc2811c70d6f 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -56,6 +56,7 @@ import ( iothub "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub/client" timeseriesinsights "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights/client" keyvault "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/client" + kubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/client" kusto "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/client" lighthouse "github.com/hashicorp/terraform-provider-azurerm/internal/services/lighthouse/client" loadbalancers "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/client" @@ -166,6 +167,7 @@ type Client struct { IoTHub *iothub.Client IoTTimeSeriesInsights *timeseriesinsights.Client KeyVault *keyvault.Client + Kubernetes *kubernetes.Client Kusto *kusto.Client Lighthouse *lighthouse.Client LoadBalancers *loadbalancers.Client @@ -278,6 +280,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.IoTHub = iothub.NewClient(o) client.IoTTimeSeriesInsights = timeseriesinsights.NewClient(o) client.KeyVault = keyvault.NewClient(o) + client.Kubernetes = kubernetes.NewClient(o) client.Kusto = kusto.NewClient(o) client.Lighthouse = lighthouse.NewClient(o) client.LogAnalytics = loganalytics.NewClient(o) diff --git a/internal/provider/services.go b/internal/provider/services.go index e8f81814dcf4..7325026b61e7 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -52,6 +52,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights" "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto" "github.com/hashicorp/terraform-provider-azurerm/internal/services/lighthouse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer" @@ -181,6 +182,7 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration { iothub.Registration{}, iotcentral.Registration{}, keyvault.Registration{}, + kubernetes.Registration{}, kusto.Registration{}, loadbalancer.Registration{}, loganalytics.Registration{}, diff --git a/internal/services/kubernetes/client/client.go b/internal/services/kubernetes/client/client.go new file mode 100644 index 000000000000..fae08c50dd34 --- /dev/null +++ b/internal/services/kubernetes/client/client.go @@ -0,0 +1,20 @@ +package client + +import ( + "github.com/hashicorp/terraform-provider-azurerm/internal/common" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/sdk/2021-10-01/kubernetes" +) + +type Client struct { + KubernetesClient *kubernetes.KubernetesClient +} + +func NewClient(o *common.ClientOptions) *Client { + + kubernetesClient := kubernetes.NewKubernetesClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&kubernetesClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + KubernetesClient: &kubernetesClient, + } +} diff --git a/internal/services/kubernetes/kubernetes_connected_cluster_resource.go b/internal/services/kubernetes/kubernetes_connected_cluster_resource.go new file mode 100644 index 000000000000..6914ec865dce --- /dev/null +++ b/internal/services/kubernetes/kubernetes_connected_cluster_resource.go @@ -0,0 +1,206 @@ +package kubernetes + +import ( + "fmt" + "time" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" + "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/location" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/sdk/2021-10-01/kubernetes" + "github.com/hashicorp/terraform-provider-azurerm/internal/tags" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +func resourceKubernetesConnectedCluster() *pluginsdk.Resource { + return &pluginsdk.Resource{ + Create: resourceKubernetesConnectedClusterCreate, + Read: resourceKubernetesConnectedClusterRead, + Update: resourceKubernetesConnectedClusterUpdate, + Delete: resourceKubernetesConnectedClusterDelete, + + Timeouts: &pluginsdk.ResourceTimeout{ + Create: pluginsdk.DefaultTimeout(30 * time.Minute), + Read: pluginsdk.DefaultTimeout(5 * time.Minute), + Update: pluginsdk.DefaultTimeout(30 * time.Minute), + Delete: pluginsdk.DefaultTimeout(30 * time.Minute), + }, + + Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { + _, err := kubernetes.ParseConnectedClusterID(id) + return err + }), + + Schema: map[string]*pluginsdk.Schema{ + "name": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "resource_group_name": azure.SchemaResourceGroupName(), + + "agent_public_key_certificate": { + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + }, + + "distribution": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + }, + + "identity": commonschema.SystemAssignedIdentityRequired(), + + "infrastructure": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + }, + + "location": azure.SchemaLocation(), + + "provisioning_state": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "tags": tags.Schema(), + }, + } +} + +func resourceKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kubernetes.KubernetesClient + subscriptionId := meta.(*clients.Client).Account.SubscriptionId + ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id := kubernetes.NewConnectedClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + + if d.IsNewResource() { + existing, err := client.ConnectedClusterGet(ctx, id) + if err != nil { + if !response.WasNotFound(existing.HttpResponse) { + return fmt.Errorf("checking for existing %s: %+v", id, err) + } + } + + if !response.WasNotFound(existing.HttpResponse) { + return tf.ImportAsExistsError("azurerm_kubernetes_connected_cluster", id.ID()) + } + } + + identity, err := identity.ExpandSystemAssigned(d.Get("identity").([]interface{})) + if err != nil { + return fmt.Errorf("expanding `identity`: %+v", err) + } + + location := azure.NormalizeLocation(d.Get("location")) + props := kubernetes.ConnectedCluster{ + Identity: *identity, + Location: location, + Properties: kubernetes.ConnectedClusterProperties{ + AgentPublicKeyCertificate: d.Get("agent_public_key_certificate").(string), + Distribution: utils.String(d.Get("distribution").(string)), + Infrastructure: utils.String(d.Get("infrastructure").(string)), + }, + Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + } + + if err := client.ConnectedClusterCreateThenPoll(ctx, id, props); err != nil { + return fmt.Errorf("creating %s: %+v", id, err) + } + + d.SetId(id.ID()) + return resourceKubernetesConnectedClusterRead(d, meta) +} + +func resourceKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kubernetes.KubernetesClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := kubernetes.ParseConnectedClusterID(d.Id()) + if err != nil { + return err + } + + resp, err := client.ConnectedClusterGet(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + d.SetId("") + return nil + } + + return fmt.Errorf("retrieving %s: %+v", id, err) + } + + d.Set("name", id.ClusterName) + d.Set("resource_group_name", id.ResourceGroupName) + if model := resp.Model; model != nil { + if err := d.Set("identity", identity.FlattenSystemAssigned(&model.Identity)); err != nil { + return fmt.Errorf("setting `identity`: %+v", err) + } + + d.Set("location", location.Normalize(model.Location)) + props := model.Properties + d.Set("agent_public_key_certificate", props.AgentPublicKeyCertificate) + d.Set("distribution", props.Distribution) + d.Set("infrastructure", props.Infrastructure) + d.Set("provisioning_state", props.ProvisioningState) + + if err := tagsHelper.FlattenAndSet(d, model.Tags); err != nil { + return err + } + } + + return nil +} + +func resourceKubernetesConnectedClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kubernetes.KubernetesClient + ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := kubernetes.ParseConnectedClusterID(d.Id()) + if err != nil { + return err + } + + props := kubernetes.ConnectedClusterPatch{ + Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), + } + + if _, err := client.ConnectedClusterUpdate(ctx, *id, props); err != nil { + return fmt.Errorf("updating %s: %+v", id, err) + } + + return resourceKubernetesConnectedClusterRead(d, meta) +} + +func resourceKubernetesConnectedClusterDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).Kubernetes.KubernetesClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := kubernetes.ParseConnectedClusterID(d.Id()) + if err != nil { + return err + } + + if err := client.ConnectedClusterDeleteThenPoll(ctx, *id); err != nil { + return fmt.Errorf("deleting %s: %+v", id, err) + } + + return nil +} diff --git a/internal/services/kubernetes/kubernetes_connected_cluster_resource_test.go b/internal/services/kubernetes/kubernetes_connected_cluster_resource_test.go new file mode 100644 index 000000000000..05690a567172 --- /dev/null +++ b/internal/services/kubernetes/kubernetes_connected_cluster_resource_test.go @@ -0,0 +1,192 @@ +package kubernetes_test + +import ( + "context" + "fmt" + "testing" + + "github.com/hashicorp/go-azure-helpers/lang/response" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" + "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" + "github.com/hashicorp/terraform-provider-azurerm/internal/clients" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/sdk/2021-10-01/kubernetes" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/utils" +) + +type KubernetesConnectedClusterResource struct{} + +func TestAccKubernetesConnectedCluster_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") + r := KubernetesConnectedClusterResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccKubernetesConnectedCluster_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") + r := KubernetesConnectedClusterResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.basic(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.RequiresImportErrorStep(r.requiresImport), + }) +} + +func TestAccKubernetesConnectedCluster_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") + r := KubernetesConnectedClusterResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func TestAccKubernetesConnectedCluster_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") + r := KubernetesConnectedClusterResource{} + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.complete(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + { + Config: r.update(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + ), + }, + data.ImportStep(), + }) +} + +func (r KubernetesConnectedClusterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := kubernetes.ParseConnectedClusterID(state.ID) + if err != nil { + return nil, err + } + + client := clients.Kubernetes.KubernetesClient + resp, err := client.ConnectedClusterGet(ctx, *id) + if err != nil { + if response.WasNotFound(resp.HttpResponse) { + return utils.Bool(false), nil + } + return nil, fmt.Errorf("retrieving %s: %+v", id, err) + } + return utils.Bool(true), nil +} + +func (r KubernetesConnectedClusterResource) template(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctest-kubernetes-%d" + location = "%s" +} +`, data.RandomInteger, data.Locations.Primary) +} + +func (r KubernetesConnectedClusterResource) basic(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_kubernetes_connected_cluster" "test" { + name = "acctest-k-%d" + resource_group_name = azurerm_resource_group.test.name + agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" + identity { + type = "SystemAssigned" + } + location = "%s" +} +`, template, data.RandomInteger, data.Locations.Primary) +} + +func (r KubernetesConnectedClusterResource) requiresImport(data acceptance.TestData) string { + config := r.basic(data) + return fmt.Sprintf(` + %s + +resource "azurerm_kubernetes_connected_cluster" "import" { + name = azurerm_kubernetes_connected_cluster.test.name + resource_group_name = azurerm_resource_group.test.name + agent_public_key_certificate = azurerm_kubernetes_connected_cluster.test.agent_public_key_certificate + identity { + type = "SystemAssigned" + } + location = azurerm_kubernetes_connected_cluster.test.location +} +`, config) +} + +func (r KubernetesConnectedClusterResource) complete(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_kubernetes_connected_cluster" "test" { + name = "acctest-k-%d" + resource_group_name = azurerm_resource_group.test.name + agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" + distribution = "kind" + + identity { + type = "SystemAssigned" + } + infrastructure = "generic" + location = "%s" + + tags = { + ENV = "Test" + } +} +`, template, data.RandomInteger, data.Locations.Primary) +} + +func (r KubernetesConnectedClusterResource) update(data acceptance.TestData) string { + template := r.template(data) + return fmt.Sprintf(` + %s + +resource "azurerm_kubernetes_connected_cluster" "test" { + name = "acctest-k-%d" + resource_group_name = azurerm_resource_group.test.name + agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" + distribution = "kind" + + identity { + type = "SystemAssigned" + } + infrastructure = "generic" + location = "%s" + + tags = { + ENV = "TestUpdate" + } +} +`, template, data.RandomInteger, data.Locations.Primary) +} diff --git a/internal/services/kubernetes/registration.go b/internal/services/kubernetes/registration.go new file mode 100644 index 000000000000..46204bb2726e --- /dev/null +++ b/internal/services/kubernetes/registration.go @@ -0,0 +1,29 @@ +package kubernetes + +import "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + +type Registration struct{} + +// Name is the name of this Service +func (r Registration) Name() string { + return "Kubernetes" +} + +// WebsiteCategories returns a list of categories which can be used for the sidebar +func (r Registration) WebsiteCategories() []string { + return []string{ + "Kubernetes", + } +} + +// SupportedDataSources returns the supported Data Sources supported by this Service +func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{} +} + +// SupportedResources returns the supported Resources supported by this Service +func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { + return map[string]*pluginsdk.Resource{ + "azurerm_kubernetes_connected_cluster": resourceKubernetesConnectedCluster(), + } +} diff --git a/internal/services/kubernetes/resourceids.go b/internal/services/kubernetes/resourceids.go new file mode 100644 index 000000000000..afa9e3b5a03e --- /dev/null +++ b/internal/services/kubernetes/resourceids.go @@ -0,0 +1,3 @@ +package kubernetes + +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=KubernetesConnectedCluster -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go new file mode 100644 index 000000000000..2855a1b76b6a --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go @@ -0,0 +1,15 @@ +package kubernetes + +import "github.com/Azure/go-autorest/autorest" + +type KubernetesClient struct { + Client autorest.Client + baseUri string +} + +func NewKubernetesClientWithBaseURI(endpoint string) KubernetesClient { + return KubernetesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/constants.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/constants.go new file mode 100644 index 000000000000..834ddb83ae4f --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/constants.go @@ -0,0 +1,176 @@ +package kubernetes + +import "strings" + +type AuthenticationMethod string + +const ( + AuthenticationMethodAAD AuthenticationMethod = "AAD" + AuthenticationMethodToken AuthenticationMethod = "Token" +) + +func PossibleValuesForAuthenticationMethod() []string { + return []string{ + string(AuthenticationMethodAAD), + string(AuthenticationMethodToken), + } +} + +func parseAuthenticationMethod(input string) (*AuthenticationMethod, error) { + vals := map[string]AuthenticationMethod{ + "aad": AuthenticationMethodAAD, + "token": AuthenticationMethodToken, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AuthenticationMethod(input) + return &out, nil +} + +type ConnectivityStatus string + +const ( + ConnectivityStatusConnected ConnectivityStatus = "Connected" + ConnectivityStatusConnecting ConnectivityStatus = "Connecting" + ConnectivityStatusExpired ConnectivityStatus = "Expired" + ConnectivityStatusOffline ConnectivityStatus = "Offline" +) + +func PossibleValuesForConnectivityStatus() []string { + return []string{ + string(ConnectivityStatusConnected), + string(ConnectivityStatusConnecting), + string(ConnectivityStatusExpired), + string(ConnectivityStatusOffline), + } +} + +func parseConnectivityStatus(input string) (*ConnectivityStatus, error) { + vals := map[string]ConnectivityStatus{ + "connected": ConnectivityStatusConnected, + "connecting": ConnectivityStatusConnecting, + "expired": ConnectivityStatusExpired, + "offline": ConnectivityStatusOffline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectivityStatus(input) + return &out, nil +} + +type CreatedByType string + +const ( + CreatedByTypeApplication CreatedByType = "Application" + CreatedByTypeKey CreatedByType = "Key" + CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" + CreatedByTypeUser CreatedByType = "User" +) + +func PossibleValuesForCreatedByType() []string { + return []string{ + string(CreatedByTypeApplication), + string(CreatedByTypeKey), + string(CreatedByTypeManagedIdentity), + string(CreatedByTypeUser), + } +} + +func parseCreatedByType(input string) (*CreatedByType, error) { + vals := map[string]CreatedByType{ + "application": CreatedByTypeApplication, + "key": CreatedByTypeKey, + "managedidentity": CreatedByTypeManagedIdentity, + "user": CreatedByTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := CreatedByType(input) + return &out, nil +} + +type LastModifiedByType string + +const ( + LastModifiedByTypeApplication LastModifiedByType = "Application" + LastModifiedByTypeKey LastModifiedByType = "Key" + LastModifiedByTypeManagedIdentity LastModifiedByType = "ManagedIdentity" + LastModifiedByTypeUser LastModifiedByType = "User" +) + +func PossibleValuesForLastModifiedByType() []string { + return []string{ + string(LastModifiedByTypeApplication), + string(LastModifiedByTypeKey), + string(LastModifiedByTypeManagedIdentity), + string(LastModifiedByTypeUser), + } +} + +func parseLastModifiedByType(input string) (*LastModifiedByType, error) { + vals := map[string]LastModifiedByType{ + "application": LastModifiedByTypeApplication, + "key": LastModifiedByTypeKey, + "managedidentity": LastModifiedByTypeManagedIdentity, + "user": LastModifiedByTypeUser, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := LastModifiedByType(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster.go new file mode 100644 index 000000000000..3b8c1ce299ea --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster.go @@ -0,0 +1,124 @@ +package kubernetes + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ConnectedClusterId{} + +// ConnectedClusterId is a struct representing the Resource ID for a Connected Cluster +type ConnectedClusterId struct { + SubscriptionId string + ResourceGroupName string + ClusterName string +} + +// NewConnectedClusterID returns a new ConnectedClusterId struct +func NewConnectedClusterID(subscriptionId string, resourceGroupName string, clusterName string) ConnectedClusterId { + return ConnectedClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ClusterName: clusterName, + } +} + +// ParseConnectedClusterID parses 'input' into a ConnectedClusterId +func ParseConnectedClusterID(input string) (*ConnectedClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(ConnectedClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ConnectedClusterId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ClusterName, ok = parsed.Parsed["clusterName"]; !ok { + return nil, fmt.Errorf("the segment 'clusterName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseConnectedClusterIDInsensitively parses 'input' case-insensitively into a ConnectedClusterId +// note: this method should only be used for API response data and not user input +func ParseConnectedClusterIDInsensitively(input string) (*ConnectedClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(ConnectedClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ConnectedClusterId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ClusterName, ok = parsed.Parsed["clusterName"]; !ok { + return nil, fmt.Errorf("the segment 'clusterName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateConnectedClusterID checks that 'input' can be parsed as a Connected Cluster ID +func ValidateConnectedClusterID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseConnectedClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Cluster ID +func (id ConnectedClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Kubernetes/connectedClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Cluster ID +func (id ConnectedClusterId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKubernetes", "Microsoft.Kubernetes", "Microsoft.Kubernetes"), + resourceids.StaticSegment("staticConnectedClusters", "connectedClusters", "connectedClusters"), + resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), + } +} + +// String returns a human-readable description of this Connected Cluster ID +func (id ConnectedClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Cluster Name: %q", id.ClusterName), + } + return fmt.Sprintf("Connected Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster_test.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster_test.go new file mode 100644 index 000000000000..85c6566331cc --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster_test.go @@ -0,0 +1,279 @@ +package kubernetes + +import ( + "testing" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +var _ resourceids.ResourceId = ConnectedClusterId{} + +func TestNewConnectedClusterID(t *testing.T) { + id := NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") + + if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { + t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") + } + + if id.ResourceGroupName != "example-resource-group" { + t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") + } + + if id.ClusterName != "clusterValue" { + t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") + } +} + +func TestFormatConnectedClusterID(t *testing.T) { + actual := NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() + expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue" + if actual != expected { + t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) + } +} + +func TestParseConnectedClusterID(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedClusterId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue", + Expected: &ConnectedClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedClusterID(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestParseConnectedClusterIDInsensitively(t *testing.T) { + testData := []struct { + Input string + Error bool + Expected *ConnectedClusterId + }{ + { + // Incomplete URI + Input: "", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS", + Error: true, + }, + { + // Incomplete URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters", + Error: true, + }, + { + // Incomplete URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS/cOnNeCtEdClUsTeRs", + Error: true, + }, + { + // Valid URI + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue", + Expected: &ConnectedClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "example-resource-group", + ClusterName: "clusterValue", + }, + }, + { + // Invalid (Valid Uri with Extra segment) + Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue/extra", + Error: true, + }, + { + // Valid URI (mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS/cOnNeCtEdClUsTeRs/cLuStErVaLuE", + Expected: &ConnectedClusterId{ + SubscriptionId: "12345678-1234-9876-4563-123456789012", + ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", + ClusterName: "cLuStErVaLuE", + }, + }, + { + // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) + Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS/cOnNeCtEdClUsTeRs/cLuStErVaLuE/extra", + Error: true, + }, + } + for _, v := range testData { + t.Logf("[DEBUG] Testing %q", v.Input) + + actual, err := ParseConnectedClusterIDInsensitively(v.Input) + if err != nil { + if v.Error { + continue + } + + t.Fatalf("Expect a value but got an error: %+v", err) + } + if v.Error { + t.Fatal("Expect an error but didn't get one") + } + + if actual.SubscriptionId != v.Expected.SubscriptionId { + t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) + } + + if actual.ResourceGroupName != v.Expected.ResourceGroupName { + t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) + } + + if actual.ClusterName != v.Expected.ClusterName { + t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) + } + + } +} + +func TestSegmentsForConnectedClusterId(t *testing.T) { + segments := ConnectedClusterId{}.Segments() + if len(segments) == 0 { + t.Fatalf("ConnectedClusterId has no segments") + } + + uniqueNames := make(map[string]struct{}, 0) + for _, segment := range segments { + uniqueNames[segment.Name] = struct{}{} + } + if len(uniqueNames) != len(segments) { + t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) + } +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclustercreate_autorest.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclustercreate_autorest.go new file mode 100644 index 000000000000..98d10d873363 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclustercreate_autorest.go @@ -0,0 +1,75 @@ +package kubernetes + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +type ConnectedClusterCreateResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ConnectedClusterCreate ... +func (c KubernetesClient) ConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (result ConnectedClusterCreateResponse, err error) { + req, err := c.preparerForConnectedClusterCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterCreate", nil, "Failure preparing request") + return + } + + result, err = c.senderForConnectedClusterCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterCreate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ConnectedClusterCreateThenPoll performs ConnectedClusterCreate then polls until it's completed +func (c KubernetesClient) ConnectedClusterCreateThenPoll(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) error { + result, err := c.ConnectedClusterCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ConnectedClusterCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ConnectedClusterCreate: %+v", err) + } + + return nil +} + +// preparerForConnectedClusterCreate prepares the ConnectedClusterCreate request. +func (c KubernetesClient) preparerForConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForConnectedClusterCreate sends the ConnectedClusterCreate request. The method will close the +// http.Response Body if it receives an error. +func (c KubernetesClient) senderForConnectedClusterCreate(ctx context.Context, req *http.Request) (future ConnectedClusterCreateResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + future.Poller, err = polling.NewLongRunningPollerFromResponse(ctx, resp, c.Client) + return +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterdelete_autorest.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterdelete_autorest.go new file mode 100644 index 000000000000..34abe80ff92e --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterdelete_autorest.go @@ -0,0 +1,74 @@ +package kubernetes + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +type ConnectedClusterDeleteResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ConnectedClusterDelete ... +func (c KubernetesClient) ConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterDeleteResponse, err error) { + req, err := c.preparerForConnectedClusterDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForConnectedClusterDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ConnectedClusterDeleteThenPoll performs ConnectedClusterDelete then polls until it's completed +func (c KubernetesClient) ConnectedClusterDeleteThenPoll(ctx context.Context, id ConnectedClusterId) error { + result, err := c.ConnectedClusterDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing ConnectedClusterDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ConnectedClusterDelete: %+v", err) + } + + return nil +} + +// preparerForConnectedClusterDelete prepares the ConnectedClusterDelete request. +func (c KubernetesClient) preparerForConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForConnectedClusterDelete sends the ConnectedClusterDelete request. The method will close the +// http.Response Body if it receives an error. +func (c KubernetesClient) senderForConnectedClusterDelete(ctx context.Context, req *http.Request) (future ConnectedClusterDeleteResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + future.Poller, err = polling.NewLongRunningPollerFromResponse(ctx, resp, c.Client) + return +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterget_autorest.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterget_autorest.go new file mode 100644 index 000000000000..34dfb80496d1 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterget_autorest.go @@ -0,0 +1,64 @@ +package kubernetes + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ConnectedClusterGetResponse struct { + HttpResponse *http.Response + Model *ConnectedCluster +} + +// ConnectedClusterGet ... +func (c KubernetesClient) ConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterGetResponse, err error) { + req, err := c.preparerForConnectedClusterGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForConnectedClusterGet prepares the ConnectedClusterGet request. +func (c KubernetesClient) preparerForConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterGet handles the response to the ConnectedClusterGet request. The method always +// closes the http.Response Body. +func (c KubernetesClient) responderForConnectedClusterGet(resp *http.Response) (result ConnectedClusterGetResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbyresourcegroup_autorest.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbyresourcegroup_autorest.go new file mode 100644 index 000000000000..61a7df5b3410 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbyresourcegroup_autorest.go @@ -0,0 +1,184 @@ +package kubernetes + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +type ConnectedClusterListByResourceGroupResponse struct { + HttpResponse *http.Response + Model *[]ConnectedCluster + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ConnectedClusterListByResourceGroupResponse, error) +} + +type ConnectedClusterListByResourceGroupCompleteResult struct { + Items []ConnectedCluster +} + +func (r ConnectedClusterListByResourceGroupResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ConnectedClusterListByResourceGroupResponse) LoadMore(ctx context.Context) (resp ConnectedClusterListByResourceGroupResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ConnectedClusterListByResourceGroup ... +func (c KubernetesClient) ConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ConnectedClusterListByResourceGroupResponse, err error) { + req, err := c.preparerForConnectedClusterListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForConnectedClusterListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ConnectedClusterListByResourceGroupComplete retrieves all of the results into a single object +func (c KubernetesClient) ConnectedClusterListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ConnectedClusterListByResourceGroupCompleteResult, error) { + return c.ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx, id, ConnectedClusterPredicate{}) +} + +// ConnectedClusterListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c KubernetesClient) ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListByResourceGroupCompleteResult, err error) { + items := make([]ConnectedCluster, 0) + + page, err := c.ConnectedClusterListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ConnectedClusterListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForConnectedClusterListByResourceGroup prepares the ConnectedClusterListByResourceGroup request. +func (c KubernetesClient) preparerForConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Kubernetes/connectedClusters", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForConnectedClusterListByResourceGroupWithNextLink prepares the ConnectedClusterListByResourceGroup request with the given nextLink token. +func (c KubernetesClient) preparerForConnectedClusterListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterListByResourceGroup handles the response to the ConnectedClusterListByResourceGroup request. The method always +// closes the http.Response Body. +func (c KubernetesClient) responderForConnectedClusterListByResourceGroup(resp *http.Response) (result ConnectedClusterListByResourceGroupResponse, err error) { + type page struct { + Values []ConnectedCluster `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListByResourceGroupResponse, err error) { + req, err := c.preparerForConnectedClusterListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbysubscription_autorest.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbysubscription_autorest.go new file mode 100644 index 000000000000..4f0a965082b1 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbysubscription_autorest.go @@ -0,0 +1,184 @@ +package kubernetes + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +type ConnectedClusterListBySubscriptionResponse struct { + HttpResponse *http.Response + Model *[]ConnectedCluster + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ConnectedClusterListBySubscriptionResponse, error) +} + +type ConnectedClusterListBySubscriptionCompleteResult struct { + Items []ConnectedCluster +} + +func (r ConnectedClusterListBySubscriptionResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ConnectedClusterListBySubscriptionResponse) LoadMore(ctx context.Context) (resp ConnectedClusterListBySubscriptionResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ConnectedClusterListBySubscription ... +func (c KubernetesClient) ConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ConnectedClusterListBySubscriptionResponse, err error) { + req, err := c.preparerForConnectedClusterListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForConnectedClusterListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// ConnectedClusterListBySubscriptionComplete retrieves all of the results into a single object +func (c KubernetesClient) ConnectedClusterListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ConnectedClusterListBySubscriptionCompleteResult, error) { + return c.ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx, id, ConnectedClusterPredicate{}) +} + +// ConnectedClusterListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c KubernetesClient) ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListBySubscriptionCompleteResult, err error) { + items := make([]ConnectedCluster, 0) + + page, err := c.ConnectedClusterListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ConnectedClusterListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} + +// preparerForConnectedClusterListBySubscription prepares the ConnectedClusterListBySubscription request. +func (c KubernetesClient) preparerForConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Kubernetes/connectedClusters", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForConnectedClusterListBySubscriptionWithNextLink prepares the ConnectedClusterListBySubscription request with the given nextLink token. +func (c KubernetesClient) preparerForConnectedClusterListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterListBySubscription handles the response to the ConnectedClusterListBySubscription request. The method always +// closes the http.Response Body. +func (c KubernetesClient) responderForConnectedClusterListBySubscription(resp *http.Response) (result ConnectedClusterListBySubscriptionResponse, err error) { + type page struct { + Values []ConnectedCluster `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListBySubscriptionResponse, err error) { + req, err := c.preparerForConnectedClusterListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistclusterusercredential_autorest.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistclusterusercredential_autorest.go new file mode 100644 index 000000000000..09e229386923 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistclusterusercredential_autorest.go @@ -0,0 +1,66 @@ +package kubernetes + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ConnectedClusterListClusterUserCredentialResponse struct { + HttpResponse *http.Response + Model *CredentialResults +} + +// ConnectedClusterListClusterUserCredential ... +func (c KubernetesClient) ConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (result ConnectedClusterListClusterUserCredentialResponse, err error) { + req, err := c.preparerForConnectedClusterListClusterUserCredential(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListClusterUserCredential", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterListClusterUserCredential(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForConnectedClusterListClusterUserCredential prepares the ConnectedClusterListClusterUserCredential request. +func (c KubernetesClient) preparerForConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/listClusterUserCredential", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterListClusterUserCredential handles the response to the ConnectedClusterListClusterUserCredential request. The method always +// closes the http.Response Body. +func (c KubernetesClient) responderForConnectedClusterListClusterUserCredential(resp *http.Response) (result ConnectedClusterListClusterUserCredentialResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterupdate_autorest.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterupdate_autorest.go new file mode 100644 index 000000000000..5ca612cb989b --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterupdate_autorest.go @@ -0,0 +1,65 @@ +package kubernetes + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +type ConnectedClusterUpdateResponse struct { + HttpResponse *http.Response + Model *ConnectedCluster +} + +// ConnectedClusterUpdate ... +func (c KubernetesClient) ConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (result ConnectedClusterUpdateResponse, err error) { + req, err := c.preparerForConnectedClusterUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForConnectedClusterUpdate prepares the ConnectedClusterUpdate request. +func (c KubernetesClient) preparerForConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterUpdate handles the response to the ConnectedClusterUpdate request. The method always +// closes the http.Response Body. +func (c KubernetesClient) responderForConnectedClusterUpdate(resp *http.Response) (result ConnectedClusterUpdateResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + return +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedcluster.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedcluster.go new file mode 100644 index 000000000000..8d1b77e5b500 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedcluster.go @@ -0,0 +1,16 @@ +package kubernetes + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" +) + +type ConnectedCluster struct { + Id *string `json:"id,omitempty"` + Identity identity.SystemAssigned `json:"identity"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties ConnectedClusterProperties `json:"properties"` + SystemData *SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterpatch.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterpatch.go new file mode 100644 index 000000000000..cdf6ca12a058 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterpatch.go @@ -0,0 +1,6 @@ +package kubernetes + +type ConnectedClusterPatch struct { + Properties *interface{} `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterproperties.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterproperties.go new file mode 100644 index 000000000000..8ee77ae749ae --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterproperties.go @@ -0,0 +1,46 @@ +package kubernetes + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +type ConnectedClusterProperties struct { + AgentPublicKeyCertificate string `json:"agentPublicKeyCertificate"` + AgentVersion *string `json:"agentVersion,omitempty"` + ConnectivityStatus *ConnectivityStatus `json:"connectivityStatus,omitempty"` + Distribution *string `json:"distribution,omitempty"` + Infrastructure *string `json:"infrastructure,omitempty"` + KubernetesVersion *string `json:"kubernetesVersion,omitempty"` + LastConnectivityTime *string `json:"lastConnectivityTime,omitempty"` + ManagedIdentityCertificateExpirationTime *string `json:"managedIdentityCertificateExpirationTime,omitempty"` + Offering *string `json:"offering,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + TotalCoreCount *int64 `json:"totalCoreCount,omitempty"` + TotalNodeCount *int64 `json:"totalNodeCount,omitempty"` +} + +func (o ConnectedClusterProperties) GetLastConnectivityTimeAsTime() (*time.Time, error) { + if o.LastConnectivityTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastConnectivityTime, "2006-01-02T15:04:05Z07:00") +} + +func (o ConnectedClusterProperties) SetLastConnectivityTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastConnectivityTime = &formatted +} + +func (o ConnectedClusterProperties) GetManagedIdentityCertificateExpirationTimeAsTime() (*time.Time, error) { + if o.ManagedIdentityCertificateExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ManagedIdentityCertificateExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o ConnectedClusterProperties) SetManagedIdentityCertificateExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ManagedIdentityCertificateExpirationTime = &formatted +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresult.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresult.go new file mode 100644 index 000000000000..6814442b2b30 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresult.go @@ -0,0 +1,6 @@ +package kubernetes + +type CredentialResult struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresults.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresults.go new file mode 100644 index 000000000000..d7319f1be113 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresults.go @@ -0,0 +1,6 @@ +package kubernetes + +type CredentialResults struct { + HybridConnectionConfig *HybridConnectionConfig `json:"hybridConnectionConfig,omitempty"` + Kubeconfigs *[]CredentialResult `json:"kubeconfigs,omitempty"` +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_hybridconnectionconfig.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_hybridconnectionconfig.go new file mode 100644 index 000000000000..7b11962e13e7 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_hybridconnectionconfig.go @@ -0,0 +1,8 @@ +package kubernetes + +type HybridConnectionConfig struct { + ExpirationTime *int64 `json:"expirationTime,omitempty"` + HybridConnectionName *string `json:"hybridConnectionName,omitempty"` + Relay *string `json:"relay,omitempty"` + Token *string `json:"token,omitempty"` +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_listclusterusercredentialproperties.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_listclusterusercredentialproperties.go new file mode 100644 index 000000000000..c4b4ed1da6cf --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_listclusterusercredentialproperties.go @@ -0,0 +1,6 @@ +package kubernetes + +type ListClusterUserCredentialProperties struct { + AuthenticationMethod AuthenticationMethod `json:"authenticationMethod"` + ClientProxy bool `json:"clientProxy"` +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_systemdata.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_systemdata.go new file mode 100644 index 000000000000..bb4142485b4c --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_systemdata.go @@ -0,0 +1,40 @@ +package kubernetes + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +type SystemData struct { + CreatedAt *string `json:"createdAt,omitempty"` + CreatedBy *string `json:"createdBy,omitempty"` + CreatedByType *CreatedByType `json:"createdByType,omitempty"` + LastModifiedAt *string `json:"lastModifiedAt,omitempty"` + LastModifiedBy *string `json:"lastModifiedBy,omitempty"` + LastModifiedByType *LastModifiedByType `json:"lastModifiedByType,omitempty"` +} + +func (o SystemData) GetCreatedAtAsTime() (*time.Time, error) { + if o.CreatedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.CreatedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o SystemData) SetCreatedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.CreatedAt = &formatted +} + +func (o SystemData) GetLastModifiedAtAsTime() (*time.Time, error) { + if o.LastModifiedAt == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastModifiedAt, "2006-01-02T15:04:05Z07:00") +} + +func (o SystemData) SetLastModifiedAtAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastModifiedAt = &formatted +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/predicates.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/predicates.go new file mode 100644 index 000000000000..266ceee4e1a6 --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/predicates.go @@ -0,0 +1,29 @@ +package kubernetes + +type ConnectedClusterPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ConnectedClusterPredicate) Matches(input ConnectedCluster) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go new file mode 100644 index 000000000000..2b84f45b1dec --- /dev/null +++ b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go @@ -0,0 +1,9 @@ +package kubernetes + +import "fmt" + +const defaultApiVersion = "2021-10-01" + +func userAgent() string { + return fmt.Sprintf("pandora/kubernetes/%s", defaultApiVersion) +} diff --git a/website/allowed-subcategories b/website/allowed-subcategories index e1fda4ccd692..bf980f775def 100644 --- a/website/allowed-subcategories +++ b/website/allowed-subcategories @@ -45,6 +45,7 @@ Healthcare IoT Central IoT Hub Key Vault +Kubernetes Lighthouse Load Balancer Load Test diff --git a/website/docs/r/kubernetes_connected_cluster.html.markdown b/website/docs/r/kubernetes_connected_cluster.html.markdown new file mode 100644 index 000000000000..fbc1053f66f9 --- /dev/null +++ b/website/docs/r/kubernetes_connected_cluster.html.markdown @@ -0,0 +1,98 @@ +--- +subcategory: "Kubernetes" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_kubernetes_connected_cluster" +description: |- + Manages a kubernetes connected cluster. +--- + +# azurerm_kubernetes_connected_cluster + +Manages a kubernetes connected cluster. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "example-kubernetes" + location = "West Europe" +} + +resource "azurerm_kubernetes_connected_cluster" "test" { + name = "acctest-k-%d" + resource_group_name = azurerm_resource_group.test.name + agent_public_key_certificate = "xxxxxxxxxxxxxxxxxxx" + distribution = "gke" + + identity = { + type = "SystemAssigned" + } + infrastructure = "gcp" + location = "West Europe" + + tags = { + ENV = "Test" + } +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this Kubernetes Connected Cluster. Changing this forces a new Kubernetes Connected Cluster to be created. + +* `resource_group_name` - (Required) The name of the Resource Group where the kubernetes connected cluster should exist. Changing this forces a new kubernetes connected cluster to be created. + +* `agent_public_key_certificate` - (Required) Base64 encoded public certificate used by the agent to do the initial handshake to the backend services in Azure. Changing this forces a new kubernetes connected cluster to be created. + +* `identity` - (Required) An `identity` block as defined below. + +* `location` - (Required) The Azure Region where the kubernetes connected cluster should exist. Changing this forces a new kubernetes connected cluster to be created. + +* `distribution` - (Optional) The Kubernetes distribution running on this connected cluster. Changing this forces a new kubernetes connected cluster to be created. + +* `infrastructure` - (Optional) The infrastructure on which the Kubernetes cluster represented by this connected cluster is running on. Changing this forces a new kubernetes connected cluster to be created. + +* `tags` - (Optional) A mapping of tags which should be assigned to the kubernetes connected cluster. + +--- + +An `identity` block exports the following: + +* `type` - (Required) Specifies the type of Managed Service Identity. Possible values are `SystemAssigned`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the kubernetes connected cluster. + +* `identity` - An `identity` block as defined below. + +* `provisioning_state` - The current deployment state of connected clusters. + +--- + +An `identity` block exports the following: + +* `principal_id` - The Principal ID associated with this Managed Service Identity. + +* `tenant_id` - The Tenant ID associated with this Managed Service Identity. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the kubernetes connected cluster. +* `read` - (Defaults to 5 minutes) Used when retrieving the kubernetes connected cluster. +* `update` - (Defaults to 30 minutes) Used when updating the kubernetes connected cluster. +* `delete` - (Defaults to 30 minutes) Used when deleting the kubernetes connected cluster. + +## Import + +kubernetes connected cluster can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_kubernetes_connected_cluster.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 +``` From 6110f8518793ab0e4d70c6ca32962cbfde11d11e Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Wed, 16 Feb 2022 10:29:02 +0800 Subject: [PATCH 02/11] rename Kubernetes to HybridKubernetes --- .teamcity/components/generated/services.kt | 2 +- internal/clients/client.go | 6 +- internal/provider/services.go | 4 +- .../hybridkubernetes/client/client.go | 20 ++++ ..._kubernetes_connected_cluster_resource.go} | 52 +++++----- ...rnetes_connected_cluster_resource_test.go} | 61 ++++++------ .../registration.go | 8 +- .../services/hybridkubernetes/resourceids.go | 3 + .../sdk/2021-10-01/hybridkubernetes/client.go | 15 +++ .../2021-10-01/hybridkubernetes}/constants.go | 2 +- .../hybridkubernetes}/id_connectedcluster.go | 2 +- .../id_connectedcluster_test.go | 2 +- .../method_connectedclustercreate_autorest.go | 14 +-- .../method_connectedclusterdelete_autorest.go | 14 +-- .../method_connectedclusterget_autorest.go | 14 +-- ...ctedclusterlistbyresourcegroup_autorest.go | 26 ++--- ...ectedclusterlistbysubscription_autorest.go | 26 ++--- ...usterlistclusterusercredential_autorest.go | 14 +-- .../method_connectedclusterupdate_autorest.go | 14 +-- .../model_connectedcluster.go | 2 +- .../model_connectedclusterpatch.go | 2 +- .../model_connectedclusterproperties.go | 2 +- .../model_credentialresult.go | 2 +- .../model_credentialresults.go | 2 +- .../model_hybridconnectionconfig.go | 2 +- ...del_listclusterusercredentialproperties.go | 2 +- .../hybridkubernetes}/model_systemdata.go | 2 +- .../hybridkubernetes}/predicates.go | 2 +- .../2021-10-01/hybridkubernetes/version.go | 9 ++ internal/services/kubernetes/client/client.go | 20 ---- internal/services/kubernetes/resourceids.go | 3 - .../sdk/2021-10-01/kubernetes/client.go | 15 --- .../sdk/2021-10-01/kubernetes/version.go | 9 -- website/allowed-subcategories | 2 +- ...kubernetes_connected_cluster.html.markdown | 98 +++++++++++++++++++ ...kubernetes_connected_cluster.html.markdown | 98 ------------------- 36 files changed, 286 insertions(+), 285 deletions(-) create mode 100644 internal/services/hybridkubernetes/client/client.go rename internal/services/{kubernetes/kubernetes_connected_cluster_resource.go => hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go} (72%) rename internal/services/{kubernetes/kubernetes_connected_cluster_resource_test.go => hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go} (71%) rename internal/services/{kubernetes => hybridkubernetes}/registration.go (81%) create mode 100644 internal/services/hybridkubernetes/resourceids.go create mode 100644 internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/client.go rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/constants.go (99%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/id_connectedcluster.go (99%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/id_connectedcluster_test.go (99%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/method_connectedclustercreate_autorest.go (64%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/method_connectedclusterdelete_autorest.go (66%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/method_connectedclusterget_autorest.go (60%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/method_connectedclusterlistbyresourcegroup_autorest.go (69%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/method_connectedclusterlistbysubscription_autorest.go (69%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/method_connectedclusterlistclusterusercredential_autorest.go (58%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/method_connectedclusterupdate_autorest.go (59%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_connectedcluster.go (96%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_connectedclusterpatch.go (86%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_connectedclusterproperties.go (98%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_credentialresult.go (81%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_credentialresults.go (89%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_hybridconnectionconfig.go (91%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_listclusterusercredentialproperties.go (88%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/model_systemdata.go (97%) rename internal/services/{kubernetes/sdk/2021-10-01/kubernetes => hybridkubernetes/sdk/2021-10-01/hybridkubernetes}/predicates.go (95%) create mode 100644 internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/version.go delete mode 100644 internal/services/kubernetes/client/client.go delete mode 100644 internal/services/kubernetes/resourceids.go delete mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go delete mode 100644 internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go create mode 100644 website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown delete mode 100644 website/docs/r/kubernetes_connected_cluster.html.markdown diff --git a/.teamcity/components/generated/services.kt b/.teamcity/components/generated/services.kt index 57dcfe9c2a02..589d90fad0ac 100644 --- a/.teamcity/components/generated/services.kt +++ b/.teamcity/components/generated/services.kt @@ -46,10 +46,10 @@ var services = mapOf( "hpccache" to "HPC Cache", "hsm" to "Hardware Security Module", "healthcare" to "Health Care", + "hybridkubernetes" to "HybridKubernetes", "iotcentral" to "IoT Central", "iothub" to "IoT Hub", "keyvault" to "KeyVault", - "kubernetes" to "Kubernetes", "kusto" to "Kusto", "lighthouse" to "Lighthouse", "loadbalancer" to "Load Balancer", diff --git a/internal/clients/client.go b/internal/clients/client.go index cc2811c70d6f..8b518e4c082e 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -52,11 +52,11 @@ import ( healthcare "github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/client" hpccache "github.com/hashicorp/terraform-provider-azurerm/internal/services/hpccache/client" hsm "github.com/hashicorp/terraform-provider-azurerm/internal/services/hsm/client" + hybridkubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/client" iotcentral "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral/client" iothub "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub/client" timeseriesinsights "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights/client" keyvault "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault/client" - kubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/client" kusto "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto/client" lighthouse "github.com/hashicorp/terraform-provider-azurerm/internal/services/lighthouse/client" loadbalancers "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer/client" @@ -163,11 +163,11 @@ type Client struct { HSM *hsm.Client HDInsight *hdinsight.Client HealthCare *healthcare.Client + HybridKubernetes *hybridkubernetes.Client IoTCentral *iotcentral.Client IoTHub *iothub.Client IoTTimeSeriesInsights *timeseriesinsights.Client KeyVault *keyvault.Client - Kubernetes *kubernetes.Client Kusto *kusto.Client Lighthouse *lighthouse.Client LoadBalancers *loadbalancers.Client @@ -276,11 +276,11 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.HSM = hsm.NewClient(o) client.HDInsight = hdinsight.NewClient(o) client.HealthCare = healthcare.NewClient(o) + client.HybridKubernetes = hybridkubernetes.NewClient(o) client.IoTCentral = iotcentral.NewClient(o) client.IoTHub = iothub.NewClient(o) client.IoTTimeSeriesInsights = timeseriesinsights.NewClient(o) client.KeyVault = keyvault.NewClient(o) - client.Kubernetes = kubernetes.NewClient(o) client.Kusto = kusto.NewClient(o) client.Lighthouse = lighthouse.NewClient(o) client.LogAnalytics = loganalytics.NewClient(o) diff --git a/internal/provider/services.go b/internal/provider/services.go index 7325026b61e7..35fba7a0bdfe 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -48,11 +48,11 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare" "github.com/hashicorp/terraform-provider-azurerm/internal/services/hpccache" "github.com/hashicorp/terraform-provider-azurerm/internal/services/hsm" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights" "github.com/hashicorp/terraform-provider-azurerm/internal/services/keyvault" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/services/kusto" "github.com/hashicorp/terraform-provider-azurerm/internal/services/lighthouse" "github.com/hashicorp/terraform-provider-azurerm/internal/services/loadbalancer" @@ -179,10 +179,10 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration { hsm.Registration{}, hdinsight.Registration{}, healthcare.Registration{}, + hybridkubernetes.Registration{}, iothub.Registration{}, iotcentral.Registration{}, keyvault.Registration{}, - kubernetes.Registration{}, kusto.Registration{}, loadbalancer.Registration{}, loganalytics.Registration{}, diff --git a/internal/services/hybridkubernetes/client/client.go b/internal/services/hybridkubernetes/client/client.go new file mode 100644 index 000000000000..3b4bb1c95877 --- /dev/null +++ b/internal/services/hybridkubernetes/client/client.go @@ -0,0 +1,20 @@ +package client + +import ( + "github.com/hashicorp/terraform-provider-azurerm/internal/common" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes" +) + +type Client struct { + HybridKubernetesClient *hybridkubernetes.HybridKubernetesClient +} + +func NewClient(o *common.ClientOptions) *Client { + + hybridKubernetesClient := hybridkubernetes.NewHybridKubernetesClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&hybridKubernetesClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + HybridKubernetesClient: &hybridKubernetesClient, + } +} diff --git a/internal/services/kubernetes/kubernetes_connected_cluster_resource.go b/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go similarity index 72% rename from internal/services/kubernetes/kubernetes_connected_cluster_resource.go rename to internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go index 6914ec865dce..6d19ca3273e4 100644 --- a/internal/services/kubernetes/kubernetes_connected_cluster_resource.go +++ b/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "fmt" @@ -12,19 +12,19 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/location" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/sdk/2021-10-01/kubernetes" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" ) -func resourceKubernetesConnectedCluster() *pluginsdk.Resource { +func resourceHybridKubernetesConnectedCluster() *pluginsdk.Resource { return &pluginsdk.Resource{ - Create: resourceKubernetesConnectedClusterCreate, - Read: resourceKubernetesConnectedClusterRead, - Update: resourceKubernetesConnectedClusterUpdate, - Delete: resourceKubernetesConnectedClusterDelete, + Create: resourceHybridKubernetesConnectedClusterCreate, + Read: resourceHybridKubernetesConnectedClusterRead, + Update: resourceHybridKubernetesConnectedClusterUpdate, + Delete: resourceHybridKubernetesConnectedClusterDelete, Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), @@ -34,7 +34,7 @@ func resourceKubernetesConnectedCluster() *pluginsdk.Resource { }, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := kubernetes.ParseConnectedClusterID(id) + _, err := hybridkubernetes.ParseConnectedClusterID(id) return err }), @@ -79,13 +79,13 @@ func resourceKubernetesConnectedCluster() *pluginsdk.Resource { } } -func resourceKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Kubernetes.KubernetesClient +func resourceHybridKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := kubernetes.NewConnectedClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := hybridkubernetes.NewConnectedClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { existing, err := client.ConnectedClusterGet(ctx, id) @@ -96,7 +96,7 @@ func resourceKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, meta in } if !response.WasNotFound(existing.HttpResponse) { - return tf.ImportAsExistsError("azurerm_kubernetes_connected_cluster", id.ID()) + return tf.ImportAsExistsError("azurerm_hybrid_kubernetes_connected_cluster", id.ID()) } } @@ -106,10 +106,10 @@ func resourceKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, meta in } location := azure.NormalizeLocation(d.Get("location")) - props := kubernetes.ConnectedCluster{ + props := hybridkubernetes.ConnectedCluster{ Identity: *identity, Location: location, - Properties: kubernetes.ConnectedClusterProperties{ + Properties: hybridkubernetes.ConnectedClusterProperties{ AgentPublicKeyCertificate: d.Get("agent_public_key_certificate").(string), Distribution: utils.String(d.Get("distribution").(string)), Infrastructure: utils.String(d.Get("infrastructure").(string)), @@ -122,15 +122,15 @@ func resourceKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, meta in } d.SetId(id.ID()) - return resourceKubernetesConnectedClusterRead(d, meta) + return resourceHybridKubernetesConnectedClusterRead(d, meta) } -func resourceKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Kubernetes.KubernetesClient +func resourceHybridKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := kubernetes.ParseConnectedClusterID(d.Id()) + id, err := hybridkubernetes.ParseConnectedClusterID(d.Id()) if err != nil { return err } @@ -167,17 +167,17 @@ func resourceKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, meta inte return nil } -func resourceKubernetesConnectedClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Kubernetes.KubernetesClient +func resourceHybridKubernetesConnectedClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := kubernetes.ParseConnectedClusterID(d.Id()) + id, err := hybridkubernetes.ParseConnectedClusterID(d.Id()) if err != nil { return err } - props := kubernetes.ConnectedClusterPatch{ + props := hybridkubernetes.ConnectedClusterPatch{ Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), } @@ -185,15 +185,15 @@ func resourceKubernetesConnectedClusterUpdate(d *pluginsdk.ResourceData, meta in return fmt.Errorf("updating %s: %+v", id, err) } - return resourceKubernetesConnectedClusterRead(d, meta) + return resourceHybridKubernetesConnectedClusterRead(d, meta) } -func resourceKubernetesConnectedClusterDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).Kubernetes.KubernetesClient +func resourceHybridKubernetesConnectedClusterDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := kubernetes.ParseConnectedClusterID(d.Id()) + id, err := hybridkubernetes.ParseConnectedClusterID(d.Id()) if err != nil { return err } diff --git a/internal/services/kubernetes/kubernetes_connected_cluster_resource_test.go b/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go similarity index 71% rename from internal/services/kubernetes/kubernetes_connected_cluster_resource_test.go rename to internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go index 05690a567172..91c6abf778e4 100644 --- a/internal/services/kubernetes/kubernetes_connected_cluster_resource_test.go +++ b/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go @@ -1,24 +1,25 @@ -package kubernetes_test +package hybridkubernetes_test import ( "context" "fmt" "testing" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/sdk/2021-10-01/kubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/utils" ) -type KubernetesConnectedClusterResource struct{} +type HybridKubernetesConnectedClusterResource struct{} -func TestAccKubernetesConnectedCluster_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") - r := KubernetesConnectedClusterResource{} +func TestAccHybridKubernetesConnectedCluster_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") + r := HybridKubernetesConnectedClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), @@ -30,9 +31,9 @@ func TestAccKubernetesConnectedCluster_basic(t *testing.T) { }) } -func TestAccKubernetesConnectedCluster_requiresImport(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") - r := KubernetesConnectedClusterResource{} +func TestAccHybridKubernetesConnectedCluster_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") + r := HybridKubernetesConnectedClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), @@ -44,9 +45,9 @@ func TestAccKubernetesConnectedCluster_requiresImport(t *testing.T) { }) } -func TestAccKubernetesConnectedCluster_complete(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") - r := KubernetesConnectedClusterResource{} +func TestAccHybridKubernetesConnectedCluster_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") + r := HybridKubernetesConnectedClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), @@ -58,9 +59,9 @@ func TestAccKubernetesConnectedCluster_complete(t *testing.T) { }) } -func TestAccKubernetesConnectedCluster_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_kubernetes_connected_cluster", "test") - r := KubernetesConnectedClusterResource{} +func TestAccHybridKubernetesConnectedCluster_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") + r := HybridKubernetesConnectedClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), @@ -79,13 +80,13 @@ func TestAccKubernetesConnectedCluster_update(t *testing.T) { }) } -func (r KubernetesConnectedClusterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := kubernetes.ParseConnectedClusterID(state.ID) +func (r HybridKubernetesConnectedClusterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := hybridkubernetes.ParseConnectedClusterID(state.ID) if err != nil { return nil, err } - client := clients.Kubernetes.KubernetesClient + client := clients.HybridKubernetes.HybridKubernetesClient resp, err := client.ConnectedClusterGet(ctx, *id) if err != nil { if response.WasNotFound(resp.HttpResponse) { @@ -96,7 +97,7 @@ func (r KubernetesConnectedClusterResource) Exists(ctx context.Context, clients return utils.Bool(true), nil } -func (r KubernetesConnectedClusterResource) template(data acceptance.TestData) string { +func (r HybridKubernetesConnectedClusterResource) template(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -109,12 +110,12 @@ resource "azurerm_resource_group" "test" { `, data.RandomInteger, data.Locations.Primary) } -func (r KubernetesConnectedClusterResource) basic(data acceptance.TestData) string { +func (r HybridKubernetesConnectedClusterResource) basic(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` %s -resource "azurerm_kubernetes_connected_cluster" "test" { +resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { name = "acctest-k-%d" resource_group_name = azurerm_resource_group.test.name agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" @@ -126,29 +127,29 @@ resource "azurerm_kubernetes_connected_cluster" "test" { `, template, data.RandomInteger, data.Locations.Primary) } -func (r KubernetesConnectedClusterResource) requiresImport(data acceptance.TestData) string { +func (r HybridKubernetesConnectedClusterResource) requiresImport(data acceptance.TestData) string { config := r.basic(data) return fmt.Sprintf(` %s -resource "azurerm_kubernetes_connected_cluster" "import" { - name = azurerm_kubernetes_connected_cluster.test.name +resource "azurerm_hybrid_kubernetes_connected_cluster" "import" { + name = azurerm_hybrid_kubernetes_connected_cluster.test.name resource_group_name = azurerm_resource_group.test.name - agent_public_key_certificate = azurerm_kubernetes_connected_cluster.test.agent_public_key_certificate + agent_public_key_certificate = azurerm_hybrid_kubernetes_connected_cluster.test.agent_public_key_certificate identity { type = "SystemAssigned" } - location = azurerm_kubernetes_connected_cluster.test.location + location = azurerm_hybrid_kubernetes_connected_cluster.test.location } `, config) } -func (r KubernetesConnectedClusterResource) complete(data acceptance.TestData) string { +func (r HybridKubernetesConnectedClusterResource) complete(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` %s -resource "azurerm_kubernetes_connected_cluster" "test" { +resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { name = "acctest-k-%d" resource_group_name = azurerm_resource_group.test.name agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" @@ -167,12 +168,12 @@ resource "azurerm_kubernetes_connected_cluster" "test" { `, template, data.RandomInteger, data.Locations.Primary) } -func (r KubernetesConnectedClusterResource) update(data acceptance.TestData) string { +func (r HybridKubernetesConnectedClusterResource) update(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` %s -resource "azurerm_kubernetes_connected_cluster" "test" { +resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { name = "acctest-k-%d" resource_group_name = azurerm_resource_group.test.name agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" diff --git a/internal/services/kubernetes/registration.go b/internal/services/hybridkubernetes/registration.go similarity index 81% rename from internal/services/kubernetes/registration.go rename to internal/services/hybridkubernetes/registration.go index 46204bb2726e..c8e614e3e3f0 100644 --- a/internal/services/kubernetes/registration.go +++ b/internal/services/hybridkubernetes/registration.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -6,13 +6,13 @@ type Registration struct{} // Name is the name of this Service func (r Registration) Name() string { - return "Kubernetes" + return "HybridKubernetes" } // WebsiteCategories returns a list of categories which can be used for the sidebar func (r Registration) WebsiteCategories() []string { return []string{ - "Kubernetes", + "HybridKubernetes", } } @@ -24,6 +24,6 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { return map[string]*pluginsdk.Resource{ - "azurerm_kubernetes_connected_cluster": resourceKubernetesConnectedCluster(), + "azurerm_hybrid_kubernetes_connected_cluster": resourceHybridKubernetesConnectedCluster(), } } diff --git a/internal/services/hybridkubernetes/resourceids.go b/internal/services/hybridkubernetes/resourceids.go new file mode 100644 index 000000000000..98eac49ded57 --- /dev/null +++ b/internal/services/hybridkubernetes/resourceids.go @@ -0,0 +1,3 @@ +package hybridkubernetes + +//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=HybridKubernetesConnectedCluster -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/client.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/client.go new file mode 100644 index 000000000000..9e5b81d83456 --- /dev/null +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/client.go @@ -0,0 +1,15 @@ +package hybridkubernetes + +import "github.com/Azure/go-autorest/autorest" + +type HybridKubernetesClient struct { + Client autorest.Client + baseUri string +} + +func NewHybridKubernetesClientWithBaseURI(endpoint string) HybridKubernetesClient { + return HybridKubernetesClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/constants.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/constants.go similarity index 99% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/constants.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/constants.go index 834ddb83ae4f..1a58aeccfe9f 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/constants.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/constants.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import "strings" diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go similarity index 99% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go index 3b8c1ce299ea..65875bac58c9 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "fmt" diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster_test.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go similarity index 99% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster_test.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go index 85c6566331cc..47a00932edd9 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/id_connectedcluster_test.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "testing" diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclustercreate_autorest.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go similarity index 64% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclustercreate_autorest.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go index 98d10d873363..533fb244fd87 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclustercreate_autorest.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "context" @@ -16,16 +16,16 @@ type ConnectedClusterCreateResponse struct { } // ConnectedClusterCreate ... -func (c KubernetesClient) ConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (result ConnectedClusterCreateResponse, err error) { +func (c HybridKubernetesClient) ConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (result ConnectedClusterCreateResponse, err error) { req, err := c.preparerForConnectedClusterCreate(ctx, id, input) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterCreate", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterCreate", nil, "Failure preparing request") return } result, err = c.senderForConnectedClusterCreate(ctx, req) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterCreate", result.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterCreate", result.HttpResponse, "Failure sending request") return } @@ -33,7 +33,7 @@ func (c KubernetesClient) ConnectedClusterCreate(ctx context.Context, id Connect } // ConnectedClusterCreateThenPoll performs ConnectedClusterCreate then polls until it's completed -func (c KubernetesClient) ConnectedClusterCreateThenPoll(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) error { +func (c HybridKubernetesClient) ConnectedClusterCreateThenPoll(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) error { result, err := c.ConnectedClusterCreate(ctx, id, input) if err != nil { return fmt.Errorf("performing ConnectedClusterCreate: %+v", err) @@ -47,7 +47,7 @@ func (c KubernetesClient) ConnectedClusterCreateThenPoll(ctx context.Context, id } // preparerForConnectedClusterCreate prepares the ConnectedClusterCreate request. -func (c KubernetesClient) preparerForConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": defaultApiVersion, } @@ -64,7 +64,7 @@ func (c KubernetesClient) preparerForConnectedClusterCreate(ctx context.Context, // senderForConnectedClusterCreate sends the ConnectedClusterCreate request. The method will close the // http.Response Body if it receives an error. -func (c KubernetesClient) senderForConnectedClusterCreate(ctx context.Context, req *http.Request) (future ConnectedClusterCreateResponse, err error) { +func (c HybridKubernetesClient) senderForConnectedClusterCreate(ctx context.Context, req *http.Request) (future ConnectedClusterCreateResponse, err error) { var resp *http.Response resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterdelete_autorest.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go similarity index 66% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterdelete_autorest.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go index 34abe80ff92e..e158d30cfef5 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterdelete_autorest.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "context" @@ -16,16 +16,16 @@ type ConnectedClusterDeleteResponse struct { } // ConnectedClusterDelete ... -func (c KubernetesClient) ConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterDeleteResponse, err error) { +func (c HybridKubernetesClient) ConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterDeleteResponse, err error) { req, err := c.preparerForConnectedClusterDelete(ctx, id) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterDelete", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterDelete", nil, "Failure preparing request") return } result, err = c.senderForConnectedClusterDelete(ctx, req) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterDelete", result.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterDelete", result.HttpResponse, "Failure sending request") return } @@ -33,7 +33,7 @@ func (c KubernetesClient) ConnectedClusterDelete(ctx context.Context, id Connect } // ConnectedClusterDeleteThenPoll performs ConnectedClusterDelete then polls until it's completed -func (c KubernetesClient) ConnectedClusterDeleteThenPoll(ctx context.Context, id ConnectedClusterId) error { +func (c HybridKubernetesClient) ConnectedClusterDeleteThenPoll(ctx context.Context, id ConnectedClusterId) error { result, err := c.ConnectedClusterDelete(ctx, id) if err != nil { return fmt.Errorf("performing ConnectedClusterDelete: %+v", err) @@ -47,7 +47,7 @@ func (c KubernetesClient) ConnectedClusterDeleteThenPoll(ctx context.Context, id } // preparerForConnectedClusterDelete prepares the ConnectedClusterDelete request. -func (c KubernetesClient) preparerForConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": defaultApiVersion, } @@ -63,7 +63,7 @@ func (c KubernetesClient) preparerForConnectedClusterDelete(ctx context.Context, // senderForConnectedClusterDelete sends the ConnectedClusterDelete request. The method will close the // http.Response Body if it receives an error. -func (c KubernetesClient) senderForConnectedClusterDelete(ctx context.Context, req *http.Request) (future ConnectedClusterDeleteResponse, err error) { +func (c HybridKubernetesClient) senderForConnectedClusterDelete(ctx context.Context, req *http.Request) (future ConnectedClusterDeleteResponse, err error) { var resp *http.Response resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterget_autorest.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go similarity index 60% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterget_autorest.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go index 34dfb80496d1..d33e1a968881 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterget_autorest.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "context" @@ -14,22 +14,22 @@ type ConnectedClusterGetResponse struct { } // ConnectedClusterGet ... -func (c KubernetesClient) ConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterGetResponse, err error) { +func (c HybridKubernetesClient) ConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterGetResponse, err error) { req, err := c.preparerForConnectedClusterGet(ctx, id) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterGet", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterGet", nil, "Failure preparing request") return } result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure sending request") return } result, err = c.responderForConnectedClusterGet(result.HttpResponse) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure responding to request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure responding to request") return } @@ -37,7 +37,7 @@ func (c KubernetesClient) ConnectedClusterGet(ctx context.Context, id ConnectedC } // preparerForConnectedClusterGet prepares the ConnectedClusterGet request. -func (c KubernetesClient) preparerForConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": defaultApiVersion, } @@ -53,7 +53,7 @@ func (c KubernetesClient) preparerForConnectedClusterGet(ctx context.Context, id // responderForConnectedClusterGet handles the response to the ConnectedClusterGet request. The method always // closes the http.Response Body. -func (c KubernetesClient) responderForConnectedClusterGet(resp *http.Response) (result ConnectedClusterGetResponse, err error) { +func (c HybridKubernetesClient) responderForConnectedClusterGet(resp *http.Response) (result ConnectedClusterGetResponse, err error) { err = autorest.Respond( resp, azure.WithErrorUnlessStatusCode(http.StatusOK), diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbyresourcegroup_autorest.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go similarity index 69% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbyresourcegroup_autorest.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go index 61a7df5b3410..9f9cd8039b0c 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbyresourcegroup_autorest.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "context" @@ -36,34 +36,34 @@ func (r ConnectedClusterListByResourceGroupResponse) LoadMore(ctx context.Contex } // ConnectedClusterListByResourceGroup ... -func (c KubernetesClient) ConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ConnectedClusterListByResourceGroupResponse, err error) { +func (c HybridKubernetesClient) ConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ConnectedClusterListByResourceGroupResponse, err error) { req, err := c.preparerForConnectedClusterListByResourceGroup(ctx, id) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") return } resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure sending request") return } resp, err = c.responderForConnectedClusterListByResourceGroup(resp.HttpResponse) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure responding to request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure responding to request") return } return } // ConnectedClusterListByResourceGroupComplete retrieves all of the results into a single object -func (c KubernetesClient) ConnectedClusterListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ConnectedClusterListByResourceGroupCompleteResult, error) { +func (c HybridKubernetesClient) ConnectedClusterListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ConnectedClusterListByResourceGroupCompleteResult, error) { return c.ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx, id, ConnectedClusterPredicate{}) } // ConnectedClusterListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c KubernetesClient) ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListByResourceGroupCompleteResult, err error) { +func (c HybridKubernetesClient) ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListByResourceGroupCompleteResult, err error) { items := make([]ConnectedCluster, 0) page, err := c.ConnectedClusterListByResourceGroup(ctx, id) @@ -102,7 +102,7 @@ func (c KubernetesClient) ConnectedClusterListByResourceGroupCompleteMatchingPre } // preparerForConnectedClusterListByResourceGroup prepares the ConnectedClusterListByResourceGroup request. -func (c KubernetesClient) preparerForConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": defaultApiVersion, } @@ -117,7 +117,7 @@ func (c KubernetesClient) preparerForConnectedClusterListByResourceGroup(ctx con } // preparerForConnectedClusterListByResourceGroupWithNextLink prepares the ConnectedClusterListByResourceGroup request with the given nextLink token. -func (c KubernetesClient) preparerForConnectedClusterListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { uri, err := url.Parse(nextLink) if err != nil { return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) @@ -143,7 +143,7 @@ func (c KubernetesClient) preparerForConnectedClusterListByResourceGroupWithNext // responderForConnectedClusterListByResourceGroup handles the response to the ConnectedClusterListByResourceGroup request. The method always // closes the http.Response Body. -func (c KubernetesClient) responderForConnectedClusterListByResourceGroup(resp *http.Response) (result ConnectedClusterListByResourceGroupResponse, err error) { +func (c HybridKubernetesClient) responderForConnectedClusterListByResourceGroup(resp *http.Response) (result ConnectedClusterListByResourceGroupResponse, err error) { type page struct { Values []ConnectedCluster `json:"value"` NextLink *string `json:"nextLink"` @@ -161,19 +161,19 @@ func (c KubernetesClient) responderForConnectedClusterListByResourceGroup(resp * result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListByResourceGroupResponse, err error) { req, err := c.preparerForConnectedClusterListByResourceGroupWithNextLink(ctx, nextLink) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") return } result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure sending request") return } result, err = c.responderForConnectedClusterListByResourceGroup(result.HttpResponse) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure responding to request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure responding to request") return } diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbysubscription_autorest.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go similarity index 69% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbysubscription_autorest.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go index 4f0a965082b1..a55e2e72146c 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistbysubscription_autorest.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "context" @@ -36,34 +36,34 @@ func (r ConnectedClusterListBySubscriptionResponse) LoadMore(ctx context.Context } // ConnectedClusterListBySubscription ... -func (c KubernetesClient) ConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ConnectedClusterListBySubscriptionResponse, err error) { +func (c HybridKubernetesClient) ConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ConnectedClusterListBySubscriptionResponse, err error) { req, err := c.preparerForConnectedClusterListBySubscription(ctx, id) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") return } resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure sending request") return } resp, err = c.responderForConnectedClusterListBySubscription(resp.HttpResponse) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure responding to request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure responding to request") return } return } // ConnectedClusterListBySubscriptionComplete retrieves all of the results into a single object -func (c KubernetesClient) ConnectedClusterListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ConnectedClusterListBySubscriptionCompleteResult, error) { +func (c HybridKubernetesClient) ConnectedClusterListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ConnectedClusterListBySubscriptionCompleteResult, error) { return c.ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx, id, ConnectedClusterPredicate{}) } // ConnectedClusterListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c KubernetesClient) ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListBySubscriptionCompleteResult, err error) { +func (c HybridKubernetesClient) ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListBySubscriptionCompleteResult, err error) { items := make([]ConnectedCluster, 0) page, err := c.ConnectedClusterListBySubscription(ctx, id) @@ -102,7 +102,7 @@ func (c KubernetesClient) ConnectedClusterListBySubscriptionCompleteMatchingPred } // preparerForConnectedClusterListBySubscription prepares the ConnectedClusterListBySubscription request. -func (c KubernetesClient) preparerForConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": defaultApiVersion, } @@ -117,7 +117,7 @@ func (c KubernetesClient) preparerForConnectedClusterListBySubscription(ctx cont } // preparerForConnectedClusterListBySubscriptionWithNextLink prepares the ConnectedClusterListBySubscription request with the given nextLink token. -func (c KubernetesClient) preparerForConnectedClusterListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { uri, err := url.Parse(nextLink) if err != nil { return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) @@ -143,7 +143,7 @@ func (c KubernetesClient) preparerForConnectedClusterListBySubscriptionWithNextL // responderForConnectedClusterListBySubscription handles the response to the ConnectedClusterListBySubscription request. The method always // closes the http.Response Body. -func (c KubernetesClient) responderForConnectedClusterListBySubscription(resp *http.Response) (result ConnectedClusterListBySubscriptionResponse, err error) { +func (c HybridKubernetesClient) responderForConnectedClusterListBySubscription(resp *http.Response) (result ConnectedClusterListBySubscriptionResponse, err error) { type page struct { Values []ConnectedCluster `json:"value"` NextLink *string `json:"nextLink"` @@ -161,19 +161,19 @@ func (c KubernetesClient) responderForConnectedClusterListBySubscription(resp *h result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListBySubscriptionResponse, err error) { req, err := c.preparerForConnectedClusterListBySubscriptionWithNextLink(ctx, nextLink) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") return } result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure sending request") return } result, err = c.responderForConnectedClusterListBySubscription(result.HttpResponse) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure responding to request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure responding to request") return } diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistclusterusercredential_autorest.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go similarity index 58% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistclusterusercredential_autorest.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go index 09e229386923..8906ae14a6ea 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterlistclusterusercredential_autorest.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "context" @@ -15,22 +15,22 @@ type ConnectedClusterListClusterUserCredentialResponse struct { } // ConnectedClusterListClusterUserCredential ... -func (c KubernetesClient) ConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (result ConnectedClusterListClusterUserCredentialResponse, err error) { +func (c HybridKubernetesClient) ConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (result ConnectedClusterListClusterUserCredentialResponse, err error) { req, err := c.preparerForConnectedClusterListClusterUserCredential(ctx, id, input) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListClusterUserCredential", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListClusterUserCredential", nil, "Failure preparing request") return } result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure sending request") return } result, err = c.responderForConnectedClusterListClusterUserCredential(result.HttpResponse) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure responding to request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure responding to request") return } @@ -38,7 +38,7 @@ func (c KubernetesClient) ConnectedClusterListClusterUserCredential(ctx context. } // preparerForConnectedClusterListClusterUserCredential prepares the ConnectedClusterListClusterUserCredential request. -func (c KubernetesClient) preparerForConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": defaultApiVersion, } @@ -55,7 +55,7 @@ func (c KubernetesClient) preparerForConnectedClusterListClusterUserCredential(c // responderForConnectedClusterListClusterUserCredential handles the response to the ConnectedClusterListClusterUserCredential request. The method always // closes the http.Response Body. -func (c KubernetesClient) responderForConnectedClusterListClusterUserCredential(resp *http.Response) (result ConnectedClusterListClusterUserCredentialResponse, err error) { +func (c HybridKubernetesClient) responderForConnectedClusterListClusterUserCredential(resp *http.Response) (result ConnectedClusterListClusterUserCredentialResponse, err error) { err = autorest.Respond( resp, azure.WithErrorUnlessStatusCode(http.StatusOK), diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterupdate_autorest.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go similarity index 59% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterupdate_autorest.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go index 5ca612cb989b..26f34b9d7c28 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/method_connectedclusterupdate_autorest.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "context" @@ -14,22 +14,22 @@ type ConnectedClusterUpdateResponse struct { } // ConnectedClusterUpdate ... -func (c KubernetesClient) ConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (result ConnectedClusterUpdateResponse, err error) { +func (c HybridKubernetesClient) ConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (result ConnectedClusterUpdateResponse, err error) { req, err := c.preparerForConnectedClusterUpdate(ctx, id, input) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterUpdate", nil, "Failure preparing request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterUpdate", nil, "Failure preparing request") return } result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure sending request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure sending request") return } result, err = c.responderForConnectedClusterUpdate(result.HttpResponse) if err != nil { - err = autorest.NewErrorWithError(err, "kubernetes.KubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure responding to request") + err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure responding to request") return } @@ -37,7 +37,7 @@ func (c KubernetesClient) ConnectedClusterUpdate(ctx context.Context, id Connect } // preparerForConnectedClusterUpdate prepares the ConnectedClusterUpdate request. -func (c KubernetesClient) preparerForConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (*http.Request, error) { +func (c HybridKubernetesClient) preparerForConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (*http.Request, error) { queryParameters := map[string]interface{}{ "api-version": defaultApiVersion, } @@ -54,7 +54,7 @@ func (c KubernetesClient) preparerForConnectedClusterUpdate(ctx context.Context, // responderForConnectedClusterUpdate handles the response to the ConnectedClusterUpdate request. The method always // closes the http.Response Body. -func (c KubernetesClient) responderForConnectedClusterUpdate(resp *http.Response) (result ConnectedClusterUpdateResponse, err error) { +func (c HybridKubernetesClient) responderForConnectedClusterUpdate(resp *http.Response) (result ConnectedClusterUpdateResponse, err error) { err = autorest.Respond( resp, azure.WithErrorUnlessStatusCode(http.StatusOK), diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedcluster.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go similarity index 96% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedcluster.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go index 8d1b77e5b500..2519906904da 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedcluster.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterpatch.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go similarity index 86% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterpatch.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go index cdf6ca12a058..e1e231970ec1 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterpatch.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes type ConnectedClusterPatch struct { Properties *interface{} `json:"properties,omitempty"` diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterproperties.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go similarity index 98% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterproperties.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go index 8ee77ae749ae..eff635aa575e 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_connectedclusterproperties.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "time" diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresult.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go similarity index 81% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresult.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go index 6814442b2b30..a8aac6a20c54 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresult.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes type CredentialResult struct { Name *string `json:"name,omitempty"` diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresults.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go similarity index 89% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresults.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go index d7319f1be113..fbe3011fb3fc 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_credentialresults.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes type CredentialResults struct { HybridConnectionConfig *HybridConnectionConfig `json:"hybridConnectionConfig,omitempty"` diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_hybridconnectionconfig.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go similarity index 91% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_hybridconnectionconfig.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go index 7b11962e13e7..9f0faf9497d5 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_hybridconnectionconfig.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes type HybridConnectionConfig struct { ExpirationTime *int64 `json:"expirationTime,omitempty"` diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_listclusterusercredentialproperties.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go similarity index 88% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_listclusterusercredentialproperties.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go index c4b4ed1da6cf..912651a569ac 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_listclusterusercredentialproperties.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes type ListClusterUserCredentialProperties struct { AuthenticationMethod AuthenticationMethod `json:"authenticationMethod"` diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_systemdata.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go similarity index 97% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_systemdata.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go index bb4142485b4c..7391d86775ed 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/model_systemdata.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes import ( "time" diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/predicates.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go similarity index 95% rename from internal/services/kubernetes/sdk/2021-10-01/kubernetes/predicates.go rename to internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go index 266ceee4e1a6..0c67034cdd5c 100644 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/predicates.go +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go @@ -1,4 +1,4 @@ -package kubernetes +package hybridkubernetes type ConnectedClusterPredicate struct { Id *string diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/version.go b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/version.go new file mode 100644 index 000000000000..31ffc92c97bd --- /dev/null +++ b/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/version.go @@ -0,0 +1,9 @@ +package hybridkubernetes + +import "fmt" + +const defaultApiVersion = "2021-10-01" + +func userAgent() string { + return fmt.Sprintf("pandora/hybridkubernetes/%s", defaultApiVersion) +} diff --git a/internal/services/kubernetes/client/client.go b/internal/services/kubernetes/client/client.go deleted file mode 100644 index fae08c50dd34..000000000000 --- a/internal/services/kubernetes/client/client.go +++ /dev/null @@ -1,20 +0,0 @@ -package client - -import ( - "github.com/hashicorp/terraform-provider-azurerm/internal/common" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/kubernetes/sdk/2021-10-01/kubernetes" -) - -type Client struct { - KubernetesClient *kubernetes.KubernetesClient -} - -func NewClient(o *common.ClientOptions) *Client { - - kubernetesClient := kubernetes.NewKubernetesClientWithBaseURI(o.ResourceManagerEndpoint) - o.ConfigureClient(&kubernetesClient.Client, o.ResourceManagerAuthorizer) - - return &Client{ - KubernetesClient: &kubernetesClient, - } -} diff --git a/internal/services/kubernetes/resourceids.go b/internal/services/kubernetes/resourceids.go deleted file mode 100644 index afa9e3b5a03e..000000000000 --- a/internal/services/kubernetes/resourceids.go +++ /dev/null @@ -1,3 +0,0 @@ -package kubernetes - -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=KubernetesConnectedCluster -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go deleted file mode 100644 index 2855a1b76b6a..000000000000 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/client.go +++ /dev/null @@ -1,15 +0,0 @@ -package kubernetes - -import "github.com/Azure/go-autorest/autorest" - -type KubernetesClient struct { - Client autorest.Client - baseUri string -} - -func NewKubernetesClientWithBaseURI(endpoint string) KubernetesClient { - return KubernetesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, - } -} diff --git a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go b/internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go deleted file mode 100644 index 2b84f45b1dec..000000000000 --- a/internal/services/kubernetes/sdk/2021-10-01/kubernetes/version.go +++ /dev/null @@ -1,9 +0,0 @@ -package kubernetes - -import "fmt" - -const defaultApiVersion = "2021-10-01" - -func userAgent() string { - return fmt.Sprintf("pandora/kubernetes/%s", defaultApiVersion) -} diff --git a/website/allowed-subcategories b/website/allowed-subcategories index bf980f775def..421136f968a1 100644 --- a/website/allowed-subcategories +++ b/website/allowed-subcategories @@ -42,10 +42,10 @@ Disks HDInsight Hardware Security Module Healthcare +HybridKubernetes IoT Central IoT Hub Key Vault -Kubernetes Lighthouse Load Balancer Load Test diff --git a/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown b/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown new file mode 100644 index 000000000000..2dea8cae2c32 --- /dev/null +++ b/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown @@ -0,0 +1,98 @@ +--- +subcategory: "HybridKubernetes" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_hybrid_kubernetes_connected_cluster" +description: |- + Manages a HybridKubernetes connected cluster. +--- + +# azurerm_hybrid_kubernetes_connected_cluster + +Manages a HybridKubernetes connected cluster. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "test" { + name = "example-hybridkubernetes" + location = "West Europe" +} + +resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { + name = "acctest-k-%d" + resource_group_name = azurerm_resource_group.test.name + agent_public_key_certificate = "xxxxxxxxxxxxxxxxxxx" + distribution = "gke" + + identity = { + type = "SystemAssigned" + } + infrastructure = "gcp" + location = "West Europe" + + tags = { + ENV = "Test" + } +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) The name which should be used for this HybridKubernetes Connected Cluster. Changing this forces a new HybridKubernetes Connected Cluster to be created. + +* `resource_group_name` - (Required) The name of the Resource Group where the HybridKubernetes connected cluster should exist. Changing this forces a new HybridKubernetes connected cluster to be created. + +* `agent_public_key_certificate` - (Required) Base64 encoded public certificate used by the agent to do the initial handshake to the backend services in Azure. Changing this forces a new HybridKubernetes connected cluster to be created. + +* `identity` - (Required) An `identity` block as defined below. + +* `location` - (Required) The Azure Region where the HybridKubernetes connected cluster should exist. Changing this forces a new HybridKubernetes connected cluster to be created. + +* `distribution` - (Optional) The HybridKubernetes distribution running on this connected cluster. Changing this forces a new HybridKubernetes connected cluster to be created. + +* `infrastructure` - (Optional) The infrastructure on which the HybridKubernetes cluster represented by this connected cluster is running on. Changing this forces a new HybridKubernetes connected cluster to be created. + +* `tags` - (Optional) A mapping of tags which should be assigned to the HybridKubernetes connected cluster. + +--- + +An `identity` block exports the following: + +* `type` - (Required) Specifies the type of Managed Service Identity. Possible values are `SystemAssigned`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the HybridKubernetes connected cluster. + +* `identity` - An `identity` block as defined below. + +* `provisioning_state` - The current deployment state of connected clusters. + +--- + +An `identity` block exports the following: + +* `principal_id` - The Principal ID associated with this Managed Service Identity. + +* `tenant_id` - The Tenant ID associated with this Managed Service Identity. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the HybridKubernetes connected cluster. +* `read` - (Defaults to 5 minutes) Used when retrieving the HybridKubernetes connected cluster. +* `update` - (Defaults to 30 minutes) Used when updating the HybridKubernetes connected cluster. +* `delete` - (Defaults to 30 minutes) Used when deleting the HybridKubernetes connected cluster. + +## Import + +HybridKubernetes connected cluster can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_hybrid_kubernetes_connected_cluster.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 +``` diff --git a/website/docs/r/kubernetes_connected_cluster.html.markdown b/website/docs/r/kubernetes_connected_cluster.html.markdown deleted file mode 100644 index fbc1053f66f9..000000000000 --- a/website/docs/r/kubernetes_connected_cluster.html.markdown +++ /dev/null @@ -1,98 +0,0 @@ ---- -subcategory: "Kubernetes" -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_kubernetes_connected_cluster" -description: |- - Manages a kubernetes connected cluster. ---- - -# azurerm_kubernetes_connected_cluster - -Manages a kubernetes connected cluster. - -## Example Usage - -```hcl -resource "azurerm_resource_group" "test" { - name = "example-kubernetes" - location = "West Europe" -} - -resource "azurerm_kubernetes_connected_cluster" "test" { - name = "acctest-k-%d" - resource_group_name = azurerm_resource_group.test.name - agent_public_key_certificate = "xxxxxxxxxxxxxxxxxxx" - distribution = "gke" - - identity = { - type = "SystemAssigned" - } - infrastructure = "gcp" - location = "West Europe" - - tags = { - ENV = "Test" - } -} -``` - -## Arguments Reference - -The following arguments are supported: - -* `name` - (Required) The name which should be used for this Kubernetes Connected Cluster. Changing this forces a new Kubernetes Connected Cluster to be created. - -* `resource_group_name` - (Required) The name of the Resource Group where the kubernetes connected cluster should exist. Changing this forces a new kubernetes connected cluster to be created. - -* `agent_public_key_certificate` - (Required) Base64 encoded public certificate used by the agent to do the initial handshake to the backend services in Azure. Changing this forces a new kubernetes connected cluster to be created. - -* `identity` - (Required) An `identity` block as defined below. - -* `location` - (Required) The Azure Region where the kubernetes connected cluster should exist. Changing this forces a new kubernetes connected cluster to be created. - -* `distribution` - (Optional) The Kubernetes distribution running on this connected cluster. Changing this forces a new kubernetes connected cluster to be created. - -* `infrastructure` - (Optional) The infrastructure on which the Kubernetes cluster represented by this connected cluster is running on. Changing this forces a new kubernetes connected cluster to be created. - -* `tags` - (Optional) A mapping of tags which should be assigned to the kubernetes connected cluster. - ---- - -An `identity` block exports the following: - -* `type` - (Required) Specifies the type of Managed Service Identity. Possible values are `SystemAssigned`. - -## Attributes Reference - -In addition to the Arguments listed above - the following Attributes are exported: - -* `id` - The ID of the kubernetes connected cluster. - -* `identity` - An `identity` block as defined below. - -* `provisioning_state` - The current deployment state of connected clusters. - ---- - -An `identity` block exports the following: - -* `principal_id` - The Principal ID associated with this Managed Service Identity. - -* `tenant_id` - The Tenant ID associated with this Managed Service Identity. - -## Timeouts - -The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: - -* `create` - (Defaults to 30 minutes) Used when creating the kubernetes connected cluster. -* `read` - (Defaults to 5 minutes) Used when retrieving the kubernetes connected cluster. -* `update` - (Defaults to 30 minutes) Used when updating the kubernetes connected cluster. -* `delete` - (Defaults to 30 minutes) Used when deleting the kubernetes connected cluster. - -## Import - -kubernetes connected cluster can be imported using the `resource id`, e.g. - -```shell -terraform import azurerm_kubernetes_connected_cluster.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 -``` From 6aea08423be1a0bad0900ab2580260b05a6fc551 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Wed, 16 Feb 2022 10:55:31 +0800 Subject: [PATCH 03/11] update markdown --- .../r/hybrid_kubernetes_connected_cluster.html.markdown | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown b/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown index 2dea8cae2c32..4e8c4ba846fe 100644 --- a/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown +++ b/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown @@ -14,17 +14,17 @@ Manages a HybridKubernetes connected cluster. ```hcl resource "azurerm_resource_group" "test" { - name = "example-hybridkubernetes" + name = "example-resources" location = "West Europe" } resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { - name = "acctest-k-%d" + name = "example-connected-cluster" resource_group_name = azurerm_resource_group.test.name agent_public_key_certificate = "xxxxxxxxxxxxxxxxxxx" distribution = "gke" - identity = { + identity { type = "SystemAssigned" } infrastructure = "gcp" From 60d1aa21def64216423c97646a65a695812551e2 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Fri, 4 Mar 2022 13:41:10 +0800 Subject: [PATCH 04/11] fix comments --- .teamcity/components/generated/services.kt | 2 +- internal/clients/client.go | 6 +- internal/provider/services.go | 4 +- .../arc_kubernetes_cluster_resource.go} | 126 +++++++++++------- .../arc_kubernetes_cluster_resource_test.go} | 72 +++++----- .../services/arckubernetes/client/client.go | 20 +++ .../registration.go | 8 +- .../sdk/2021-10-01/hybridkubernetes/client.go | 0 .../2021-10-01/hybridkubernetes/constants.go | 0 .../hybridkubernetes/id_connectedcluster.go | 0 .../id_connectedcluster_test.go | 0 .../method_connectedclustercreate_autorest.go | 0 .../method_connectedclusterdelete_autorest.go | 0 .../method_connectedclusterget_autorest.go | 0 ...ctedclusterlistbyresourcegroup_autorest.go | 0 ...ectedclusterlistbysubscription_autorest.go | 0 ...usterlistclusterusercredential_autorest.go | 0 .../method_connectedclusterupdate_autorest.go | 0 .../model_connectedcluster.go | 0 .../model_connectedclusterpatch.go | 0 .../model_connectedclusterproperties.go | 0 .../model_credentialresult.go | 0 .../model_credentialresults.go | 0 .../model_hybridconnectionconfig.go | 0 ...del_listclusterusercredentialproperties.go | 0 .../hybridkubernetes/model_systemdata.go | 0 .../2021-10-01/hybridkubernetes/predicates.go | 0 .../2021-10-01/hybridkubernetes/version.go | 0 .../hybridkubernetes/client/client.go | 20 --- .../services/hybridkubernetes/resourceids.go | 3 - website/allowed-subcategories | 2 +- .../r/arc_kubernetes_cluster.html.markdown | 106 +++++++++++++++ ...kubernetes_connected_cluster.html.markdown | 98 -------------- 33 files changed, 253 insertions(+), 214 deletions(-) rename internal/services/{hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go => arckubernetes/arc_kubernetes_cluster_resource.go} (52%) rename internal/services/{hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go => arckubernetes/arc_kubernetes_cluster_resource_test.go} (66%) create mode 100644 internal/services/arckubernetes/client/client.go rename internal/services/{hybridkubernetes => arckubernetes}/registration.go (81%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/client.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/constants.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/model_systemdata.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/predicates.go (100%) rename internal/services/{hybridkubernetes => arckubernetes}/sdk/2021-10-01/hybridkubernetes/version.go (100%) delete mode 100644 internal/services/hybridkubernetes/client/client.go delete mode 100644 internal/services/hybridkubernetes/resourceids.go create mode 100644 website/docs/r/arc_kubernetes_cluster.html.markdown delete mode 100644 website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown diff --git a/.teamcity/components/generated/services.kt b/.teamcity/components/generated/services.kt index 589d90fad0ac..83c1a5715a34 100644 --- a/.teamcity/components/generated/services.kt +++ b/.teamcity/components/generated/services.kt @@ -8,6 +8,7 @@ var services = mapOf( "appconfiguration" to "App Configuration", "appservice" to "AppService", "applicationinsights" to "Application Insights", + "arckubernetes" to "ArcKubernetes", "attestation" to "Attestation", "authorization" to "Authorization", "automation" to "Automation", @@ -46,7 +47,6 @@ var services = mapOf( "hpccache" to "HPC Cache", "hsm" to "Hardware Security Module", "healthcare" to "Health Care", - "hybridkubernetes" to "HybridKubernetes", "iotcentral" to "IoT Central", "iothub" to "IoT Hub", "keyvault" to "KeyVault", diff --git a/internal/clients/client.go b/internal/clients/client.go index 8b518e4c082e..7e9b37524dea 100644 --- a/internal/clients/client.go +++ b/internal/clients/client.go @@ -14,6 +14,7 @@ import ( appConfiguration "github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration/client" applicationInsights "github.com/hashicorp/terraform-provider-azurerm/internal/services/applicationinsights/client" appService "github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice/client" + arckubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/client" attestation "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation/client" authorization "github.com/hashicorp/terraform-provider-azurerm/internal/services/authorization/client" automation "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation/client" @@ -52,7 +53,6 @@ import ( healthcare "github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare/client" hpccache "github.com/hashicorp/terraform-provider-azurerm/internal/services/hpccache/client" hsm "github.com/hashicorp/terraform-provider-azurerm/internal/services/hsm/client" - hybridkubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/client" iotcentral "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral/client" iothub "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub/client" timeseriesinsights "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights/client" @@ -125,6 +125,7 @@ type Client struct { AppInsights *applicationInsights.Client AppPlatform *appPlatform.Client AppService *appService.Client + ArcKubernetes *arckubernetes.Client Attestation *attestation.Client Authorization *authorization.Client Automation *automation.Client @@ -163,7 +164,6 @@ type Client struct { HSM *hsm.Client HDInsight *hdinsight.Client HealthCare *healthcare.Client - HybridKubernetes *hybridkubernetes.Client IoTCentral *iotcentral.Client IoTHub *iothub.Client IoTTimeSeriesInsights *timeseriesinsights.Client @@ -238,6 +238,7 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.AppInsights = applicationInsights.NewClient(o) client.AppPlatform = appPlatform.NewClient(o) client.AppService = appService.NewClient(o) + client.ArcKubernetes = arckubernetes.NewClient(o) client.Attestation = attestation.NewClient(o) client.Authorization = authorization.NewClient(o) client.Automation = automation.NewClient(o) @@ -276,7 +277,6 @@ func (client *Client) Build(ctx context.Context, o *common.ClientOptions) error client.HSM = hsm.NewClient(o) client.HDInsight = hdinsight.NewClient(o) client.HealthCare = healthcare.NewClient(o) - client.HybridKubernetes = hybridkubernetes.NewClient(o) client.IoTCentral = iotcentral.NewClient(o) client.IoTHub = iothub.NewClient(o) client.IoTTimeSeriesInsights = timeseriesinsights.NewClient(o) diff --git a/internal/provider/services.go b/internal/provider/services.go index 35fba7a0bdfe..08124e5643ec 100644 --- a/internal/provider/services.go +++ b/internal/provider/services.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/appconfiguration" "github.com/hashicorp/terraform-provider-azurerm/internal/services/applicationinsights" "github.com/hashicorp/terraform-provider-azurerm/internal/services/appservice" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/services/attestation" "github.com/hashicorp/terraform-provider-azurerm/internal/services/authorization" "github.com/hashicorp/terraform-provider-azurerm/internal/services/automation" @@ -48,7 +49,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/services/healthcare" "github.com/hashicorp/terraform-provider-azurerm/internal/services/hpccache" "github.com/hashicorp/terraform-provider-azurerm/internal/services/hsm" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iotcentral" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iothub" "github.com/hashicorp/terraform-provider-azurerm/internal/services/iottimeseriesinsights" @@ -141,6 +141,7 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration { appconfiguration.Registration{}, springcloud.Registration{}, applicationinsights.Registration{}, + arckubernetes.Registration{}, attestation.Registration{}, authorization.Registration{}, automation.Registration{}, @@ -179,7 +180,6 @@ func SupportedUntypedServices() []sdk.UntypedServiceRegistration { hsm.Registration{}, hdinsight.Registration{}, healthcare.Registration{}, - hybridkubernetes.Registration{}, iothub.Registration{}, iotcentral.Registration{}, keyvault.Registration{}, diff --git a/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go similarity index 52% rename from internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go rename to internal/services/arckubernetes/arc_kubernetes_cluster_resource.go index 6d19ca3273e4..a8286a9a6a45 100644 --- a/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go @@ -1,30 +1,33 @@ -package hybridkubernetes +package arckubernetes import ( "fmt" + "regexp" "time" + azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" + "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" - "github.com/hashicorp/terraform-provider-azurerm/helpers/azure" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" "github.com/hashicorp/terraform-provider-azurerm/internal/location" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes" + arckubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" + "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" "github.com/hashicorp/terraform-provider-azurerm/utils" ) -func resourceHybridKubernetesConnectedCluster() *pluginsdk.Resource { +func resourceArcKubernetesCluster() *pluginsdk.Resource { return &pluginsdk.Resource{ - Create: resourceHybridKubernetesConnectedClusterCreate, - Read: resourceHybridKubernetesConnectedClusterRead, - Update: resourceHybridKubernetesConnectedClusterUpdate, - Delete: resourceHybridKubernetesConnectedClusterDelete, + Create: resourceArcKubernetesClusterCreate, + Read: resourceArcKubernetesClusterRead, + Update: resourceArcKubernetesClusterUpdate, + Delete: resourceArcKubernetesClusterDelete, Timeouts: &pluginsdk.ResourceTimeout{ Create: pluginsdk.DefaultTimeout(30 * time.Minute), @@ -34,7 +37,7 @@ func resourceHybridKubernetesConnectedCluster() *pluginsdk.Resource { }, Importer: pluginsdk.ImporterValidatingResourceId(func(id string) error { - _, err := hybridkubernetes.ParseConnectedClusterID(id) + _, err := arckubernetes.ParseConnectedClusterID(id) return err }), @@ -43,49 +46,76 @@ func resourceHybridKubernetesConnectedCluster() *pluginsdk.Resource { Type: pluginsdk.TypeString, Required: true, ForceNew: true, + ValidateFunc: validation.StringMatch( + regexp.MustCompile("^[-_a-zA-Z0-9]{1,260}$"), + "The name of Arc Kubernetes Cluster can only include alphanumeric characters, underscores, hyphens, has a maximum length of 260 characters, and must be unique.", + ), }, - "resource_group_name": azure.SchemaResourceGroupName(), + "resource_group_name": commonschema.ResourceGroupName(), "agent_public_key_certificate": { - Type: pluginsdk.TypeString, - Required: true, - ForceNew: true, + Type: pluginsdk.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: azValidate.Base64EncodedString, }, "distribution": { - Type: pluginsdk.TypeString, - Optional: true, - ForceNew: true, + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, }, - "identity": commonschema.SystemAssignedIdentityRequired(), + "identity": commonschema.SystemAssignedIdentityRequiredForceNew(), "infrastructure": { + Type: pluginsdk.TypeString, + Optional: true, + ForceNew: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "location": commonschema.Location(), + + "agent_version": { Type: pluginsdk.TypeString, - Optional: true, - ForceNew: true, + Computed: true, }, - "location": azure.SchemaLocation(), + "kubernetes_version": { + Type: pluginsdk.TypeString, + Computed: true, + }, - "provisioning_state": { + "offering": { Type: pluginsdk.TypeString, Computed: true, }, + "total_core_count": { + Type: pluginsdk.TypeInt, + Computed: true, + }, + + "total_node_count": { + Type: pluginsdk.TypeInt, + Computed: true, + }, + "tags": tags.Schema(), }, } } -func resourceHybridKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient +func resourceArcKubernetesClusterCreate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ArcKubernetes.ArcKubernetesClient subscriptionId := meta.(*clients.Client).Account.SubscriptionId ctx, cancel := timeouts.ForCreate(meta.(*clients.Client).StopContext, d) defer cancel() - id := hybridkubernetes.NewConnectedClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) + id := arckubernetes.NewConnectedClusterID(subscriptionId, d.Get("resource_group_name").(string), d.Get("name").(string)) if d.IsNewResource() { existing, err := client.ConnectedClusterGet(ctx, id) @@ -96,20 +126,20 @@ func resourceHybridKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, m } if !response.WasNotFound(existing.HttpResponse) { - return tf.ImportAsExistsError("azurerm_hybrid_kubernetes_connected_cluster", id.ID()) + return tf.ImportAsExistsError("azurerm_arc_kubernetes_cluster", id.ID()) } } - identity, err := identity.ExpandSystemAssigned(d.Get("identity").([]interface{})) + identityValue, err := identity.ExpandSystemAssigned(d.Get("identity").([]interface{})) if err != nil { return fmt.Errorf("expanding `identity`: %+v", err) } - location := azure.NormalizeLocation(d.Get("location")) - props := hybridkubernetes.ConnectedCluster{ - Identity: *identity, + location := location.Normalize(d.Get("location").(string)) + props := arckubernetes.ConnectedCluster{ + Identity: *identityValue, Location: location, - Properties: hybridkubernetes.ConnectedClusterProperties{ + Properties: arckubernetes.ConnectedClusterProperties{ AgentPublicKeyCertificate: d.Get("agent_public_key_certificate").(string), Distribution: utils.String(d.Get("distribution").(string)), Infrastructure: utils.String(d.Get("infrastructure").(string)), @@ -122,15 +152,15 @@ func resourceHybridKubernetesConnectedClusterCreate(d *pluginsdk.ResourceData, m } d.SetId(id.ID()) - return resourceHybridKubernetesConnectedClusterRead(d, meta) + return resourceArcKubernetesClusterRead(d, meta) } -func resourceHybridKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient +func resourceArcKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ArcKubernetes.ArcKubernetesClient ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := hybridkubernetes.ParseConnectedClusterID(d.Id()) + id, err := arckubernetes.ParseConnectedClusterID(d.Id()) if err != nil { return err } @@ -142,7 +172,7 @@ func resourceHybridKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, met return nil } - return fmt.Errorf("retrieving %s: %+v", id, err) + return fmt.Errorf("retrieving %s: %+v", *id, err) } d.Set("name", id.ClusterName) @@ -155,9 +185,13 @@ func resourceHybridKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, met d.Set("location", location.Normalize(model.Location)) props := model.Properties d.Set("agent_public_key_certificate", props.AgentPublicKeyCertificate) + d.Set("agent_version", props.AgentVersion) d.Set("distribution", props.Distribution) d.Set("infrastructure", props.Infrastructure) - d.Set("provisioning_state", props.ProvisioningState) + d.Set("kubernetes_version", props.KubernetesVersion) + d.Set("offering", props.Offering) + d.Set("total_core_count", props.TotalCoreCount) + d.Set("total_node_count", props.TotalNodeCount) if err := tagsHelper.FlattenAndSet(d, model.Tags); err != nil { return err @@ -167,39 +201,39 @@ func resourceHybridKubernetesConnectedClusterRead(d *pluginsdk.ResourceData, met return nil } -func resourceHybridKubernetesConnectedClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient +func resourceArcKubernetesClusterUpdate(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ArcKubernetes.ArcKubernetesClient ctx, cancel := timeouts.ForUpdate(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := hybridkubernetes.ParseConnectedClusterID(d.Id()) + id, err := arckubernetes.ParseConnectedClusterID(d.Id()) if err != nil { return err } - props := hybridkubernetes.ConnectedClusterPatch{ + props := arckubernetes.ConnectedClusterPatch{ Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), } if _, err := client.ConnectedClusterUpdate(ctx, *id, props); err != nil { - return fmt.Errorf("updating %s: %+v", id, err) + return fmt.Errorf("updating %s: %+v", *id, err) } - return resourceHybridKubernetesConnectedClusterRead(d, meta) + return resourceArcKubernetesClusterRead(d, meta) } -func resourceHybridKubernetesConnectedClusterDelete(d *pluginsdk.ResourceData, meta interface{}) error { - client := meta.(*clients.Client).HybridKubernetes.HybridKubernetesClient +func resourceArcKubernetesClusterDelete(d *pluginsdk.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).ArcKubernetes.ArcKubernetesClient ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := hybridkubernetes.ParseConnectedClusterID(d.Id()) + id, err := arckubernetes.ParseConnectedClusterID(d.Id()) if err != nil { return err } if err := client.ConnectedClusterDeleteThenPoll(ctx, *id); err != nil { - return fmt.Errorf("deleting %s: %+v", id, err) + return fmt.Errorf("deleting %s: %+v", *id, err) } return nil diff --git a/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go similarity index 66% rename from internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go rename to internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go index 91c6abf778e4..40ae6a0d5cee 100644 --- a/internal/services/hybridkubernetes/hybrid_kubernetes_connected_cluster_resource_test.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go @@ -1,11 +1,11 @@ -package hybridkubernetes_test +package arckubernetes_test import ( "context" "fmt" "testing" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes" + arckubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" @@ -15,11 +15,11 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/utils" ) -type HybridKubernetesConnectedClusterResource struct{} +type ArcKubernetesClusterResource struct{} -func TestAccHybridKubernetesConnectedCluster_basic(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") - r := HybridKubernetesConnectedClusterResource{} +func TestAccArcKubernetesCluster_basic(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") + r := ArcKubernetesClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), @@ -31,9 +31,9 @@ func TestAccHybridKubernetesConnectedCluster_basic(t *testing.T) { }) } -func TestAccHybridKubernetesConnectedCluster_requiresImport(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") - r := HybridKubernetesConnectedClusterResource{} +func TestAccArcKubernetesCluster_requiresImport(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") + r := ArcKubernetesClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.basic(data), @@ -45,9 +45,9 @@ func TestAccHybridKubernetesConnectedCluster_requiresImport(t *testing.T) { }) } -func TestAccHybridKubernetesConnectedCluster_complete(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") - r := HybridKubernetesConnectedClusterResource{} +func TestAccArcKubernetesCluster_complete(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") + r := ArcKubernetesClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), @@ -59,9 +59,9 @@ func TestAccHybridKubernetesConnectedCluster_complete(t *testing.T) { }) } -func TestAccHybridKubernetesConnectedCluster_update(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_hybrid_kubernetes_connected_cluster", "test") - r := HybridKubernetesConnectedClusterResource{} +func TestAccArcKubernetesCluster_update(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") + r := ArcKubernetesClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { Config: r.complete(data), @@ -80,13 +80,13 @@ func TestAccHybridKubernetesConnectedCluster_update(t *testing.T) { }) } -func (r HybridKubernetesConnectedClusterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { - id, err := hybridkubernetes.ParseConnectedClusterID(state.ID) +func (r ArcKubernetesClusterResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) { + id, err := arckubernetes.ParseConnectedClusterID(state.ID) if err != nil { return nil, err } - client := clients.HybridKubernetes.HybridKubernetesClient + client := clients.ArcKubernetes.ArcKubernetesClient resp, err := client.ConnectedClusterGet(ctx, *id) if err != nil { if response.WasNotFound(resp.HttpResponse) { @@ -94,29 +94,29 @@ func (r HybridKubernetesConnectedClusterResource) Exists(ctx context.Context, cl } return nil, fmt.Errorf("retrieving %s: %+v", id, err) } - return utils.Bool(true), nil + return utils.Bool(resp.Model != nil), nil } -func (r HybridKubernetesConnectedClusterResource) template(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) template(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} } resource "azurerm_resource_group" "test" { - name = "acctest-kubernetes-%d" + name = "acctest-rg-%d" location = "%s" } `, data.RandomInteger, data.Locations.Primary) } -func (r HybridKubernetesConnectedClusterResource) basic(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) basic(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` %s -resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { - name = "acctest-k-%d" +resource "azurerm_arc_kubernetes_cluster" "test" { + name = "acctest-akcc-%d" resource_group_name = azurerm_resource_group.test.name agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" identity { @@ -127,30 +127,30 @@ resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { `, template, data.RandomInteger, data.Locations.Primary) } -func (r HybridKubernetesConnectedClusterResource) requiresImport(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) requiresImport(data acceptance.TestData) string { config := r.basic(data) return fmt.Sprintf(` %s -resource "azurerm_hybrid_kubernetes_connected_cluster" "import" { - name = azurerm_hybrid_kubernetes_connected_cluster.test.name - resource_group_name = azurerm_resource_group.test.name - agent_public_key_certificate = azurerm_hybrid_kubernetes_connected_cluster.test.agent_public_key_certificate +resource "azurerm_arc_kubernetes_cluster" "import" { + name = azurerm_arc_kubernetes_cluster.test.name + resource_group_name = azurerm_arc_kubernetes_cluster.test.resource_group_name + agent_public_key_certificate = azurerm_arc_kubernetes_cluster.test.agent_public_key_certificate identity { type = "SystemAssigned" } - location = azurerm_hybrid_kubernetes_connected_cluster.test.location + location = azurerm_arc_kubernetes_cluster.test.location } `, config) } -func (r HybridKubernetesConnectedClusterResource) complete(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) complete(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` %s -resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { - name = "acctest-k-%d" +resource "azurerm_arc_kubernetes_cluster" "test" { + name = "acctest-akcc-%d" resource_group_name = azurerm_resource_group.test.name agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" distribution = "kind" @@ -168,13 +168,13 @@ resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { `, template, data.RandomInteger, data.Locations.Primary) } -func (r HybridKubernetesConnectedClusterResource) update(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) update(data acceptance.TestData) string { template := r.template(data) return fmt.Sprintf(` %s -resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { - name = "acctest-k-%d" +resource "azurerm_arc_kubernetes_cluster" "test" { + name = "acctest-akcc-%d" resource_group_name = azurerm_resource_group.test.name agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" distribution = "kind" diff --git a/internal/services/arckubernetes/client/client.go b/internal/services/arckubernetes/client/client.go new file mode 100644 index 000000000000..b748f6da3ef2 --- /dev/null +++ b/internal/services/arckubernetes/client/client.go @@ -0,0 +1,20 @@ +package client + +import ( + "github.com/hashicorp/terraform-provider-azurerm/internal/common" + "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" +) + +type Client struct { + ArcKubernetesClient *hybridkubernetes.HybridKubernetesClient +} + +func NewClient(o *common.ClientOptions) *Client { + + arcKubernetesClient := hybridkubernetes.NewHybridKubernetesClientWithBaseURI(o.ResourceManagerEndpoint) + o.ConfigureClient(&arcKubernetesClient.Client, o.ResourceManagerAuthorizer) + + return &Client{ + ArcKubernetesClient: &arcKubernetesClient, + } +} diff --git a/internal/services/hybridkubernetes/registration.go b/internal/services/arckubernetes/registration.go similarity index 81% rename from internal/services/hybridkubernetes/registration.go rename to internal/services/arckubernetes/registration.go index c8e614e3e3f0..8a9257a24970 100644 --- a/internal/services/hybridkubernetes/registration.go +++ b/internal/services/arckubernetes/registration.go @@ -1,4 +1,4 @@ -package hybridkubernetes +package arckubernetes import "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" @@ -6,13 +6,13 @@ type Registration struct{} // Name is the name of this Service func (r Registration) Name() string { - return "HybridKubernetes" + return "ArcKubernetes" } // WebsiteCategories returns a list of categories which can be used for the sidebar func (r Registration) WebsiteCategories() []string { return []string{ - "HybridKubernetes", + "ArcKubernetes", } } @@ -24,6 +24,6 @@ func (r Registration) SupportedDataSources() map[string]*pluginsdk.Resource { // SupportedResources returns the supported Resources supported by this Service func (r Registration) SupportedResources() map[string]*pluginsdk.Resource { return map[string]*pluginsdk.Resource{ - "azurerm_hybrid_kubernetes_connected_cluster": resourceHybridKubernetesConnectedCluster(), + "azurerm_arc_kubernetes_cluster": resourceArcKubernetesCluster(), } } diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/client.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/client.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/client.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/client.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/constants.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/constants.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/constants.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/constants.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go diff --git a/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/version.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/version.go similarity index 100% rename from internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes/version.go rename to internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/version.go diff --git a/internal/services/hybridkubernetes/client/client.go b/internal/services/hybridkubernetes/client/client.go deleted file mode 100644 index 3b4bb1c95877..000000000000 --- a/internal/services/hybridkubernetes/client/client.go +++ /dev/null @@ -1,20 +0,0 @@ -package client - -import ( - "github.com/hashicorp/terraform-provider-azurerm/internal/common" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/hybridkubernetes/sdk/2021-10-01/hybridkubernetes" -) - -type Client struct { - HybridKubernetesClient *hybridkubernetes.HybridKubernetesClient -} - -func NewClient(o *common.ClientOptions) *Client { - - hybridKubernetesClient := hybridkubernetes.NewHybridKubernetesClientWithBaseURI(o.ResourceManagerEndpoint) - o.ConfigureClient(&hybridKubernetesClient.Client, o.ResourceManagerAuthorizer) - - return &Client{ - HybridKubernetesClient: &hybridKubernetesClient, - } -} diff --git a/internal/services/hybridkubernetes/resourceids.go b/internal/services/hybridkubernetes/resourceids.go deleted file mode 100644 index 98eac49ded57..000000000000 --- a/internal/services/hybridkubernetes/resourceids.go +++ /dev/null @@ -1,3 +0,0 @@ -package hybridkubernetes - -//go:generate go run ../../tools/generator-resource-id/main.go -path=./ -name=HybridKubernetesConnectedCluster -id=/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 diff --git a/website/allowed-subcategories b/website/allowed-subcategories index 421136f968a1..fc4916ab5c98 100644 --- a/website/allowed-subcategories +++ b/website/allowed-subcategories @@ -6,6 +6,7 @@ Analysis Services App Configuration App Service (Web Apps) Application Insights +ArcKubernetes Attestation Authorization Automation @@ -42,7 +43,6 @@ Disks HDInsight Hardware Security Module Healthcare -HybridKubernetes IoT Central IoT Hub Key Vault diff --git a/website/docs/r/arc_kubernetes_cluster.html.markdown b/website/docs/r/arc_kubernetes_cluster.html.markdown new file mode 100644 index 000000000000..8ae3390abbfd --- /dev/null +++ b/website/docs/r/arc_kubernetes_cluster.html.markdown @@ -0,0 +1,106 @@ +--- +subcategory: "ArcKubernetes" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_arc_kubernetes_cluster" +description: |- + Manages an Arc Kubernetes Cluster. +--- + +# azurerm_arc_kubernetes_cluster + +Manages an Arc Kubernetes Cluster. + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "West Europe" +} + +resource "azurerm_arc_kubernetes_cluster" "example" { + name = "example-akcc" + resource_group_name = azurerm_resource_group.example.name + location = "West Europe" + distribution = "azure" + infrastructure = "azure" + agent_public_key_certificate = "xxxxxxxxxxxxxxxxxxx" + + identity { + type = "SystemAssigned" + } + + tags = { + ENV = "Test" + } +} +``` + +## Arguments Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name which should be used for this Arc Kubernetes Cluster. Changing this forces a new Arc Kubernetes Cluster to be created. + +* `resource_group_name` - (Required) Specifies the name of the Resource Group where the Arc Kubernetes Cluster should exist. Changing this forces a new Arc Kubernetes Cluster to be created. + +* `agent_public_key_certificate` - (Required) Specifies the base64-encoded public certificate used by the agent to do the initial handshake to the backend services in Azure. Changing this forces a new Arc Kubernetes Cluster to be created. + +* `identity` - (Required) An `identity` block as defined below. Changing this forces a new Arc Kubernetes Cluster to be created. + +* `location` - (Required) Specifies the Azure Region where the Arc Kubernetes Cluster should exist. Changing this forces a new Arc Kubernetes Cluster to be created. + +* `distribution` - (Optional) Specifies the distribution running on this Arc Kubernetes Cluster. Changing this forces a new Arc Kubernetes Cluster to be created. + +* `infrastructure` - (Optional) Specifies the infrastructure on which the Arc Kubernetes Cluster is running on. Changing this forces a new Arc Kubernetes Cluster to be created. + +* `tags` - (Optional) A mapping of tags which should be assigned to the Arc Kubernetes Cluster. + +--- + +An `identity` block supports the following: + +* `type` - (Required) Specifies the type of Managed Service Identity assigned to this Arc Kubernetes Cluster. At this time the only possible value is `SystemAssigned`. + +## Attributes Reference + +In addition to the Arguments listed above - the following Attributes are exported: + +* `id` - The ID of the Arc Kubernetes Cluster. + +* `agent_version` - Version of the agent running on the cluster resource. + +* `identity` - An `identity` block as defined below. + +* `kubernetes_version` - The Kubernetes version of the cluster resource. + +* `offering` - The cluster offering. + +* `total_core_count` - Number of CPU cores present in the cluster resource. + +* `total_node_count` - Number of nodes present in the cluster resource. + +--- + +An `identity` block exports the following: + +* `principal_id` - The Principal ID associated with this Managed Service Identity. + +* `tenant_id` - The Tenant ID associated with this Managed Service Identity. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Arc Kubernetes Cluster. +* `read` - (Defaults to 5 minutes) Used when retrieving the Arc Kubernetes Cluster. +* `update` - (Defaults to 30 minutes) Used when updating the Arc Kubernetes Cluster. +* `delete` - (Defaults to 30 minutes) Used when deleting the Arc Kubernetes Cluster. + +## Import + +Arc Kubernetes Cluster can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_arc_kubernetes_cluster.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 +``` diff --git a/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown b/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown deleted file mode 100644 index 4e8c4ba846fe..000000000000 --- a/website/docs/r/hybrid_kubernetes_connected_cluster.html.markdown +++ /dev/null @@ -1,98 +0,0 @@ ---- -subcategory: "HybridKubernetes" -layout: "azurerm" -page_title: "Azure Resource Manager: azurerm_hybrid_kubernetes_connected_cluster" -description: |- - Manages a HybridKubernetes connected cluster. ---- - -# azurerm_hybrid_kubernetes_connected_cluster - -Manages a HybridKubernetes connected cluster. - -## Example Usage - -```hcl -resource "azurerm_resource_group" "test" { - name = "example-resources" - location = "West Europe" -} - -resource "azurerm_hybrid_kubernetes_connected_cluster" "test" { - name = "example-connected-cluster" - resource_group_name = azurerm_resource_group.test.name - agent_public_key_certificate = "xxxxxxxxxxxxxxxxxxx" - distribution = "gke" - - identity { - type = "SystemAssigned" - } - infrastructure = "gcp" - location = "West Europe" - - tags = { - ENV = "Test" - } -} -``` - -## Arguments Reference - -The following arguments are supported: - -* `name` - (Required) The name which should be used for this HybridKubernetes Connected Cluster. Changing this forces a new HybridKubernetes Connected Cluster to be created. - -* `resource_group_name` - (Required) The name of the Resource Group where the HybridKubernetes connected cluster should exist. Changing this forces a new HybridKubernetes connected cluster to be created. - -* `agent_public_key_certificate` - (Required) Base64 encoded public certificate used by the agent to do the initial handshake to the backend services in Azure. Changing this forces a new HybridKubernetes connected cluster to be created. - -* `identity` - (Required) An `identity` block as defined below. - -* `location` - (Required) The Azure Region where the HybridKubernetes connected cluster should exist. Changing this forces a new HybridKubernetes connected cluster to be created. - -* `distribution` - (Optional) The HybridKubernetes distribution running on this connected cluster. Changing this forces a new HybridKubernetes connected cluster to be created. - -* `infrastructure` - (Optional) The infrastructure on which the HybridKubernetes cluster represented by this connected cluster is running on. Changing this forces a new HybridKubernetes connected cluster to be created. - -* `tags` - (Optional) A mapping of tags which should be assigned to the HybridKubernetes connected cluster. - ---- - -An `identity` block exports the following: - -* `type` - (Required) Specifies the type of Managed Service Identity. Possible values are `SystemAssigned`. - -## Attributes Reference - -In addition to the Arguments listed above - the following Attributes are exported: - -* `id` - The ID of the HybridKubernetes connected cluster. - -* `identity` - An `identity` block as defined below. - -* `provisioning_state` - The current deployment state of connected clusters. - ---- - -An `identity` block exports the following: - -* `principal_id` - The Principal ID associated with this Managed Service Identity. - -* `tenant_id` - The Tenant ID associated with this Managed Service Identity. - -## Timeouts - -The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: - -* `create` - (Defaults to 30 minutes) Used when creating the HybridKubernetes connected cluster. -* `read` - (Defaults to 5 minutes) Used when retrieving the HybridKubernetes connected cluster. -* `update` - (Defaults to 30 minutes) Used when updating the HybridKubernetes connected cluster. -* `delete` - (Defaults to 30 minutes) Used when deleting the HybridKubernetes connected cluster. - -## Import - -HybridKubernetes connected cluster can be imported using the `resource id`, e.g. - -```shell -terraform import azurerm_hybrid_kubernetes_connected_cluster.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/resourceGroup1/providers/Microsoft.Kubernetes/connectedClusters/cluster1 -``` From 6ae277bae1a30c3888596405a865b93a825d1fd7 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Mon, 7 Mar 2022 14:30:48 +0800 Subject: [PATCH 05/11] update --- .../arckubernetes/arc_kubernetes_cluster_resource.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go index a8286a9a6a45..64eadf3d5e25 100644 --- a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go @@ -5,15 +5,14 @@ import ( "regexp" "time" - azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" - "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/location" tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" + azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - "github.com/hashicorp/terraform-provider-azurerm/internal/location" arckubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" From 41fca387993fdec1a73fa59949f69de1d8559fd7 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Mon, 13 Feb 2023 16:52:43 +0800 Subject: [PATCH 06/11] auto run test by remote-exec provision --- .../arc_kubernetes_cluster_resource.go | 27 +- .../arc_kubernetes_cluster_resource_test.go | 232 +++++++++++++--- .../arckubernetes/testdata/install_agent.py | 249 ++++++++++++++++++ .../testdata/install_agent.sh.tftpl | 38 +++ .../services/arckubernetes/testdata/kind.yaml | 20 ++ .../arckubernetes/testdata/private.pem | 51 ++++ .../arckubernetes/testdata/public.cer | Bin 0 -> 526 bytes .../r/arc_kubernetes_cluster.html.markdown | 12 +- 8 files changed, 564 insertions(+), 65 deletions(-) create mode 100644 internal/services/arckubernetes/testdata/install_agent.py create mode 100644 internal/services/arckubernetes/testdata/install_agent.sh.tftpl create mode 100644 internal/services/arckubernetes/testdata/kind.yaml create mode 100644 internal/services/arckubernetes/testdata/private.pem create mode 100644 internal/services/arckubernetes/testdata/public.cer diff --git a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go index 64eadf3d5e25..139afcb3e747 100644 --- a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go @@ -18,7 +18,6 @@ import ( "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" "github.com/hashicorp/terraform-provider-azurerm/internal/timeouts" - "github.com/hashicorp/terraform-provider-azurerm/utils" ) func resourceArcKubernetesCluster() *pluginsdk.Resource { @@ -60,22 +59,8 @@ func resourceArcKubernetesCluster() *pluginsdk.Resource { ValidateFunc: azValidate.Base64EncodedString, }, - "distribution": { - Type: pluginsdk.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "identity": commonschema.SystemAssignedIdentityRequiredForceNew(), - "infrastructure": { - Type: pluginsdk.TypeString, - Optional: true, - ForceNew: true, - ValidateFunc: validation.StringIsNotEmpty, - }, - "location": commonschema.Location(), "agent_version": { @@ -83,6 +68,16 @@ func resourceArcKubernetesCluster() *pluginsdk.Resource { Computed: true, }, + "distribution": { + Type: pluginsdk.TypeString, + Computed: true, + }, + + "infrastructure": { + Type: pluginsdk.TypeString, + Computed: true, + }, + "kubernetes_version": { Type: pluginsdk.TypeString, Computed: true, @@ -140,8 +135,6 @@ func resourceArcKubernetesClusterCreate(d *pluginsdk.ResourceData, meta interfac Location: location, Properties: arckubernetes.ConnectedClusterProperties{ AgentPublicKeyCertificate: d.Get("agent_public_key_certificate").(string), - Distribution: utils.String(d.Get("distribution").(string)), - Infrastructure: utils.String(d.Get("infrastructure").(string)), }, Tags: tagsHelper.Expand(d.Get("tags").(map[string]interface{})), } diff --git a/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go index 40ae6a0d5cee..01bd75e6d343 100644 --- a/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go @@ -3,6 +3,8 @@ package arckubernetes_test import ( "context" "fmt" + "math/rand" + "os" "testing" arckubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" @@ -28,38 +30,33 @@ func TestAccArcKubernetesCluster_basic(t *testing.T) { ), }, data.ImportStep(), - }) -} - -func TestAccArcKubernetesCluster_requiresImport(t *testing.T) { - data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") - r := ArcKubernetesClusterResource{} - data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.update(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("distribution").HasValue("kind"), + check.That(data.ResourceName).Key("infrastructure").HasValue("generic"), ), }, - data.RequiresImportErrorStep(r.requiresImport), + data.ImportStep(), }) } -func TestAccArcKubernetesCluster_complete(t *testing.T) { +func TestAccArcKubernetesCluster_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") r := ArcKubernetesClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.complete(data), + Config: r.basic(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.ImportStep(), + data.RequiresImportErrorStep(r.requiresImport), }) } -func TestAccArcKubernetesCluster_update(t *testing.T) { +func TestAccArcKubernetesCluster_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") r := ArcKubernetesClusterResource{} data.ResourceTest(t, r, []acceptance.TestStep{ @@ -74,6 +71,8 @@ func TestAccArcKubernetesCluster_update(t *testing.T) { Config: r.update(data), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("distribution").HasValue("kind"), + check.That(data.ResourceName).Key("infrastructure").HasValue("generic"), ), }, data.ImportStep(), @@ -97,34 +96,172 @@ func (r ArcKubernetesClusterResource) Exists(ctx context.Context, clients *clien return utils.Bool(resp.Model != nil), nil } -func (r ArcKubernetesClusterResource) template(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) template(data acceptance.TestData, credential string) string { return fmt.Sprintf(` provider "azurerm" { - features {} + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } } resource "azurerm_resource_group" "test" { - name = "acctest-rg-%d" - location = "%s" + name = "acctestRG-%[1]d" + location = "%[2]s" +} + +resource "azurerm_virtual_network" "test" { + name = "acctestnw-%[1]d" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_subnet" "test" { + name = "internal" + resource_group_name = azurerm_resource_group.test.name + virtual_network_name = azurerm_virtual_network.test.name + address_prefixes = ["10.0.2.0/24"] +} + +resource "azurerm_public_ip" "test" { + name = "acctestpip-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + allocation_method = "Static" +} + +resource "azurerm_network_interface" "test" { + name = "acctestnic-%[1]d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + ip_configuration { + name = "internal" + subnet_id = azurerm_subnet.test.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.test.id + } +} + +resource "azurerm_network_security_group" "my_terraform_nsg" { + name = "myNetworkSecurityGroup" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + security_rule { + name = "SSH" + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "22" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +resource "azurerm_network_interface_security_group_association" "example" { + network_interface_id = azurerm_network_interface.test.id + network_security_group_id = azurerm_network_security_group.my_terraform_nsg.id +} + +resource "azurerm_linux_virtual_machine" "test" { + name = "acctestVM-%[1]d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + size = "Standard_F2" + admin_username = "adminuser" + admin_password = "%[3]s" + provision_vm_agent = false + allow_extension_operations = false + disable_password_authentication = false + network_interface_ids = [ + azurerm_network_interface.test.id, + ] + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "18.04-LTS" + version = "latest" + } +} +`, data.RandomInteger, data.Locations.Primary, credential) +} + +func (r ArcKubernetesClusterResource) provisionTemplate(data acceptance.TestData, credential string) string { + return fmt.Sprintf(` +connection { + type = "ssh" + host = azurerm_public_ip.test.ip_address + user = "adminuser" + password = "%[1]s" +} + +provisioner "file" { + content = templatefile("testdata/install_agent.sh.tftpl", { + subscription_id = "%[4]s" + resource_group_name = azurerm_resource_group.test.name + cluster_name = "acctest-akcc-%[2]d" + location = azurerm_resource_group.test.location + tenant_id = "%[5]s" + working_dir = "%[3]s" + }) + destination = "%[3]s/install_agent.sh" +} + +provisioner "file" { + source = "testdata/install_agent.py" + destination = "%[3]s/install_agent.py" } -`, data.RandomInteger, data.Locations.Primary) + +provisioner "file" { + source = "testdata/kind.yaml" + destination = "%[3]s/kind.yaml" +} + +provisioner "file" { + source = "testdata/private.pem" + destination = "%[3]s/private.pem" +} + +provisioner "remote-exec" { + inline = [ + "sudo sed -i 's/\r$//' %[3]s/install_agent.sh", + "sudo chmod +x %[3]s/install_agent.sh", + "bash %[3]s/install_agent.sh > %[3]s/agent_log", + ] +} +`, credential, data.RandomInteger, "/home/adminuser", os.Getenv("ARM_SUBSCRIPTION_ID"), os.Getenv("ARM_TENANT_ID")) } func (r ArcKubernetesClusterResource) basic(data acceptance.TestData) string { - template := r.template(data) + credential := fmt.Sprintf("P@$$w0rd%d!", rand.Intn(10000)) + template := r.template(data, credential) + provisionTemplate := r.provisionTemplate(data, credential) return fmt.Sprintf(` - %s + %[1]s resource "azurerm_arc_kubernetes_cluster" "test" { - name = "acctest-akcc-%d" + name = "acctest-akcc-%[2]d" resource_group_name = azurerm_resource_group.test.name - agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" + location = azurerm_resource_group.test.location + agent_public_key_certificate = filebase64("testdata/public.cer") identity { type = "SystemAssigned" } - location = "%s" + + %[3]s + + depends_on = [ + azurerm_linux_virtual_machine.test + ] } -`, template, data.RandomInteger, data.Locations.Primary) +`, template, data.RandomInteger, provisionTemplate) } func (r ArcKubernetesClusterResource) requiresImport(data acceptance.TestData) string { @@ -135,59 +272,72 @@ func (r ArcKubernetesClusterResource) requiresImport(data acceptance.TestData) s resource "azurerm_arc_kubernetes_cluster" "import" { name = azurerm_arc_kubernetes_cluster.test.name resource_group_name = azurerm_arc_kubernetes_cluster.test.resource_group_name + location = azurerm_arc_kubernetes_cluster.test.location agent_public_key_certificate = azurerm_arc_kubernetes_cluster.test.agent_public_key_certificate + identity { type = "SystemAssigned" } - location = azurerm_arc_kubernetes_cluster.test.location } `, config) } func (r ArcKubernetesClusterResource) complete(data acceptance.TestData) string { - template := r.template(data) + credential := fmt.Sprintf("P@$$w0rd%d!", rand.Intn(10000)) + template := r.template(data, credential) + provisionTemplate := r.provisionTemplate(data, credential) return fmt.Sprintf(` - %s + %[1]s resource "azurerm_arc_kubernetes_cluster" "test" { - name = "acctest-akcc-%d" + name = "acctest-akcc-%[2]d" resource_group_name = azurerm_resource_group.test.name - agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" - distribution = "kind" + location = azurerm_resource_group.test.location + agent_public_key_certificate = filebase64("testdata/public.cer") identity { type = "SystemAssigned" } - infrastructure = "generic" - location = "%s" tags = { ENV = "Test" } + + %[3]s + + depends_on = [ + azurerm_linux_virtual_machine.test + ] } -`, template, data.RandomInteger, data.Locations.Primary) +`, template, data.RandomInteger, provisionTemplate) } func (r ArcKubernetesClusterResource) update(data acceptance.TestData) string { - template := r.template(data) + credential := fmt.Sprintf("P@$$w0rd%d!", rand.Intn(10000)) + template := r.template(data, credential) + provisionTemplate := r.provisionTemplate(data, credential) return fmt.Sprintf(` - %s + %[1]s resource "azurerm_arc_kubernetes_cluster" "test" { - name = "acctest-akcc-%d" + name = "acctest-akcc-%[2]d" resource_group_name = azurerm_resource_group.test.name - agent_public_key_certificate = "MIICCgKCAgEAsSpALlON3394ysLQdRSy6cCBwL08NgZp7c1xsy0kQH/wHuixfoCwtL1OZ0a5kqod9vE6L8ICsXAE+iEdU1OspcJxL9J/gSyiOCMYPUabbYRXFy5x258RRLtn60NoaqcaDW+Z80HLwJOMECdJ/yDkuuNbnL0J2cyR8/WXjoeee8cG52QmDuxB6a4ROOushroIE2NS3FuhJh3b3Ddj+NU3gfbgIjjCMJQDpJWqUi/68lB33K1FQwuY1CCT8rKC5dDRKnlTgEWtnhBBly1D+C9GPTh7l9NTxcAEcBKo1ZIkMcixcS+gTcsTtDRRwuTtt8kybohfRMvmBA/S9bkD6cCaGJMe8YerOyJsDd4zSUHz/qN9iTt8FDdFcCIjhEdsMKl350wMj7+UNPvchlRAAve3oCIntW9063fDlQHrsaPfhCplTlKLAt1jcUkGSaeuylnRi8te+hmDCIhmo8wDqMv8Yvy7BTX4bYMg+6j0EGiIKPMRf5NHt6bXbiWEcO5LWEwgCbvpTjf7XdrU/xJ+eB+uAP1etvE0tCYAEFisfFnqNZxMQCFjovI0ZNxizrZOBznk15fWTr4KTNsPUTkEvbJfZPQqc/QyC5yqIAFHAAj+jusd4tK9f19nCsoi78xeKGH2s1zrD0AmBNGUrPLPVzgfdueadJKbVbiPteYec9qSG50CAwEAAQ==" - distribution = "kind" + location = azurerm_resource_group.test.location + agent_public_key_certificate = filebase64("testdata/public.cer") identity { type = "SystemAssigned" } - infrastructure = "generic" - location = "%s" tags = { ENV = "TestUpdate" } + + %[3]s + + depends_on = [ + azurerm_linux_virtual_machine.test + ] } -`, template, data.RandomInteger, data.Locations.Primary) +`, template, data.RandomInteger, provisionTemplate) } diff --git a/internal/services/arckubernetes/testdata/install_agent.py b/internal/services/arckubernetes/testdata/install_agent.py new file mode 100644 index 000000000000..90f1851333ee --- /dev/null +++ b/internal/services/arckubernetes/testdata/install_agent.py @@ -0,0 +1,249 @@ +import argparse +import json +import logging as logger +import os +import platform +import shutil +import stat +import subprocess +import time +import urllib +from subprocess import PIPE, Popen +from urllib import request + +HELM_VERSION = 'v3.6.3' +HELM_STORAGE_URL = "https://k8connecthelm.azureedge.net" +Pre_Onboarding_Helm_Charts_Folder_Name = 'PreOnboardingChecksCharts' + + +def get_helm_registry(config_dp_endpoint): + # Setting uri + get_chart_location_url = "{}/{}/GetLatestHelmPackagePath?api-version=2019-11-01-preview".format( + config_dp_endpoint, 'azure-arc-k8sagents') + + try: + response = urllib.request.urlopen( + request.Request(get_chart_location_url, method="POST")) + except Exception as e: + raise Exception("Failed to get helm registry." + str(e)) + + try: + return json.load(response).get('repositoryPath') + except Exception as e: + raise Exception( + "Error while fetching helm chart registry path from JSON response: " + str(e)) + + +def pull_helm_chart(registry_path, kube_config, kube_context, helm_client_location, chart_name='azure-arc-k8sagents', retry_count=5, retry_delay=3): + cmd_helm_chart_pull = [helm_client_location, + "chart", "pull", registry_path] + if kube_config: + cmd_helm_chart_pull.extend(["--kubeconfig", kube_config]) + if kube_context: + cmd_helm_chart_pull.extend(["--kube-context", kube_context]) + for i in range(retry_count): + response_helm_chart_pull = subprocess.Popen( + cmd_helm_chart_pull, stdout=PIPE, stderr=PIPE) + _, error_helm_chart_pull = response_helm_chart_pull.communicate() + if response_helm_chart_pull.returncode != 0: + if i == retry_count - 1: + raise Exception("Unable to pull {} helm chart from the registry '{}': ".format( + chart_name, registry_path) + error_helm_chart_pull.decode("ascii")) + time.sleep(retry_delay) + else: + break + + +def export_helm_chart(registry_path, chart_export_path, kube_config, kube_context, helm_client_location, chart_name='azure-arc-k8sagents'): + cmd_helm_chart_export = [helm_client_location, "chart", + "export", registry_path, "--destination", chart_export_path] + if kube_config: + cmd_helm_chart_export.extend(["--kubeconfig", kube_config]) + if kube_context: + cmd_helm_chart_export.extend(["--kube-context", kube_context]) + response_helm_chart_export = subprocess.Popen( + cmd_helm_chart_export, stdout=PIPE, stderr=PIPE) + _, error_helm_chart_export = response_helm_chart_export.communicate() + if response_helm_chart_export.returncode != 0: + raise Exception("Unable to export {} helm chart from the registry '{}': ".format( + chart_name, registry_path) + error_helm_chart_export.decode("ascii")) + + +def get_chart_path(registry_path, kube_config, kube_context, helm_client_location, chart_folder_name='AzureArcCharts', chart_name='azure-arc-k8sagents'): + # Pulling helm chart from registry + os.environ['HELM_EXPERIMENTAL_OCI'] = '1' + pull_helm_chart(registry_path, kube_config, kube_context, + helm_client_location, chart_name) + + # Exporting helm chart after cleanup + chart_export_path = os.path.join( + os.path.expanduser('~'), '.azure', chart_folder_name) + try: + if os.path.isdir(chart_export_path): + shutil.rmtree(chart_export_path) + except: + logger.warning("Unable to cleanup the {} already present on the machine. In case of failure, please cleanup the directory '{}' and try again.".format( + chart_folder_name, chart_export_path)) + + export_helm_chart(registry_path, chart_export_path, kube_config, + kube_context, helm_client_location, chart_name) + + # Returning helm chart path + helm_chart_path = os.path.join(chart_export_path, chart_name) + if chart_folder_name == Pre_Onboarding_Helm_Charts_Folder_Name: + chart_path = helm_chart_path + else: + chart_path = os.getenv('HELMCHART') if os.getenv( + 'HELMCHART') else helm_chart_path + + return chart_path + + +def install_helm_client(): + # Fetch system related info + operating_system = platform.system().lower() + platform.machine() + + # Set helm binary download & install locations + if (operating_system == 'windows'): + download_location_string = f'.azure\\helm\\{HELM_VERSION}\\helm-{HELM_VERSION}-{operating_system}-amd64.zip' + install_location_string = f'.azure\\helm\\{HELM_VERSION}\\{operating_system}-amd64\\helm.exe' + requestUri = f'{HELM_STORAGE_URL}/helm/helm-{HELM_VERSION}-{operating_system}-amd64.zip' + elif (operating_system == 'linux' or operating_system == 'darwin'): + download_location_string = f'.azure/helm/{HELM_VERSION}/helm-{HELM_VERSION}-{operating_system}-amd64.tar.gz' + install_location_string = f'.azure/helm/{HELM_VERSION}/{operating_system}-amd64/helm' + requestUri = f'{HELM_STORAGE_URL}/helm/helm-{HELM_VERSION}-{operating_system}-amd64.tar.gz' + else: + raise Exception( + f'The {operating_system} platform is not currently supported for installing helm client.') + + download_location = os.path.expanduser( + os.path.join('~', download_location_string)) + download_dir = os.path.dirname(download_location) + install_location = os.path.expanduser( + os.path.join('~', install_location_string)) + + # Download compressed halm binary if not already present + if not os.path.isfile(download_location): + # Creating the helm folder if it doesnt exist + if not os.path.exists(download_dir): + try: + os.makedirs(download_dir) + except Exception as e: + raise Exception("Failed to create helm directory." + str(e)) + + # Downloading compressed helm client executable + logger.warning( + "Downloading helm client for first time. This can take few minutes...") + try: + response = urllib.request.urlopen(requestUri) + except Exception as e: + raise Exception("Failed to download helm client." + str(e)) + + responseContent = response.read() + response.close() + + # Creating the compressed helm binaries + try: + with open(download_location, 'wb') as f: + f.write(responseContent) + except Exception as e: + raise Exception("Failed to create helm executable." + str(e)) + + # Extract compressed helm binary + if not os.path.isfile(install_location): + try: + shutil.unpack_archive(download_location, download_dir) + os.chmod(install_location, os.stat( + install_location).st_mode | stat.S_IXUSR) + except Exception as e: + raise Exception("Failed to extract helm executable." + str(e)) + + return install_location + + +def helm_install_release(chart_path, subscription_id, kubernetes_distro, kubernetes_infra, resource_group_name, cluster_name, + location, onboarding_tenant_id, private_key_pem, + no_wait, cloud_name, helm_client_location, onboarding_timeout="600"): + cmd_helm_install = [helm_client_location, "upgrade", "--install", "azure-arc", chart_path, + "--set", "global.subscriptionId={}".format( + subscription_id), + "--set", "global.kubernetesDistro={}".format( + kubernetes_distro), + "--set", "global.kubernetesInfra={}".format( + kubernetes_infra), + "--set", "global.resourceGroupName={}".format( + resource_group_name), + "--set", "global.resourceName={}".format(cluster_name), + "--set", "global.location={}".format(location), + "--set", "global.tenantId={}".format( + onboarding_tenant_id), + "--set", "global.onboardingPrivateKey={}".format( + private_key_pem), + "--set", "systemDefaultValues.spnOnboarding=false", + "--set", "global.azureEnvironment={}".format( + cloud_name), + "--set", "systemDefaultValues.clusterconnect-agent.enabled=true", + "--namespace", "{}".format("azure-arc-release"), + "--create-namespace", + "--output", "json"] + + if not no_wait: + # Change --timeout format for helm client to understand + onboarding_timeout = onboarding_timeout + "s" + cmd_helm_install.extend( + ["--wait", "--timeout", "{}".format(onboarding_timeout)]) + response_helm_install = Popen(cmd_helm_install, stdout=PIPE, stderr=PIPE) + _, error_helm_install = response_helm_install.communicate() + if response_helm_install.returncode != 0: + raise Exception("Unable to install helm release" + error_helm_install.decode("ascii")) + + +def install_agent(): + parser = argparse.ArgumentParser( + description='Install Connected Cluster Agent') + parser.add_argument('--subscriptionId', type=str, required=True) + parser.add_argument('--resourceGroupName', type=str, required=True) + parser.add_argument('--clusterName', type=str, required=True) + parser.add_argument('--location', type=str, required=True) + parser.add_argument('--tenantId', type=str, required=True) + parser.add_argument('--privatePem', type=str, required=True) + + try: + args = parser.parse_args() + except Exception as e: + raise Exception("Failed to parse arguments." + str(e)) + + try: + with open(args.privatePem, "r") as f: + privateKey = f.read() + except Exception as e: + raise Exception("Failed to get private key." + str(e)) + + # Install helm client + helm_client_location = install_helm_client() + + # Retrieving Helm chart OCI Artifact location + registry_path = get_helm_registry("https://westeurope.dp.kubernetesconfiguration.azure.com") + + # Get helm chart path + chart_path = get_chart_path( + registry_path, None, None, helm_client_location) + + helm_install_release(chart_path, + args.subscriptionId, + "generic", + "generic", + args.resourceGroupName, + args.clusterName, + args.location, + args.tenantId, + privateKey, + # private_key_pem2, + False, + "AZUREPUBLICCLOUD", + helm_client_location) + + +if __name__ == "__main__": + install_agent() diff --git a/internal/services/arckubernetes/testdata/install_agent.sh.tftpl b/internal/services/arckubernetes/testdata/install_agent.sh.tftpl new file mode 100644 index 000000000000..9bb2cbcbd0bf --- /dev/null +++ b/internal/services/arckubernetes/testdata/install_agent.sh.tftpl @@ -0,0 +1,38 @@ +#!/bin/bash + +# install docker +sudo apt-get update +sudo apt-get -y install ca-certificates curl gnupg lsb-release +sudo mkdir -m 0755 -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg +echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null +sudo chmod a+r /etc/apt/keyrings/docker.gpg +sudo apt-get update +sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +#Manage Docker as a non-root user +sudo groupadd docker || true +sudo usermod -aG docker $USER +newgrp docker << END + +#install golang and kind +sudo snap install go --classic +sudo go install sigs.k8s.io/kind@latest + +#create a new cluster +export PATH="$HOME/go/bin:$PATH" +export KUBECONFIG="${working_dir}/kind-config" +kind create cluster --name arc-kind --config kind.yaml --kubeconfig kind-config + +#install agent +python3 "${working_dir}/install_agent.py" \ +--subscriptionId "${subscription_id}" \ +--resourceGroupName "${resource_group_name}" \ +--clusterName "${cluster_name}" \ +--location "${location}" \ +--tenantId "${tenant_id}" \ +--privatePem "${working_dir}/private.pem" + +END \ No newline at end of file diff --git a/internal/services/arckubernetes/testdata/kind.yaml b/internal/services/arckubernetes/testdata/kind.yaml new file mode 100644 index 000000000000..fe336a44025d --- /dev/null +++ b/internal/services/arckubernetes/testdata/kind.yaml @@ -0,0 +1,20 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + # port forward 80 on the host to 80 on this node + extraPortMappings: + - containerPort: 81 + hostPort: 81 + listenAddress: "127.0.0.1" + protocol: TCP + - containerPort: 443 + hostPort: 443 + listenAddress: "127.0.0.1" + protocol: TCP diff --git a/internal/services/arckubernetes/testdata/private.pem b/internal/services/arckubernetes/testdata/private.pem new file mode 100644 index 000000000000..a0dfb3aedb3c --- /dev/null +++ b/internal/services/arckubernetes/testdata/private.pem @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKAIBAAKCAgEAxEJ9BOnVptQvDAuUZL5p1qhln7p9W/nSrnSDQPtiRfCcRcVb +GbjnU78T6HsLwT4Un37bhXqj2u+Pg6TTpnc9XKa7mGHT3mOGF4G4lIhxGaC9bgCW +as0d8bb97VKq/DkJqgSCqXVZ6hjOo5z4ESisYbkugtO9uENXVYNqkeRXAan7oWjK +JAFV8/pq6lctzNpiAoSti/INGUT2tfLjbsu2f+PrPIljFytXPNiUJClaChxZAwZ8 +pU2YJLUdFAtjOp/tlEnHt9UcdHp65DV6C00GNrORnR/hFrim9fqigMxGRtrJm96u +RGeApBLKto+OPodlSSpiuBztQlaNnX6Ryw5iKe2j241ehzA937shq14x3IuCBvkC +6OxL/KQP5Ry950d4nl4QtrFddWYa1Gjl+qkL6uqgfxV87JkieEfp1wdNzG+11bqt +38dm0SoWEB/4+PTRVKq2vwBIBGKv2lEEb3hFFUb7vAOU6RGwYDTUGQiHuL8ZtC8q +fHQe86J3CSFRS5ENBnCi9RMr6/blMlca5OmOa4/zWpCyZCIWvlK4Pb6/lOA15aMU +4+Z2SdUvBN8Zf1QAc+5nrWP/70gs2mut1SpaVl+gN0/0hhAw8HPvBXUc4WMZLLDf +P25knbOywJ9zJQH0sDxijCozdGpfxO904cTo278Fwx4tOWcZZ+55+2j0OBsCAwEA +AQKCAgBA6c7pC6Cfk+nVvZTA95wRJFSsjqW9ALX2/tGU8jCwemNtzleR++8Da51d +lSkvquVuVaqtDQHaPcdFnwRkOGdC2GEPBzhpA5kL+FuBQVnLRLezBR27SInBc6ms +T93/G6x/IAvJmed5/ueGBTqljkLp9bKVEgzbv+ZIgfWDOLewdLUmT38ghpKT5n1r +chdTfN3TAGhYc+ByPbWuO56O/HEp/sxFExoDxVGO7gGdrlG6K2MjlYcvs6kBZygt +g5C4CMKve/HDc4j8W7B+/9MUns7R0/XzNuKfvcZ3cIVEPYx3DhGF7RLNzEAnxJFo +7bV6KBVPrGXHiMXO3crsTztQorrDmB/KRrldserQd0UiYtydSHlRbQnDRbGKYnVf +Z3NGtjjqHb2mZv2YsKHKhtJcUbohSNYZLv4tJLy6SDfsgexIH1f4+knrUvgmlMvG +zWKsHm4d7/mLJAzpEFhs8C4AsMC4mdt60+R23uMJ6nZ/RUxz7NgtDRZLbX46XumW +I2e6+yXitKLxZ5SyO/dW/26YUBYZNJaw/7A5o7KveBtGpslSK75zaHyajfNsrZoj +eQDlpmCEViDRGhAKT+fSrGH9EO2wX8hzGo2ZD4lxYiRyzAogF/lCgOR+TxlKKd0l +Iz9fibVXloRerZbrQNNf2D2p3dDotNZC9hDKeWPW2NqpVw7EwQKCAQEA2bto0Jpr +zd4MNANQpaGp33dJaLOwK06Qd3U/9Gv8HId94iN1ocUMfU/BFItziLreIVd9dt47 +8XIqHPaMSZ+mJiWSZ0IMh/ZxVnoyeU9UTfNxnS6pUGMN+5JpZHUvgkipJZTnhPU+ +bG9unSRE37jLLss2yGNBiFww8BUgp5FtwFD/V5+yvlNxtt+IJQ1vMnoexa3LRLum +NyXNY8MOZckZ6/isVsJbYslzyAhxC0nhl77NKVGvqU8btc79PPzSleSWAqQxuSop +NKb1GXUEXtBWnFnSpclUTy1SYCJMPuXiKbXwtPpGQX8QgDUUGoTthurR5uJcO1W1 +DGVTqifUArzs2wKCAQEA5sD05sFBfGjPJrTM6YEGuFE5URaSPSssdYuwesB4aOVT +HiPlvoB3//b6NtLw8WnnbPe0tKu9D/8Q8Hh4j0sA/WTGUc9yg2HgfdWWDoa3CG00 +AOsv6oHGULSitsD4uceRfxh2Y1DCvV7uhBhTtcgtCH14qx/q2Hee8LddZpzl+LyS +nXvo6t3+uKGRw2W/qVbhpboQiolfCvXRFA5ZXGZc8atGE8sniqYyh4pG3Bppwxqz +D/ixkuChBoXGaQTtQ4jfyj86ZcPCc6Pn4jMJ3LJOuKFcRgqSkbyUPuAYcXs5TR5Y +BwzxoJLjGZIY6YQlHkFrl8wy9Z9rPnrMOTOg6/4lwQKCAQA+QZL3yp+2jp4opSYD +JhV/ewk3ceGWkHFIZvMxfUrqEWfSKFdzOPeYQRyxNiqD1wK6v9x1B5hWMlGOVITK +bGbCk42oDr+shK/ljS0veJpfa5N54SSygpA19ahC/CrocsRCpbAJWWJO+RHExuEW +oy0dpSd15sOPLOUlULU0lKWwDrjkIhqmxw9FveacyZmY8kgoN8heT9V4AUwYEWbl +fbn2ufT1Hb+poHaFpLxGAQsLK5hYDy5OF/uRYa0RKi1AhMrL2I0LJ93+WxrL+6ST +Q7jwHdLYape7x/a83DG27l5blNVNuh4qjh12uzaTWpzcLfp0rRa4NIp/D937UkYR +vllvAoIBAEQGbiv4nM2IOEk404+isdB0YWk+Ni5CJAEjBQuq4dRKho5EFt5qEPYs +YOb4mH8SsV62R1dbqYilsOCzIxdbDRemNbC4bxG8MOnnpSzzGdIqH0KGEsIXL9dq +6OznRmu+IW5OT9hHXqFk8vuOEF9ue5gdJQ2NgzX9TaW46JfvePwy2yYB+VAD0aus +NcRconvRWQP6LhYpGROqE9DNyhorMwsraqU7JpUBGbRLV0hboQIbRN5YekDKZ638 +kdkz0p4uI4sDyLtnUlO05g8Q7L9a8UoMh58+TqcX6LwAZDRQFzxczaaGclTb+Ib5 +Qs7UXfzlXEqLsBoovPzWRo42YiIv8gECggEBAIu3DDxlIc6Y6t7AuDzknCkqpLXC +VqREmfhYflirlMtXgRgh1+wnZ3S4Uid9eCPtHcFKHgQ5Y3f084r7E0OpNdo/UgER +nX86LNtpSdeQ3tTWt3vqgX8WPdOo9Fyll357/+LfRX5U1SeCbmmSI9PBTmx0qe4F +ZGhFfh6kgVcYBWtYoOaqrniBdWjotxoNeDoiG/PA2UNiD3CCEiS0NcG8HElXWGNG +wlj/1JfmzvNOqy3I7R+vjM5+KyBWnmq1neCGMLI6yFq9Rms7Twotoeil3477m2B5 +Fg0RRUb6dJHX25xTahwLu0/8weAFuj6xIBoz+oVAw3pCyAxTUNqui8f/0Ug= +-----END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/internal/services/arckubernetes/testdata/public.cer b/internal/services/arckubernetes/testdata/public.cer new file mode 100644 index 0000000000000000000000000000000000000000..18e27003a9ca978e33c73bbce1b5b5817129e472 GIT binary patch literal 526 zcmV+p0`dJYf&vNxf&u{m#6o=p>D8vxFANKmWWH(EsAZqJeOvj`u5^Py`(j1#oJGZ3 z8Mx0-OYRw(- zw*Bo=s{A<#ssw_mby?~d&ZC_85h$!-xh{g!y|_bHRfB4gZDOw5~Spx=qrA?S5wH*`-V>+Mh zlu5_8)f{wsdgL{F3rz+#vyq)2;TE{2_4=ZK%tl7q$(!D;L}!4c63VuZjy{KFNh)Hv z9PL6@jh%jx%MM~G?W5a`UWYI}-@75JUNPK@f(H2l=Y#rWeC(Mbct`2i2Tjaxwbi<<-^XUrDi#nQ`1thERI0YW07wL4ui8-r zZ+Jx&M*F-2l<5($U^LVj2#2`88MH4dd~_c3qIU@)QA?2x25_SF6D#ZX0+EZS?W)hb$6U!XTn z^o9^H@N@44bsXVi87#2hKW=25v$DXSb0q=vusmXnDl>FyU&QZp;l$|MzXih{Ejecy QXYP6XX!JN60s{d60gp)o4FCWD literal 0 HcmV?d00001 diff --git a/website/docs/r/arc_kubernetes_cluster.html.markdown b/website/docs/r/arc_kubernetes_cluster.html.markdown index 8ae3390abbfd..db28ab3a9d96 100644 --- a/website/docs/r/arc_kubernetes_cluster.html.markdown +++ b/website/docs/r/arc_kubernetes_cluster.html.markdown @@ -22,9 +22,7 @@ resource "azurerm_arc_kubernetes_cluster" "example" { name = "example-akcc" resource_group_name = azurerm_resource_group.example.name location = "West Europe" - distribution = "azure" - infrastructure = "azure" - agent_public_key_certificate = "xxxxxxxxxxxxxxxxxxx" + agent_public_key_certificate = filebase64("testdata/public.cer") identity { type = "SystemAssigned" @@ -50,10 +48,6 @@ The following arguments are supported: * `location` - (Required) Specifies the Azure Region where the Arc Kubernetes Cluster should exist. Changing this forces a new Arc Kubernetes Cluster to be created. -* `distribution` - (Optional) Specifies the distribution running on this Arc Kubernetes Cluster. Changing this forces a new Arc Kubernetes Cluster to be created. - -* `infrastructure` - (Optional) Specifies the infrastructure on which the Arc Kubernetes Cluster is running on. Changing this forces a new Arc Kubernetes Cluster to be created. - * `tags` - (Optional) A mapping of tags which should be assigned to the Arc Kubernetes Cluster. --- @@ -70,8 +64,12 @@ In addition to the Arguments listed above - the following Attributes are exporte * `agent_version` - Version of the agent running on the cluster resource. +* `distribution` - The distribution running on this Arc Kubernetes Cluster. + * `identity` - An `identity` block as defined below. +* `infrastructure` - The infrastructure on which the Arc Kubernetes Cluster is running on. + * `kubernetes_version` - The Kubernetes version of the cluster resource. * `offering` - The cluster offering. From 83b69b123024a332cf5159b595eafa54ac3e0793 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Thu, 23 Mar 2023 15:31:50 +0800 Subject: [PATCH 07/11] add code --- .../arc_kubernetes_cluster_resource.go | 2 +- .../sdk/2021-10-01/hybridkubernetes/client.go | 15 - .../2021-10-01/hybridkubernetes/constants.go | 176 ----------- .../hybridkubernetes/id_connectedcluster.go | 124 -------- .../id_connectedcluster_test.go | 279 ------------------ .../method_connectedclustercreate_autorest.go | 75 ----- .../method_connectedclusterdelete_autorest.go | 74 ----- .../method_connectedclusterget_autorest.go | 64 ---- ...ctedclusterlistbyresourcegroup_autorest.go | 184 ------------ ...ectedclusterlistbysubscription_autorest.go | 184 ------------ ...usterlistclusterusercredential_autorest.go | 66 ----- .../method_connectedclusterupdate_autorest.go | 65 ---- .../model_connectedcluster.go | 16 - .../model_connectedclusterpatch.go | 6 - .../model_connectedclusterproperties.go | 46 --- .../model_credentialresult.go | 6 - .../model_credentialresults.go | 6 - .../model_hybridconnectionconfig.go | 8 - ...del_listclusterusercredentialproperties.go | 6 - .../hybridkubernetes/model_systemdata.go | 40 --- .../2021-10-01/hybridkubernetes/predicates.go | 29 -- .../2021-10-01/hybridkubernetes/version.go | 9 - 22 files changed, 1 insertion(+), 1479 deletions(-) delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/client.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/constants.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go delete mode 100644 internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/version.go diff --git a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go index 139afcb3e747..c140642d725f 100644 --- a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go @@ -10,10 +10,10 @@ import ( "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" "github.com/hashicorp/go-azure-helpers/resourcemanager/location" tagsHelper "github.com/hashicorp/go-azure-helpers/resourcemanager/tags" + arckubernetes "github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters" "github.com/hashicorp/terraform-provider-azurerm/helpers/tf" azValidate "github.com/hashicorp/terraform-provider-azurerm/helpers/validate" "github.com/hashicorp/terraform-provider-azurerm/internal/clients" - arckubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" "github.com/hashicorp/terraform-provider-azurerm/internal/tags" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk" "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation" diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/client.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/client.go deleted file mode 100644 index 9e5b81d83456..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/client.go +++ /dev/null @@ -1,15 +0,0 @@ -package hybridkubernetes - -import "github.com/Azure/go-autorest/autorest" - -type HybridKubernetesClient struct { - Client autorest.Client - baseUri string -} - -func NewHybridKubernetesClientWithBaseURI(endpoint string) HybridKubernetesClient { - return HybridKubernetesClient{ - Client: autorest.NewClientWithUserAgent(userAgent()), - baseUri: endpoint, - } -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/constants.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/constants.go deleted file mode 100644 index 1a58aeccfe9f..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/constants.go +++ /dev/null @@ -1,176 +0,0 @@ -package hybridkubernetes - -import "strings" - -type AuthenticationMethod string - -const ( - AuthenticationMethodAAD AuthenticationMethod = "AAD" - AuthenticationMethodToken AuthenticationMethod = "Token" -) - -func PossibleValuesForAuthenticationMethod() []string { - return []string{ - string(AuthenticationMethodAAD), - string(AuthenticationMethodToken), - } -} - -func parseAuthenticationMethod(input string) (*AuthenticationMethod, error) { - vals := map[string]AuthenticationMethod{ - "aad": AuthenticationMethodAAD, - "token": AuthenticationMethodToken, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := AuthenticationMethod(input) - return &out, nil -} - -type ConnectivityStatus string - -const ( - ConnectivityStatusConnected ConnectivityStatus = "Connected" - ConnectivityStatusConnecting ConnectivityStatus = "Connecting" - ConnectivityStatusExpired ConnectivityStatus = "Expired" - ConnectivityStatusOffline ConnectivityStatus = "Offline" -) - -func PossibleValuesForConnectivityStatus() []string { - return []string{ - string(ConnectivityStatusConnected), - string(ConnectivityStatusConnecting), - string(ConnectivityStatusExpired), - string(ConnectivityStatusOffline), - } -} - -func parseConnectivityStatus(input string) (*ConnectivityStatus, error) { - vals := map[string]ConnectivityStatus{ - "connected": ConnectivityStatusConnected, - "connecting": ConnectivityStatusConnecting, - "expired": ConnectivityStatusExpired, - "offline": ConnectivityStatusOffline, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := ConnectivityStatus(input) - return &out, nil -} - -type CreatedByType string - -const ( - CreatedByTypeApplication CreatedByType = "Application" - CreatedByTypeKey CreatedByType = "Key" - CreatedByTypeManagedIdentity CreatedByType = "ManagedIdentity" - CreatedByTypeUser CreatedByType = "User" -) - -func PossibleValuesForCreatedByType() []string { - return []string{ - string(CreatedByTypeApplication), - string(CreatedByTypeKey), - string(CreatedByTypeManagedIdentity), - string(CreatedByTypeUser), - } -} - -func parseCreatedByType(input string) (*CreatedByType, error) { - vals := map[string]CreatedByType{ - "application": CreatedByTypeApplication, - "key": CreatedByTypeKey, - "managedidentity": CreatedByTypeManagedIdentity, - "user": CreatedByTypeUser, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := CreatedByType(input) - return &out, nil -} - -type LastModifiedByType string - -const ( - LastModifiedByTypeApplication LastModifiedByType = "Application" - LastModifiedByTypeKey LastModifiedByType = "Key" - LastModifiedByTypeManagedIdentity LastModifiedByType = "ManagedIdentity" - LastModifiedByTypeUser LastModifiedByType = "User" -) - -func PossibleValuesForLastModifiedByType() []string { - return []string{ - string(LastModifiedByTypeApplication), - string(LastModifiedByTypeKey), - string(LastModifiedByTypeManagedIdentity), - string(LastModifiedByTypeUser), - } -} - -func parseLastModifiedByType(input string) (*LastModifiedByType, error) { - vals := map[string]LastModifiedByType{ - "application": LastModifiedByTypeApplication, - "key": LastModifiedByTypeKey, - "managedidentity": LastModifiedByTypeManagedIdentity, - "user": LastModifiedByTypeUser, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := LastModifiedByType(input) - return &out, nil -} - -type ProvisioningState string - -const ( - ProvisioningStateAccepted ProvisioningState = "Accepted" - ProvisioningStateCanceled ProvisioningState = "Canceled" - ProvisioningStateDeleting ProvisioningState = "Deleting" - ProvisioningStateFailed ProvisioningState = "Failed" - ProvisioningStateProvisioning ProvisioningState = "Provisioning" - ProvisioningStateSucceeded ProvisioningState = "Succeeded" - ProvisioningStateUpdating ProvisioningState = "Updating" -) - -func PossibleValuesForProvisioningState() []string { - return []string{ - string(ProvisioningStateAccepted), - string(ProvisioningStateCanceled), - string(ProvisioningStateDeleting), - string(ProvisioningStateFailed), - string(ProvisioningStateProvisioning), - string(ProvisioningStateSucceeded), - string(ProvisioningStateUpdating), - } -} - -func parseProvisioningState(input string) (*ProvisioningState, error) { - vals := map[string]ProvisioningState{ - "accepted": ProvisioningStateAccepted, - "canceled": ProvisioningStateCanceled, - "deleting": ProvisioningStateDeleting, - "failed": ProvisioningStateFailed, - "provisioning": ProvisioningStateProvisioning, - "succeeded": ProvisioningStateSucceeded, - "updating": ProvisioningStateUpdating, - } - if v, ok := vals[strings.ToLower(input)]; ok { - return &v, nil - } - - // otherwise presume it's an undefined value and best-effort it - out := ProvisioningState(input) - return &out, nil -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go deleted file mode 100644 index 65875bac58c9..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster.go +++ /dev/null @@ -1,124 +0,0 @@ -package hybridkubernetes - -import ( - "fmt" - "strings" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -var _ resourceids.ResourceId = ConnectedClusterId{} - -// ConnectedClusterId is a struct representing the Resource ID for a Connected Cluster -type ConnectedClusterId struct { - SubscriptionId string - ResourceGroupName string - ClusterName string -} - -// NewConnectedClusterID returns a new ConnectedClusterId struct -func NewConnectedClusterID(subscriptionId string, resourceGroupName string, clusterName string) ConnectedClusterId { - return ConnectedClusterId{ - SubscriptionId: subscriptionId, - ResourceGroupName: resourceGroupName, - ClusterName: clusterName, - } -} - -// ParseConnectedClusterID parses 'input' into a ConnectedClusterId -func ParseConnectedClusterID(input string) (*ConnectedClusterId, error) { - parser := resourceids.NewParserFromResourceIdType(ConnectedClusterId{}) - parsed, err := parser.Parse(input, false) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := ConnectedClusterId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.ClusterName, ok = parsed.Parsed["clusterName"]; !ok { - return nil, fmt.Errorf("the segment 'clusterName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ParseConnectedClusterIDInsensitively parses 'input' case-insensitively into a ConnectedClusterId -// note: this method should only be used for API response data and not user input -func ParseConnectedClusterIDInsensitively(input string) (*ConnectedClusterId, error) { - parser := resourceids.NewParserFromResourceIdType(ConnectedClusterId{}) - parsed, err := parser.Parse(input, true) - if err != nil { - return nil, fmt.Errorf("parsing %q: %+v", input, err) - } - - var ok bool - id := ConnectedClusterId{} - - if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { - return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) - } - - if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { - return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) - } - - if id.ClusterName, ok = parsed.Parsed["clusterName"]; !ok { - return nil, fmt.Errorf("the segment 'clusterName' was not found in the resource id %q", input) - } - - return &id, nil -} - -// ValidateConnectedClusterID checks that 'input' can be parsed as a Connected Cluster ID -func ValidateConnectedClusterID(input interface{}, key string) (warnings []string, errors []error) { - v, ok := input.(string) - if !ok { - errors = append(errors, fmt.Errorf("expected %q to be a string", key)) - return - } - - if _, err := ParseConnectedClusterID(v); err != nil { - errors = append(errors, err) - } - - return -} - -// ID returns the formatted Connected Cluster ID -func (id ConnectedClusterId) ID() string { - fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Kubernetes/connectedClusters/%s" - return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ClusterName) -} - -// Segments returns a slice of Resource ID Segments which comprise this Connected Cluster ID -func (id ConnectedClusterId) Segments() []resourceids.Segment { - return []resourceids.Segment{ - resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), - resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), - resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), - resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), - resourceids.StaticSegment("staticProviders", "providers", "providers"), - resourceids.ResourceProviderSegment("staticMicrosoftKubernetes", "Microsoft.Kubernetes", "Microsoft.Kubernetes"), - resourceids.StaticSegment("staticConnectedClusters", "connectedClusters", "connectedClusters"), - resourceids.UserSpecifiedSegment("clusterName", "clusterValue"), - } -} - -// String returns a human-readable description of this Connected Cluster ID -func (id ConnectedClusterId) String() string { - components := []string{ - fmt.Sprintf("Subscription: %q", id.SubscriptionId), - fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), - fmt.Sprintf("Cluster Name: %q", id.ClusterName), - } - return fmt.Sprintf("Connected Cluster (%s)", strings.Join(components, "\n")) -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go deleted file mode 100644 index 47a00932edd9..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/id_connectedcluster_test.go +++ /dev/null @@ -1,279 +0,0 @@ -package hybridkubernetes - -import ( - "testing" - - "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" -) - -var _ resourceids.ResourceId = ConnectedClusterId{} - -func TestNewConnectedClusterID(t *testing.T) { - id := NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue") - - if id.SubscriptionId != "12345678-1234-9876-4563-123456789012" { - t.Fatalf("Expected %q but got %q for Segment 'SubscriptionId'", id.SubscriptionId, "12345678-1234-9876-4563-123456789012") - } - - if id.ResourceGroupName != "example-resource-group" { - t.Fatalf("Expected %q but got %q for Segment 'ResourceGroupName'", id.ResourceGroupName, "example-resource-group") - } - - if id.ClusterName != "clusterValue" { - t.Fatalf("Expected %q but got %q for Segment 'ClusterName'", id.ClusterName, "clusterValue") - } -} - -func TestFormatConnectedClusterID(t *testing.T) { - actual := NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "clusterValue").ID() - expected := "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue" - if actual != expected { - t.Fatalf("Expected the Formatted ID to be %q but got %q", expected, actual) - } -} - -func TestParseConnectedClusterID(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ConnectedClusterId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue", - Expected: &ConnectedClusterId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - ClusterName: "clusterValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseConnectedClusterID(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.SubscriptionId != v.Expected.SubscriptionId { - t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) - } - - if actual.ResourceGroupName != v.Expected.ResourceGroupName { - t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) - } - - if actual.ClusterName != v.Expected.ClusterName { - t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) - } - - } -} - -func TestParseConnectedClusterIDInsensitively(t *testing.T) { - testData := []struct { - Input string - Error bool - Expected *ConnectedClusterId - }{ - { - // Incomplete URI - Input: "", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS", - Error: true, - }, - { - // Incomplete URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters", - Error: true, - }, - { - // Incomplete URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS/cOnNeCtEdClUsTeRs", - Error: true, - }, - { - // Valid URI - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue", - Expected: &ConnectedClusterId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "example-resource-group", - ClusterName: "clusterValue", - }, - }, - { - // Invalid (Valid Uri with Extra segment) - Input: "/subscriptions/12345678-1234-9876-4563-123456789012/resourceGroups/example-resource-group/providers/Microsoft.Kubernetes/connectedClusters/clusterValue/extra", - Error: true, - }, - { - // Valid URI (mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS/cOnNeCtEdClUsTeRs/cLuStErVaLuE", - Expected: &ConnectedClusterId{ - SubscriptionId: "12345678-1234-9876-4563-123456789012", - ResourceGroupName: "eXaMpLe-rEsOuRcE-GrOuP", - ClusterName: "cLuStErVaLuE", - }, - }, - { - // Invalid (Valid Uri with Extra segment - mIxEd CaSe since this is insensitive) - Input: "/sUbScRiPtIoNs/12345678-1234-9876-4563-123456789012/rEsOuRcEgRoUpS/eXaMpLe-rEsOuRcE-GrOuP/pRoViDeRs/mIcRoSoFt.kUbErNeTeS/cOnNeCtEdClUsTeRs/cLuStErVaLuE/extra", - Error: true, - }, - } - for _, v := range testData { - t.Logf("[DEBUG] Testing %q", v.Input) - - actual, err := ParseConnectedClusterIDInsensitively(v.Input) - if err != nil { - if v.Error { - continue - } - - t.Fatalf("Expect a value but got an error: %+v", err) - } - if v.Error { - t.Fatal("Expect an error but didn't get one") - } - - if actual.SubscriptionId != v.Expected.SubscriptionId { - t.Fatalf("Expected %q but got %q for SubscriptionId", v.Expected.SubscriptionId, actual.SubscriptionId) - } - - if actual.ResourceGroupName != v.Expected.ResourceGroupName { - t.Fatalf("Expected %q but got %q for ResourceGroupName", v.Expected.ResourceGroupName, actual.ResourceGroupName) - } - - if actual.ClusterName != v.Expected.ClusterName { - t.Fatalf("Expected %q but got %q for ClusterName", v.Expected.ClusterName, actual.ClusterName) - } - - } -} - -func TestSegmentsForConnectedClusterId(t *testing.T) { - segments := ConnectedClusterId{}.Segments() - if len(segments) == 0 { - t.Fatalf("ConnectedClusterId has no segments") - } - - uniqueNames := make(map[string]struct{}, 0) - for _, segment := range segments { - uniqueNames[segment.Name] = struct{}{} - } - if len(uniqueNames) != len(segments) { - t.Fatalf("Expected the Segments to be unique but got %q unique segments and %d total segments", len(uniqueNames), len(segments)) - } -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go deleted file mode 100644 index 533fb244fd87..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclustercreate_autorest.go +++ /dev/null @@ -1,75 +0,0 @@ -package hybridkubernetes - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -type ConnectedClusterCreateResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// ConnectedClusterCreate ... -func (c HybridKubernetesClient) ConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (result ConnectedClusterCreateResponse, err error) { - req, err := c.preparerForConnectedClusterCreate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterCreate", nil, "Failure preparing request") - return - } - - result, err = c.senderForConnectedClusterCreate(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterCreate", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// ConnectedClusterCreateThenPoll performs ConnectedClusterCreate then polls until it's completed -func (c HybridKubernetesClient) ConnectedClusterCreateThenPoll(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) error { - result, err := c.ConnectedClusterCreate(ctx, id, input) - if err != nil { - return fmt.Errorf("performing ConnectedClusterCreate: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after ConnectedClusterCreate: %+v", err) - } - - return nil -} - -// preparerForConnectedClusterCreate prepares the ConnectedClusterCreate request. -func (c HybridKubernetesClient) preparerForConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPut(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForConnectedClusterCreate sends the ConnectedClusterCreate request. The method will close the -// http.Response Body if it receives an error. -func (c HybridKubernetesClient) senderForConnectedClusterCreate(ctx context.Context, req *http.Request) (future ConnectedClusterCreateResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - future.Poller, err = polling.NewLongRunningPollerFromResponse(ctx, resp, c.Client) - return -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go deleted file mode 100644 index e158d30cfef5..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterdelete_autorest.go +++ /dev/null @@ -1,74 +0,0 @@ -package hybridkubernetes - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/polling" -) - -type ConnectedClusterDeleteResponse struct { - Poller polling.LongRunningPoller - HttpResponse *http.Response -} - -// ConnectedClusterDelete ... -func (c HybridKubernetesClient) ConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterDeleteResponse, err error) { - req, err := c.preparerForConnectedClusterDelete(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterDelete", nil, "Failure preparing request") - return - } - - result, err = c.senderForConnectedClusterDelete(ctx, req) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterDelete", result.HttpResponse, "Failure sending request") - return - } - - return -} - -// ConnectedClusterDeleteThenPoll performs ConnectedClusterDelete then polls until it's completed -func (c HybridKubernetesClient) ConnectedClusterDeleteThenPoll(ctx context.Context, id ConnectedClusterId) error { - result, err := c.ConnectedClusterDelete(ctx, id) - if err != nil { - return fmt.Errorf("performing ConnectedClusterDelete: %+v", err) - } - - if err := result.Poller.PollUntilDone(); err != nil { - return fmt.Errorf("polling after ConnectedClusterDelete: %+v", err) - } - - return nil -} - -// preparerForConnectedClusterDelete prepares the ConnectedClusterDelete request. -func (c HybridKubernetesClient) preparerForConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsDelete(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// senderForConnectedClusterDelete sends the ConnectedClusterDelete request. The method will close the -// http.Response Body if it receives an error. -func (c HybridKubernetesClient) senderForConnectedClusterDelete(ctx context.Context, req *http.Request) (future ConnectedClusterDeleteResponse, err error) { - var resp *http.Response - resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - return - } - future.Poller, err = polling.NewLongRunningPollerFromResponse(ctx, resp, c.Client) - return -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go deleted file mode 100644 index d33e1a968881..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterget_autorest.go +++ /dev/null @@ -1,64 +0,0 @@ -package hybridkubernetes - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -type ConnectedClusterGetResponse struct { - HttpResponse *http.Response - Model *ConnectedCluster -} - -// ConnectedClusterGet ... -func (c HybridKubernetesClient) ConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterGetResponse, err error) { - req, err := c.preparerForConnectedClusterGet(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterGet", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForConnectedClusterGet(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterGet", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForConnectedClusterGet prepares the ConnectedClusterGet request. -func (c HybridKubernetesClient) preparerForConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForConnectedClusterGet handles the response to the ConnectedClusterGet request. The method always -// closes the http.Response Body. -func (c HybridKubernetesClient) responderForConnectedClusterGet(resp *http.Response) (result ConnectedClusterGetResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - return -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go deleted file mode 100644 index 9f9cd8039b0c..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbyresourcegroup_autorest.go +++ /dev/null @@ -1,184 +0,0 @@ -package hybridkubernetes - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -type ConnectedClusterListByResourceGroupResponse struct { - HttpResponse *http.Response - Model *[]ConnectedCluster - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ConnectedClusterListByResourceGroupResponse, error) -} - -type ConnectedClusterListByResourceGroupCompleteResult struct { - Items []ConnectedCluster -} - -func (r ConnectedClusterListByResourceGroupResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ConnectedClusterListByResourceGroupResponse) LoadMore(ctx context.Context) (resp ConnectedClusterListByResourceGroupResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ConnectedClusterListByResourceGroup ... -func (c HybridKubernetesClient) ConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ConnectedClusterListByResourceGroupResponse, err error) { - req, err := c.preparerForConnectedClusterListByResourceGroup(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForConnectedClusterListByResourceGroup(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// ConnectedClusterListByResourceGroupComplete retrieves all of the results into a single object -func (c HybridKubernetesClient) ConnectedClusterListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ConnectedClusterListByResourceGroupCompleteResult, error) { - return c.ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx, id, ConnectedClusterPredicate{}) -} - -// ConnectedClusterListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c HybridKubernetesClient) ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListByResourceGroupCompleteResult, err error) { - items := make([]ConnectedCluster, 0) - - page, err := c.ConnectedClusterListByResourceGroup(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ConnectedClusterListByResourceGroupCompleteResult{ - Items: items, - } - return out, nil -} - -// preparerForConnectedClusterListByResourceGroup prepares the ConnectedClusterListByResourceGroup request. -func (c HybridKubernetesClient) preparerForConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Kubernetes/connectedClusters", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForConnectedClusterListByResourceGroupWithNextLink prepares the ConnectedClusterListByResourceGroup request with the given nextLink token. -func (c HybridKubernetesClient) preparerForConnectedClusterListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForConnectedClusterListByResourceGroup handles the response to the ConnectedClusterListByResourceGroup request. The method always -// closes the http.Response Body. -func (c HybridKubernetesClient) responderForConnectedClusterListByResourceGroup(resp *http.Response) (result ConnectedClusterListByResourceGroupResponse, err error) { - type page struct { - Values []ConnectedCluster `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListByResourceGroupResponse, err error) { - req, err := c.preparerForConnectedClusterListByResourceGroupWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForConnectedClusterListByResourceGroup(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go deleted file mode 100644 index a55e2e72146c..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistbysubscription_autorest.go +++ /dev/null @@ -1,184 +0,0 @@ -package hybridkubernetes - -import ( - "context" - "fmt" - "net/http" - "net/url" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" - "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" -) - -type ConnectedClusterListBySubscriptionResponse struct { - HttpResponse *http.Response - Model *[]ConnectedCluster - - nextLink *string - nextPageFunc func(ctx context.Context, nextLink string) (ConnectedClusterListBySubscriptionResponse, error) -} - -type ConnectedClusterListBySubscriptionCompleteResult struct { - Items []ConnectedCluster -} - -func (r ConnectedClusterListBySubscriptionResponse) HasMore() bool { - return r.nextLink != nil -} - -func (r ConnectedClusterListBySubscriptionResponse) LoadMore(ctx context.Context) (resp ConnectedClusterListBySubscriptionResponse, err error) { - if !r.HasMore() { - err = fmt.Errorf("no more pages returned") - return - } - return r.nextPageFunc(ctx, *r.nextLink) -} - -// ConnectedClusterListBySubscription ... -func (c HybridKubernetesClient) ConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ConnectedClusterListBySubscriptionResponse, err error) { - req, err := c.preparerForConnectedClusterListBySubscription(ctx, id) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") - return - } - - resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure sending request") - return - } - - resp, err = c.responderForConnectedClusterListBySubscription(resp.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure responding to request") - return - } - return -} - -// ConnectedClusterListBySubscriptionComplete retrieves all of the results into a single object -func (c HybridKubernetesClient) ConnectedClusterListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ConnectedClusterListBySubscriptionCompleteResult, error) { - return c.ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx, id, ConnectedClusterPredicate{}) -} - -// ConnectedClusterListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate -func (c HybridKubernetesClient) ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ConnectedClusterPredicate) (resp ConnectedClusterListBySubscriptionCompleteResult, err error) { - items := make([]ConnectedCluster, 0) - - page, err := c.ConnectedClusterListBySubscription(ctx, id) - if err != nil { - err = fmt.Errorf("loading the initial page: %+v", err) - return - } - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - - for page.HasMore() { - page, err = page.LoadMore(ctx) - if err != nil { - err = fmt.Errorf("loading the next page: %+v", err) - return - } - - if page.Model != nil { - for _, v := range *page.Model { - if predicate.Matches(v) { - items = append(items, v) - } - } - } - } - - out := ConnectedClusterListBySubscriptionCompleteResult{ - Items: items, - } - return out, nil -} - -// preparerForConnectedClusterListBySubscription prepares the ConnectedClusterListBySubscription request. -func (c HybridKubernetesClient) preparerForConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Kubernetes/connectedClusters", id.ID())), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// preparerForConnectedClusterListBySubscriptionWithNextLink prepares the ConnectedClusterListBySubscription request with the given nextLink token. -func (c HybridKubernetesClient) preparerForConnectedClusterListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { - uri, err := url.Parse(nextLink) - if err != nil { - return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) - } - queryParameters := map[string]interface{}{} - for k, v := range uri.Query() { - if len(v) == 0 { - continue - } - val := v[0] - val = autorest.Encode("query", val) - queryParameters[k] = val - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsGet(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(uri.Path), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForConnectedClusterListBySubscription handles the response to the ConnectedClusterListBySubscription request. The method always -// closes the http.Response Body. -func (c HybridKubernetesClient) responderForConnectedClusterListBySubscription(resp *http.Response) (result ConnectedClusterListBySubscriptionResponse, err error) { - type page struct { - Values []ConnectedCluster `json:"value"` - NextLink *string `json:"nextLink"` - } - var respObj page - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&respObj), - autorest.ByClosing()) - result.HttpResponse = resp - result.Model = &respObj.Values - result.nextLink = respObj.NextLink - if respObj.NextLink != nil { - result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListBySubscriptionResponse, err error) { - req, err := c.preparerForConnectedClusterListBySubscriptionWithNextLink(ctx, nextLink) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForConnectedClusterListBySubscription(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure responding to request") - return - } - - return - } - } - return -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go deleted file mode 100644 index 8906ae14a6ea..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterlistclusterusercredential_autorest.go +++ /dev/null @@ -1,66 +0,0 @@ -package hybridkubernetes - -import ( - "context" - "fmt" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -type ConnectedClusterListClusterUserCredentialResponse struct { - HttpResponse *http.Response - Model *CredentialResults -} - -// ConnectedClusterListClusterUserCredential ... -func (c HybridKubernetesClient) ConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (result ConnectedClusterListClusterUserCredentialResponse, err error) { - req, err := c.preparerForConnectedClusterListClusterUserCredential(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListClusterUserCredential", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForConnectedClusterListClusterUserCredential(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForConnectedClusterListClusterUserCredential prepares the ConnectedClusterListClusterUserCredential request. -func (c HybridKubernetesClient) preparerForConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPost(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(fmt.Sprintf("%s/listClusterUserCredential", id.ID())), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForConnectedClusterListClusterUserCredential handles the response to the ConnectedClusterListClusterUserCredential request. The method always -// closes the http.Response Body. -func (c HybridKubernetesClient) responderForConnectedClusterListClusterUserCredential(resp *http.Response) (result ConnectedClusterListClusterUserCredentialResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - return -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go deleted file mode 100644 index 26f34b9d7c28..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/method_connectedclusterupdate_autorest.go +++ /dev/null @@ -1,65 +0,0 @@ -package hybridkubernetes - -import ( - "context" - "net/http" - - "github.com/Azure/go-autorest/autorest" - "github.com/Azure/go-autorest/autorest/azure" -) - -type ConnectedClusterUpdateResponse struct { - HttpResponse *http.Response - Model *ConnectedCluster -} - -// ConnectedClusterUpdate ... -func (c HybridKubernetesClient) ConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (result ConnectedClusterUpdateResponse, err error) { - req, err := c.preparerForConnectedClusterUpdate(ctx, id, input) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterUpdate", nil, "Failure preparing request") - return - } - - result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure sending request") - return - } - - result, err = c.responderForConnectedClusterUpdate(result.HttpResponse) - if err != nil { - err = autorest.NewErrorWithError(err, "hybridkubernetes.HybridKubernetesClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure responding to request") - return - } - - return -} - -// preparerForConnectedClusterUpdate prepares the ConnectedClusterUpdate request. -func (c HybridKubernetesClient) preparerForConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (*http.Request, error) { - queryParameters := map[string]interface{}{ - "api-version": defaultApiVersion, - } - - preparer := autorest.CreatePreparer( - autorest.AsContentType("application/json; charset=utf-8"), - autorest.AsPatch(), - autorest.WithBaseURL(c.baseUri), - autorest.WithPath(id.ID()), - autorest.WithJSON(input), - autorest.WithQueryParameters(queryParameters)) - return preparer.Prepare((&http.Request{}).WithContext(ctx)) -} - -// responderForConnectedClusterUpdate handles the response to the ConnectedClusterUpdate request. The method always -// closes the http.Response Body. -func (c HybridKubernetesClient) responderForConnectedClusterUpdate(resp *http.Response) (result ConnectedClusterUpdateResponse, err error) { - err = autorest.Respond( - resp, - azure.WithErrorUnlessStatusCode(http.StatusOK), - autorest.ByUnmarshallingJSON(&result.Model), - autorest.ByClosing()) - result.HttpResponse = resp - return -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go deleted file mode 100644 index 2519906904da..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedcluster.go +++ /dev/null @@ -1,16 +0,0 @@ -package hybridkubernetes - -import ( - "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" -) - -type ConnectedCluster struct { - Id *string `json:"id,omitempty"` - Identity identity.SystemAssigned `json:"identity"` - Location string `json:"location"` - Name *string `json:"name,omitempty"` - Properties ConnectedClusterProperties `json:"properties"` - SystemData *SystemData `json:"systemData,omitempty"` - Tags *map[string]string `json:"tags,omitempty"` - Type *string `json:"type,omitempty"` -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go deleted file mode 100644 index e1e231970ec1..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterpatch.go +++ /dev/null @@ -1,6 +0,0 @@ -package hybridkubernetes - -type ConnectedClusterPatch struct { - Properties *interface{} `json:"properties,omitempty"` - Tags *map[string]string `json:"tags,omitempty"` -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go deleted file mode 100644 index eff635aa575e..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_connectedclusterproperties.go +++ /dev/null @@ -1,46 +0,0 @@ -package hybridkubernetes - -import ( - "time" - - "github.com/hashicorp/go-azure-helpers/lang/dates" -) - -type ConnectedClusterProperties struct { - AgentPublicKeyCertificate string `json:"agentPublicKeyCertificate"` - AgentVersion *string `json:"agentVersion,omitempty"` - ConnectivityStatus *ConnectivityStatus `json:"connectivityStatus,omitempty"` - Distribution *string `json:"distribution,omitempty"` - Infrastructure *string `json:"infrastructure,omitempty"` - KubernetesVersion *string `json:"kubernetesVersion,omitempty"` - LastConnectivityTime *string `json:"lastConnectivityTime,omitempty"` - ManagedIdentityCertificateExpirationTime *string `json:"managedIdentityCertificateExpirationTime,omitempty"` - Offering *string `json:"offering,omitempty"` - ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` - TotalCoreCount *int64 `json:"totalCoreCount,omitempty"` - TotalNodeCount *int64 `json:"totalNodeCount,omitempty"` -} - -func (o ConnectedClusterProperties) GetLastConnectivityTimeAsTime() (*time.Time, error) { - if o.LastConnectivityTime == nil { - return nil, nil - } - return dates.ParseAsFormat(o.LastConnectivityTime, "2006-01-02T15:04:05Z07:00") -} - -func (o ConnectedClusterProperties) SetLastConnectivityTimeAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.LastConnectivityTime = &formatted -} - -func (o ConnectedClusterProperties) GetManagedIdentityCertificateExpirationTimeAsTime() (*time.Time, error) { - if o.ManagedIdentityCertificateExpirationTime == nil { - return nil, nil - } - return dates.ParseAsFormat(o.ManagedIdentityCertificateExpirationTime, "2006-01-02T15:04:05Z07:00") -} - -func (o ConnectedClusterProperties) SetManagedIdentityCertificateExpirationTimeAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.ManagedIdentityCertificateExpirationTime = &formatted -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go deleted file mode 100644 index a8aac6a20c54..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresult.go +++ /dev/null @@ -1,6 +0,0 @@ -package hybridkubernetes - -type CredentialResult struct { - Name *string `json:"name,omitempty"` - Value *string `json:"value,omitempty"` -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go deleted file mode 100644 index fbe3011fb3fc..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_credentialresults.go +++ /dev/null @@ -1,6 +0,0 @@ -package hybridkubernetes - -type CredentialResults struct { - HybridConnectionConfig *HybridConnectionConfig `json:"hybridConnectionConfig,omitempty"` - Kubeconfigs *[]CredentialResult `json:"kubeconfigs,omitempty"` -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go deleted file mode 100644 index 9f0faf9497d5..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_hybridconnectionconfig.go +++ /dev/null @@ -1,8 +0,0 @@ -package hybridkubernetes - -type HybridConnectionConfig struct { - ExpirationTime *int64 `json:"expirationTime,omitempty"` - HybridConnectionName *string `json:"hybridConnectionName,omitempty"` - Relay *string `json:"relay,omitempty"` - Token *string `json:"token,omitempty"` -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go deleted file mode 100644 index 912651a569ac..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_listclusterusercredentialproperties.go +++ /dev/null @@ -1,6 +0,0 @@ -package hybridkubernetes - -type ListClusterUserCredentialProperties struct { - AuthenticationMethod AuthenticationMethod `json:"authenticationMethod"` - ClientProxy bool `json:"clientProxy"` -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go deleted file mode 100644 index 7391d86775ed..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/model_systemdata.go +++ /dev/null @@ -1,40 +0,0 @@ -package hybridkubernetes - -import ( - "time" - - "github.com/hashicorp/go-azure-helpers/lang/dates" -) - -type SystemData struct { - CreatedAt *string `json:"createdAt,omitempty"` - CreatedBy *string `json:"createdBy,omitempty"` - CreatedByType *CreatedByType `json:"createdByType,omitempty"` - LastModifiedAt *string `json:"lastModifiedAt,omitempty"` - LastModifiedBy *string `json:"lastModifiedBy,omitempty"` - LastModifiedByType *LastModifiedByType `json:"lastModifiedByType,omitempty"` -} - -func (o SystemData) GetCreatedAtAsTime() (*time.Time, error) { - if o.CreatedAt == nil { - return nil, nil - } - return dates.ParseAsFormat(o.CreatedAt, "2006-01-02T15:04:05Z07:00") -} - -func (o SystemData) SetCreatedAtAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.CreatedAt = &formatted -} - -func (o SystemData) GetLastModifiedAtAsTime() (*time.Time, error) { - if o.LastModifiedAt == nil { - return nil, nil - } - return dates.ParseAsFormat(o.LastModifiedAt, "2006-01-02T15:04:05Z07:00") -} - -func (o SystemData) SetLastModifiedAtAsTime(input time.Time) { - formatted := input.Format("2006-01-02T15:04:05Z07:00") - o.LastModifiedAt = &formatted -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go deleted file mode 100644 index 0c67034cdd5c..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/predicates.go +++ /dev/null @@ -1,29 +0,0 @@ -package hybridkubernetes - -type ConnectedClusterPredicate struct { - Id *string - Location *string - Name *string - Type *string -} - -func (p ConnectedClusterPredicate) Matches(input ConnectedCluster) bool { - - if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { - return false - } - - if p.Location != nil && *p.Location != input.Location { - return false - } - - if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { - return false - } - - if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { - return false - } - - return true -} diff --git a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/version.go b/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/version.go deleted file mode 100644 index 31ffc92c97bd..000000000000 --- a/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes/version.go +++ /dev/null @@ -1,9 +0,0 @@ -package hybridkubernetes - -import "fmt" - -const defaultApiVersion = "2021-10-01" - -func userAgent() string { - return fmt.Sprintf("pandora/hybridkubernetes/%s", defaultApiVersion) -} From fe3601df7c15981cb11b53ffe267f14035094b55 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Thu, 23 Mar 2023 16:24:05 +0800 Subject: [PATCH 08/11] resolve comments --- .../arc_kubernetes_cluster_resource.go | 2 +- .../arc_kubernetes_cluster_resource_test.go | 94 ++++++--- .../services/arckubernetes/client/client.go | 6 +- .../arckubernetes/testdata/private.pem | 51 ----- .../arckubernetes/testdata/public.cer | Bin 526 -> 0 bytes .../2021-10-01/connectedclusters/README.md | 141 +++++++++++++ .../2021-10-01/connectedclusters/client.go | 18 ++ .../2021-10-01/connectedclusters/constants.go | 111 +++++++++++ .../connectedclusters/id_connectedcluster.go | 127 ++++++++++++ .../method_connectedclustercreate_autorest.go | 79 ++++++++ .../method_connectedclusterdelete_autorest.go | 78 ++++++++ .../method_connectedclusterget_autorest.go | 68 +++++++ ...ctedclusterlistbyresourcegroup_autorest.go | 187 ++++++++++++++++++ ...ectedclusterlistbysubscription_autorest.go | 187 ++++++++++++++++++ ...usterlistclusterusercredential_autorest.go | 70 +++++++ .../method_connectedclusterupdate_autorest.go | 69 +++++++ .../model_connectedcluster.go | 20 ++ .../model_connectedclusterpatch.go | 9 + .../model_connectedclusterproperties.go | 49 +++++ .../model_credentialresult.go | 9 + .../model_credentialresults.go | 9 + .../model_hybridconnectionconfig.go | 11 ++ ...del_listclusterusercredentialproperties.go | 9 + .../connectedclusters/predicates.go | 32 +++ .../2021-10-01/connectedclusters/version.go | 12 ++ vendor/modules.txt | 1 + .../r/arc_kubernetes_cluster.html.markdown | 2 + 27 files changed, 1372 insertions(+), 79 deletions(-) delete mode 100644 internal/services/arckubernetes/testdata/private.pem delete mode 100644 internal/services/arckubernetes/testdata/public.cer create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/README.md create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/client.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/constants.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/id_connectedcluster.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclustercreate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterdelete_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterget_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbyresourcegroup_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbysubscription_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistclusterusercredential_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterupdate_autorest.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedcluster.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterpatch.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresult.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresults.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_hybridconnectionconfig.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_listclusterusercredentialproperties.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/predicates.go create mode 100644 vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/version.go diff --git a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go index c140642d725f..e785f3c82f46 100644 --- a/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource.go @@ -167,7 +167,7 @@ func resourceArcKubernetesClusterRead(d *pluginsdk.ResourceData, meta interface{ return fmt.Errorf("retrieving %s: %+v", *id, err) } - d.Set("name", id.ClusterName) + d.Set("name", id.ConnectedClusterName) d.Set("resource_group_name", id.ResourceGroupName) if model := resp.Model; model != nil { if err := d.Set("identity", identity.FlattenSystemAssigned(&model.Identity)); err != nil { diff --git a/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go b/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go index 01bd75e6d343..eaa320afd179 100644 --- a/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go +++ b/internal/services/arckubernetes/arc_kubernetes_cluster_resource_test.go @@ -2,12 +2,18 @@ package arckubernetes_test import ( "context" + "crypto/rsa" + "crypto/x509" + "encoding/base64" + "encoding/pem" "fmt" + + cryptoRand "crypto/rand" "math/rand" "os" "testing" - arckubernetes "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" + arckubernetes "github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters" "github.com/hashicorp/go-azure-helpers/lang/response" "github.com/hashicorp/terraform-provider-azurerm/internal/acceptance" @@ -22,16 +28,21 @@ type ArcKubernetesClusterResource struct{} func TestAccArcKubernetesCluster_basic(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") r := ArcKubernetesClusterResource{} + privateKey, publicKey, err := r.generateKey() + if err != nil { + t.Fatalf("failed to generate key: %+v", err) + } + data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.basic(data, privateKey, publicKey), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.update(data), + Config: r.update(data, privateKey, publicKey), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("distribution").HasValue("kind"), @@ -45,30 +56,43 @@ func TestAccArcKubernetesCluster_basic(t *testing.T) { func TestAccArcKubernetesCluster_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") r := ArcKubernetesClusterResource{} + privateKey, publicKey, err := r.generateKey() + if err != nil { + t.Fatalf("failed to generate key: %+v", err) + } + data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.basic(data), + Config: r.basic(data, privateKey, publicKey), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, - data.RequiresImportErrorStep(r.requiresImport), + { + Config: r.requiresImport(data, privateKey, publicKey), + ExpectError: acceptance.RequiresImportError(data.ResourceType), + }, }) } func TestAccArcKubernetesCluster_complete(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_arc_kubernetes_cluster", "test") r := ArcKubernetesClusterResource{} + privateKey, publicKey, err := r.generateKey() + if err != nil { + t.Fatalf("failed to generate key: %+v", err) + } + data.ResourceTest(t, r, []acceptance.TestStep{ { - Config: r.complete(data), + Config: r.complete(data, privateKey, publicKey), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), ), }, data.ImportStep(), { - Config: r.update(data), + Config: r.update(data, privateKey, publicKey), Check: acceptance.ComposeTestCheckFunc( check.That(data.ResourceName).ExistsInAzure(r), check.That(data.ResourceName).Key("distribution").HasValue("kind"), @@ -193,7 +217,7 @@ resource "azurerm_linux_virtual_machine" "test" { `, data.RandomInteger, data.Locations.Primary, credential) } -func (r ArcKubernetesClusterResource) provisionTemplate(data acceptance.TestData, credential string) string { +func (r ArcKubernetesClusterResource) provisionTemplate(data acceptance.TestData, credential string, privateKey string) string { return fmt.Sprintf(` connection { type = "ssh" @@ -225,7 +249,9 @@ provisioner "file" { } provisioner "file" { - source = "testdata/private.pem" + content = < %[3]s/agent_log", ] } -`, credential, data.RandomInteger, "/home/adminuser", os.Getenv("ARM_SUBSCRIPTION_ID"), os.Getenv("ARM_TENANT_ID")) +`, credential, data.RandomInteger, "/home/adminuser", os.Getenv("ARM_SUBSCRIPTION_ID"), os.Getenv("ARM_TENANT_ID"), privateKey) } -func (r ArcKubernetesClusterResource) basic(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) basic(data acceptance.TestData, privateKey string, publicKey string) string { credential := fmt.Sprintf("P@$$w0rd%d!", rand.Intn(10000)) template := r.template(data, credential) - provisionTemplate := r.provisionTemplate(data, credential) + provisionTemplate := r.provisionTemplate(data, credential, privateKey) return fmt.Sprintf(` %[1]s @@ -250,7 +276,7 @@ resource "azurerm_arc_kubernetes_cluster" "test" { name = "acctest-akcc-%[2]d" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location - agent_public_key_certificate = filebase64("testdata/public.cer") + agent_public_key_certificate = "%[4]s" identity { type = "SystemAssigned" } @@ -261,11 +287,11 @@ resource "azurerm_arc_kubernetes_cluster" "test" { azurerm_linux_virtual_machine.test ] } -`, template, data.RandomInteger, provisionTemplate) +`, template, data.RandomInteger, provisionTemplate, publicKey) } -func (r ArcKubernetesClusterResource) requiresImport(data acceptance.TestData) string { - config := r.basic(data) +func (r ArcKubernetesClusterResource) requiresImport(data acceptance.TestData, privateKey string, publicKey string) string { + config := r.basic(data, privateKey, publicKey) return fmt.Sprintf(` %s @@ -282,10 +308,10 @@ resource "azurerm_arc_kubernetes_cluster" "import" { `, config) } -func (r ArcKubernetesClusterResource) complete(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) complete(data acceptance.TestData, privateKey string, publicKey string) string { credential := fmt.Sprintf("P@$$w0rd%d!", rand.Intn(10000)) template := r.template(data, credential) - provisionTemplate := r.provisionTemplate(data, credential) + provisionTemplate := r.provisionTemplate(data, credential, privateKey) return fmt.Sprintf(` %[1]s @@ -293,7 +319,7 @@ resource "azurerm_arc_kubernetes_cluster" "test" { name = "acctest-akcc-%[2]d" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location - agent_public_key_certificate = filebase64("testdata/public.cer") + agent_public_key_certificate = "%[4]s" identity { type = "SystemAssigned" @@ -309,13 +335,13 @@ resource "azurerm_arc_kubernetes_cluster" "test" { azurerm_linux_virtual_machine.test ] } -`, template, data.RandomInteger, provisionTemplate) +`, template, data.RandomInteger, provisionTemplate, publicKey) } -func (r ArcKubernetesClusterResource) update(data acceptance.TestData) string { +func (r ArcKubernetesClusterResource) update(data acceptance.TestData, privateKey string, publicKey string) string { credential := fmt.Sprintf("P@$$w0rd%d!", rand.Intn(10000)) template := r.template(data, credential) - provisionTemplate := r.provisionTemplate(data, credential) + provisionTemplate := r.provisionTemplate(data, credential, privateKey) return fmt.Sprintf(` %[1]s @@ -323,7 +349,7 @@ resource "azurerm_arc_kubernetes_cluster" "test" { name = "acctest-akcc-%[2]d" resource_group_name = azurerm_resource_group.test.name location = azurerm_resource_group.test.location - agent_public_key_certificate = filebase64("testdata/public.cer") + agent_public_key_certificate = "%[4]s" identity { type = "SystemAssigned" @@ -339,5 +365,25 @@ resource "azurerm_arc_kubernetes_cluster" "test" { azurerm_linux_virtual_machine.test ] } -`, template, data.RandomInteger, provisionTemplate) +`, template, data.RandomInteger, provisionTemplate, publicKey) +} + +func (r ArcKubernetesClusterResource) generateKey() (string, string, error) { + privateKey, err := rsa.GenerateKey(cryptoRand.Reader, 4096) + if err != nil { + return "", "", fmt.Errorf("failed to generate RSA key") + } + + privateKeyBytes := x509.MarshalPKCS1PrivateKey(privateKey) + privateKeyBlock := &pem.Block{ + Type: "RSA PRIVATE KEY", + Bytes: privateKeyBytes, + } + + privatePem := pem.EncodeToMemory(privateKeyBlock) + if privatePem == nil { + return "", "", fmt.Errorf("failed to encode pem") + } + + return string(privatePem), base64.StdEncoding.EncodeToString(x509.MarshalPKCS1PublicKey(&privateKey.PublicKey)), nil } diff --git a/internal/services/arckubernetes/client/client.go b/internal/services/arckubernetes/client/client.go index b748f6da3ef2..952a90e0d220 100644 --- a/internal/services/arckubernetes/client/client.go +++ b/internal/services/arckubernetes/client/client.go @@ -1,17 +1,17 @@ package client import ( + "github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters" "github.com/hashicorp/terraform-provider-azurerm/internal/common" - "github.com/hashicorp/terraform-provider-azurerm/internal/services/arckubernetes/sdk/2021-10-01/hybridkubernetes" ) type Client struct { - ArcKubernetesClient *hybridkubernetes.HybridKubernetesClient + ArcKubernetesClient *connectedclusters.ConnectedClustersClient } func NewClient(o *common.ClientOptions) *Client { - arcKubernetesClient := hybridkubernetes.NewHybridKubernetesClientWithBaseURI(o.ResourceManagerEndpoint) + arcKubernetesClient := connectedclusters.NewConnectedClustersClientWithBaseURI(o.ResourceManagerEndpoint) o.ConfigureClient(&arcKubernetesClient.Client, o.ResourceManagerAuthorizer) return &Client{ diff --git a/internal/services/arckubernetes/testdata/private.pem b/internal/services/arckubernetes/testdata/private.pem deleted file mode 100644 index a0dfb3aedb3c..000000000000 --- a/internal/services/arckubernetes/testdata/private.pem +++ /dev/null @@ -1,51 +0,0 @@ ------BEGIN RSA PRIVATE KEY----- -MIIJKAIBAAKCAgEAxEJ9BOnVptQvDAuUZL5p1qhln7p9W/nSrnSDQPtiRfCcRcVb -GbjnU78T6HsLwT4Un37bhXqj2u+Pg6TTpnc9XKa7mGHT3mOGF4G4lIhxGaC9bgCW -as0d8bb97VKq/DkJqgSCqXVZ6hjOo5z4ESisYbkugtO9uENXVYNqkeRXAan7oWjK -JAFV8/pq6lctzNpiAoSti/INGUT2tfLjbsu2f+PrPIljFytXPNiUJClaChxZAwZ8 -pU2YJLUdFAtjOp/tlEnHt9UcdHp65DV6C00GNrORnR/hFrim9fqigMxGRtrJm96u -RGeApBLKto+OPodlSSpiuBztQlaNnX6Ryw5iKe2j241ehzA937shq14x3IuCBvkC -6OxL/KQP5Ry950d4nl4QtrFddWYa1Gjl+qkL6uqgfxV87JkieEfp1wdNzG+11bqt -38dm0SoWEB/4+PTRVKq2vwBIBGKv2lEEb3hFFUb7vAOU6RGwYDTUGQiHuL8ZtC8q -fHQe86J3CSFRS5ENBnCi9RMr6/blMlca5OmOa4/zWpCyZCIWvlK4Pb6/lOA15aMU -4+Z2SdUvBN8Zf1QAc+5nrWP/70gs2mut1SpaVl+gN0/0hhAw8HPvBXUc4WMZLLDf -P25knbOywJ9zJQH0sDxijCozdGpfxO904cTo278Fwx4tOWcZZ+55+2j0OBsCAwEA -AQKCAgBA6c7pC6Cfk+nVvZTA95wRJFSsjqW9ALX2/tGU8jCwemNtzleR++8Da51d -lSkvquVuVaqtDQHaPcdFnwRkOGdC2GEPBzhpA5kL+FuBQVnLRLezBR27SInBc6ms -T93/G6x/IAvJmed5/ueGBTqljkLp9bKVEgzbv+ZIgfWDOLewdLUmT38ghpKT5n1r -chdTfN3TAGhYc+ByPbWuO56O/HEp/sxFExoDxVGO7gGdrlG6K2MjlYcvs6kBZygt -g5C4CMKve/HDc4j8W7B+/9MUns7R0/XzNuKfvcZ3cIVEPYx3DhGF7RLNzEAnxJFo -7bV6KBVPrGXHiMXO3crsTztQorrDmB/KRrldserQd0UiYtydSHlRbQnDRbGKYnVf -Z3NGtjjqHb2mZv2YsKHKhtJcUbohSNYZLv4tJLy6SDfsgexIH1f4+knrUvgmlMvG -zWKsHm4d7/mLJAzpEFhs8C4AsMC4mdt60+R23uMJ6nZ/RUxz7NgtDRZLbX46XumW -I2e6+yXitKLxZ5SyO/dW/26YUBYZNJaw/7A5o7KveBtGpslSK75zaHyajfNsrZoj -eQDlpmCEViDRGhAKT+fSrGH9EO2wX8hzGo2ZD4lxYiRyzAogF/lCgOR+TxlKKd0l -Iz9fibVXloRerZbrQNNf2D2p3dDotNZC9hDKeWPW2NqpVw7EwQKCAQEA2bto0Jpr -zd4MNANQpaGp33dJaLOwK06Qd3U/9Gv8HId94iN1ocUMfU/BFItziLreIVd9dt47 -8XIqHPaMSZ+mJiWSZ0IMh/ZxVnoyeU9UTfNxnS6pUGMN+5JpZHUvgkipJZTnhPU+ -bG9unSRE37jLLss2yGNBiFww8BUgp5FtwFD/V5+yvlNxtt+IJQ1vMnoexa3LRLum -NyXNY8MOZckZ6/isVsJbYslzyAhxC0nhl77NKVGvqU8btc79PPzSleSWAqQxuSop -NKb1GXUEXtBWnFnSpclUTy1SYCJMPuXiKbXwtPpGQX8QgDUUGoTthurR5uJcO1W1 -DGVTqifUArzs2wKCAQEA5sD05sFBfGjPJrTM6YEGuFE5URaSPSssdYuwesB4aOVT -HiPlvoB3//b6NtLw8WnnbPe0tKu9D/8Q8Hh4j0sA/WTGUc9yg2HgfdWWDoa3CG00 -AOsv6oHGULSitsD4uceRfxh2Y1DCvV7uhBhTtcgtCH14qx/q2Hee8LddZpzl+LyS -nXvo6t3+uKGRw2W/qVbhpboQiolfCvXRFA5ZXGZc8atGE8sniqYyh4pG3Bppwxqz -D/ixkuChBoXGaQTtQ4jfyj86ZcPCc6Pn4jMJ3LJOuKFcRgqSkbyUPuAYcXs5TR5Y -BwzxoJLjGZIY6YQlHkFrl8wy9Z9rPnrMOTOg6/4lwQKCAQA+QZL3yp+2jp4opSYD -JhV/ewk3ceGWkHFIZvMxfUrqEWfSKFdzOPeYQRyxNiqD1wK6v9x1B5hWMlGOVITK -bGbCk42oDr+shK/ljS0veJpfa5N54SSygpA19ahC/CrocsRCpbAJWWJO+RHExuEW -oy0dpSd15sOPLOUlULU0lKWwDrjkIhqmxw9FveacyZmY8kgoN8heT9V4AUwYEWbl -fbn2ufT1Hb+poHaFpLxGAQsLK5hYDy5OF/uRYa0RKi1AhMrL2I0LJ93+WxrL+6ST -Q7jwHdLYape7x/a83DG27l5blNVNuh4qjh12uzaTWpzcLfp0rRa4NIp/D937UkYR -vllvAoIBAEQGbiv4nM2IOEk404+isdB0YWk+Ni5CJAEjBQuq4dRKho5EFt5qEPYs -YOb4mH8SsV62R1dbqYilsOCzIxdbDRemNbC4bxG8MOnnpSzzGdIqH0KGEsIXL9dq -6OznRmu+IW5OT9hHXqFk8vuOEF9ue5gdJQ2NgzX9TaW46JfvePwy2yYB+VAD0aus -NcRconvRWQP6LhYpGROqE9DNyhorMwsraqU7JpUBGbRLV0hboQIbRN5YekDKZ638 -kdkz0p4uI4sDyLtnUlO05g8Q7L9a8UoMh58+TqcX6LwAZDRQFzxczaaGclTb+Ib5 -Qs7UXfzlXEqLsBoovPzWRo42YiIv8gECggEBAIu3DDxlIc6Y6t7AuDzknCkqpLXC -VqREmfhYflirlMtXgRgh1+wnZ3S4Uid9eCPtHcFKHgQ5Y3f084r7E0OpNdo/UgER -nX86LNtpSdeQ3tTWt3vqgX8WPdOo9Fyll357/+LfRX5U1SeCbmmSI9PBTmx0qe4F -ZGhFfh6kgVcYBWtYoOaqrniBdWjotxoNeDoiG/PA2UNiD3CCEiS0NcG8HElXWGNG -wlj/1JfmzvNOqy3I7R+vjM5+KyBWnmq1neCGMLI6yFq9Rms7Twotoeil3477m2B5 -Fg0RRUb6dJHX25xTahwLu0/8weAFuj6xIBoz+oVAw3pCyAxTUNqui8f/0Ug= ------END RSA PRIVATE KEY----- \ No newline at end of file diff --git a/internal/services/arckubernetes/testdata/public.cer b/internal/services/arckubernetes/testdata/public.cer deleted file mode 100644 index 18e27003a9ca978e33c73bbce1b5b5817129e472..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 526 zcmV+p0`dJYf&vNxf&u{m#6o=p>D8vxFANKmWWH(EsAZqJeOvj`u5^Py`(j1#oJGZ3 z8Mx0-OYRw(- zw*Bo=s{A<#ssw_mby?~d&ZC_85h$!-xh{g!y|_bHRfB4gZDOw5~Spx=qrA?S5wH*`-V>+Mh zlu5_8)f{wsdgL{F3rz+#vyq)2;TE{2_4=ZK%tl7q$(!D;L}!4c63VuZjy{KFNh)Hv z9PL6@jh%jx%MM~G?W5a`UWYI}-@75JUNPK@f(H2l=Y#rWeC(Mbct`2i2Tjaxwbi<<-^XUrDi#nQ`1thERI0YW07wL4ui8-r zZ+Jx&M*F-2l<5($U^LVj2#2`88MH4dd~_c3qIU@)QA?2x25_SF6D#ZX0+EZS?W)hb$6U!XTn z^o9^H@N@44bsXVi87#2hKW=25v$DXSb0q=vusmXnDl>FyU&QZp;l$|MzXih{Ejecy QXYP6XX!JN60s{d60gp)o4FCWD diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/README.md b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/README.md new file mode 100644 index 000000000000..6b58fde3c10e --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/README.md @@ -0,0 +1,141 @@ + +## `github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters` Documentation + +The `connectedclusters` SDK allows for interaction with the Azure Resource Manager Service `hybridkubernetes` (API Version `2021-10-01`). + +This readme covers example usages, but further information on [using this SDK can be found in the project root](https://github.com/hashicorp/go-azure-sdk/tree/main/docs). + +### Import Path + +```go +import "github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters" +``` + + +### Client Initialization + +```go +client := connectedclusters.NewConnectedClustersClientWithBaseURI("https://management.azure.com") +client.Client.Authorizer = authorizer +``` + + +### Example Usage: `ConnectedClustersClient.ConnectedClusterCreate` + +```go +ctx := context.TODO() +id := connectedclusters.NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedClusterValue") + +payload := connectedclusters.ConnectedCluster{ + // ... +} + + +if err := client.ConnectedClusterCreateThenPoll(ctx, id, payload); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConnectedClustersClient.ConnectedClusterDelete` + +```go +ctx := context.TODO() +id := connectedclusters.NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedClusterValue") + +if err := client.ConnectedClusterDeleteThenPoll(ctx, id); err != nil { + // handle the error +} +``` + + +### Example Usage: `ConnectedClustersClient.ConnectedClusterGet` + +```go +ctx := context.TODO() +id := connectedclusters.NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedClusterValue") + +read, err := client.ConnectedClusterGet(ctx, id) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedClustersClient.ConnectedClusterListByResourceGroup` + +```go +ctx := context.TODO() +id := connectedclusters.NewResourceGroupID("12345678-1234-9876-4563-123456789012", "example-resource-group") + +// alternatively `client.ConnectedClusterListByResourceGroup(ctx, id)` can be used to do batched pagination +items, err := client.ConnectedClusterListByResourceGroupComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ConnectedClustersClient.ConnectedClusterListBySubscription` + +```go +ctx := context.TODO() +id := connectedclusters.NewSubscriptionID("12345678-1234-9876-4563-123456789012") + +// alternatively `client.ConnectedClusterListBySubscription(ctx, id)` can be used to do batched pagination +items, err := client.ConnectedClusterListBySubscriptionComplete(ctx, id) +if err != nil { + // handle the error +} +for _, item := range items { + // do something +} +``` + + +### Example Usage: `ConnectedClustersClient.ConnectedClusterListClusterUserCredential` + +```go +ctx := context.TODO() +id := connectedclusters.NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedClusterValue") + +payload := connectedclusters.ListClusterUserCredentialProperties{ + // ... +} + + +read, err := client.ConnectedClusterListClusterUserCredential(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` + + +### Example Usage: `ConnectedClustersClient.ConnectedClusterUpdate` + +```go +ctx := context.TODO() +id := connectedclusters.NewConnectedClusterID("12345678-1234-9876-4563-123456789012", "example-resource-group", "connectedClusterValue") + +payload := connectedclusters.ConnectedClusterPatch{ + // ... +} + + +read, err := client.ConnectedClusterUpdate(ctx, id, payload) +if err != nil { + // handle the error +} +if model := read.Model; model != nil { + // do something with the model/response object +} +``` diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/client.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/client.go new file mode 100644 index 000000000000..8927fd807b8f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/client.go @@ -0,0 +1,18 @@ +package connectedclusters + +import "github.com/Azure/go-autorest/autorest" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClustersClient struct { + Client autorest.Client + baseUri string +} + +func NewConnectedClustersClientWithBaseURI(endpoint string) ConnectedClustersClient { + return ConnectedClustersClient{ + Client: autorest.NewClientWithUserAgent(userAgent()), + baseUri: endpoint, + } +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/constants.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/constants.go new file mode 100644 index 000000000000..dbe53c5b621b --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/constants.go @@ -0,0 +1,111 @@ +package connectedclusters + +import "strings" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type AuthenticationMethod string + +const ( + AuthenticationMethodAAD AuthenticationMethod = "AAD" + AuthenticationMethodToken AuthenticationMethod = "Token" +) + +func PossibleValuesForAuthenticationMethod() []string { + return []string{ + string(AuthenticationMethodAAD), + string(AuthenticationMethodToken), + } +} + +func parseAuthenticationMethod(input string) (*AuthenticationMethod, error) { + vals := map[string]AuthenticationMethod{ + "aad": AuthenticationMethodAAD, + "token": AuthenticationMethodToken, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := AuthenticationMethod(input) + return &out, nil +} + +type ConnectivityStatus string + +const ( + ConnectivityStatusConnected ConnectivityStatus = "Connected" + ConnectivityStatusConnecting ConnectivityStatus = "Connecting" + ConnectivityStatusExpired ConnectivityStatus = "Expired" + ConnectivityStatusOffline ConnectivityStatus = "Offline" +) + +func PossibleValuesForConnectivityStatus() []string { + return []string{ + string(ConnectivityStatusConnected), + string(ConnectivityStatusConnecting), + string(ConnectivityStatusExpired), + string(ConnectivityStatusOffline), + } +} + +func parseConnectivityStatus(input string) (*ConnectivityStatus, error) { + vals := map[string]ConnectivityStatus{ + "connected": ConnectivityStatusConnected, + "connecting": ConnectivityStatusConnecting, + "expired": ConnectivityStatusExpired, + "offline": ConnectivityStatusOffline, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ConnectivityStatus(input) + return &out, nil +} + +type ProvisioningState string + +const ( + ProvisioningStateAccepted ProvisioningState = "Accepted" + ProvisioningStateCanceled ProvisioningState = "Canceled" + ProvisioningStateDeleting ProvisioningState = "Deleting" + ProvisioningStateFailed ProvisioningState = "Failed" + ProvisioningStateProvisioning ProvisioningState = "Provisioning" + ProvisioningStateSucceeded ProvisioningState = "Succeeded" + ProvisioningStateUpdating ProvisioningState = "Updating" +) + +func PossibleValuesForProvisioningState() []string { + return []string{ + string(ProvisioningStateAccepted), + string(ProvisioningStateCanceled), + string(ProvisioningStateDeleting), + string(ProvisioningStateFailed), + string(ProvisioningStateProvisioning), + string(ProvisioningStateSucceeded), + string(ProvisioningStateUpdating), + } +} + +func parseProvisioningState(input string) (*ProvisioningState, error) { + vals := map[string]ProvisioningState{ + "accepted": ProvisioningStateAccepted, + "canceled": ProvisioningStateCanceled, + "deleting": ProvisioningStateDeleting, + "failed": ProvisioningStateFailed, + "provisioning": ProvisioningStateProvisioning, + "succeeded": ProvisioningStateSucceeded, + "updating": ProvisioningStateUpdating, + } + if v, ok := vals[strings.ToLower(input)]; ok { + return &v, nil + } + + // otherwise presume it's an undefined value and best-effort it + out := ProvisioningState(input) + return &out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/id_connectedcluster.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/id_connectedcluster.go new file mode 100644 index 000000000000..c89b6451ad6a --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/id_connectedcluster.go @@ -0,0 +1,127 @@ +package connectedclusters + +import ( + "fmt" + "strings" + + "github.com/hashicorp/go-azure-helpers/resourcemanager/resourceids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +var _ resourceids.ResourceId = ConnectedClusterId{} + +// ConnectedClusterId is a struct representing the Resource ID for a Connected Cluster +type ConnectedClusterId struct { + SubscriptionId string + ResourceGroupName string + ConnectedClusterName string +} + +// NewConnectedClusterID returns a new ConnectedClusterId struct +func NewConnectedClusterID(subscriptionId string, resourceGroupName string, connectedClusterName string) ConnectedClusterId { + return ConnectedClusterId{ + SubscriptionId: subscriptionId, + ResourceGroupName: resourceGroupName, + ConnectedClusterName: connectedClusterName, + } +} + +// ParseConnectedClusterID parses 'input' into a ConnectedClusterId +func ParseConnectedClusterID(input string) (*ConnectedClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(ConnectedClusterId{}) + parsed, err := parser.Parse(input, false) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ConnectedClusterId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ConnectedClusterName, ok = parsed.Parsed["connectedClusterName"]; !ok { + return nil, fmt.Errorf("the segment 'connectedClusterName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ParseConnectedClusterIDInsensitively parses 'input' case-insensitively into a ConnectedClusterId +// note: this method should only be used for API response data and not user input +func ParseConnectedClusterIDInsensitively(input string) (*ConnectedClusterId, error) { + parser := resourceids.NewParserFromResourceIdType(ConnectedClusterId{}) + parsed, err := parser.Parse(input, true) + if err != nil { + return nil, fmt.Errorf("parsing %q: %+v", input, err) + } + + var ok bool + id := ConnectedClusterId{} + + if id.SubscriptionId, ok = parsed.Parsed["subscriptionId"]; !ok { + return nil, fmt.Errorf("the segment 'subscriptionId' was not found in the resource id %q", input) + } + + if id.ResourceGroupName, ok = parsed.Parsed["resourceGroupName"]; !ok { + return nil, fmt.Errorf("the segment 'resourceGroupName' was not found in the resource id %q", input) + } + + if id.ConnectedClusterName, ok = parsed.Parsed["connectedClusterName"]; !ok { + return nil, fmt.Errorf("the segment 'connectedClusterName' was not found in the resource id %q", input) + } + + return &id, nil +} + +// ValidateConnectedClusterID checks that 'input' can be parsed as a Connected Cluster ID +func ValidateConnectedClusterID(input interface{}, key string) (warnings []string, errors []error) { + v, ok := input.(string) + if !ok { + errors = append(errors, fmt.Errorf("expected %q to be a string", key)) + return + } + + if _, err := ParseConnectedClusterID(v); err != nil { + errors = append(errors, err) + } + + return +} + +// ID returns the formatted Connected Cluster ID +func (id ConnectedClusterId) ID() string { + fmtString := "/subscriptions/%s/resourceGroups/%s/providers/Microsoft.Kubernetes/connectedClusters/%s" + return fmt.Sprintf(fmtString, id.SubscriptionId, id.ResourceGroupName, id.ConnectedClusterName) +} + +// Segments returns a slice of Resource ID Segments which comprise this Connected Cluster ID +func (id ConnectedClusterId) Segments() []resourceids.Segment { + return []resourceids.Segment{ + resourceids.StaticSegment("staticSubscriptions", "subscriptions", "subscriptions"), + resourceids.SubscriptionIdSegment("subscriptionId", "12345678-1234-9876-4563-123456789012"), + resourceids.StaticSegment("staticResourceGroups", "resourceGroups", "resourceGroups"), + resourceids.ResourceGroupSegment("resourceGroupName", "example-resource-group"), + resourceids.StaticSegment("staticProviders", "providers", "providers"), + resourceids.ResourceProviderSegment("staticMicrosoftKubernetes", "Microsoft.Kubernetes", "Microsoft.Kubernetes"), + resourceids.StaticSegment("staticConnectedClusters", "connectedClusters", "connectedClusters"), + resourceids.UserSpecifiedSegment("connectedClusterName", "connectedClusterValue"), + } +} + +// String returns a human-readable description of this Connected Cluster ID +func (id ConnectedClusterId) String() string { + components := []string{ + fmt.Sprintf("Subscription: %q", id.SubscriptionId), + fmt.Sprintf("Resource Group Name: %q", id.ResourceGroupName), + fmt.Sprintf("Connected Cluster Name: %q", id.ConnectedClusterName), + } + return fmt.Sprintf("Connected Cluster (%s)", strings.Join(components, "\n")) +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclustercreate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclustercreate_autorest.go new file mode 100644 index 000000000000..46ed03fa0a75 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclustercreate_autorest.go @@ -0,0 +1,79 @@ +package connectedclusters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterCreateOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ConnectedClusterCreate ... +func (c ConnectedClustersClient) ConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (result ConnectedClusterCreateOperationResponse, err error) { + req, err := c.preparerForConnectedClusterCreate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterCreate", nil, "Failure preparing request") + return + } + + result, err = c.senderForConnectedClusterCreate(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterCreate", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ConnectedClusterCreateThenPoll performs ConnectedClusterCreate then polls until it's completed +func (c ConnectedClustersClient) ConnectedClusterCreateThenPoll(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) error { + result, err := c.ConnectedClusterCreate(ctx, id, input) + if err != nil { + return fmt.Errorf("performing ConnectedClusterCreate: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ConnectedClusterCreate: %+v", err) + } + + return nil +} + +// preparerForConnectedClusterCreate prepares the ConnectedClusterCreate request. +func (c ConnectedClustersClient) preparerForConnectedClusterCreate(ctx context.Context, id ConnectedClusterId, input ConnectedCluster) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPut(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForConnectedClusterCreate sends the ConnectedClusterCreate request. The method will close the +// http.Response Body if it receives an error. +func (c ConnectedClustersClient) senderForConnectedClusterCreate(ctx context.Context, req *http.Request) (future ConnectedClusterCreateOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterdelete_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterdelete_autorest.go new file mode 100644 index 000000000000..3c075e92fb78 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterdelete_autorest.go @@ -0,0 +1,78 @@ +package connectedclusters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/polling" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterDeleteOperationResponse struct { + Poller polling.LongRunningPoller + HttpResponse *http.Response +} + +// ConnectedClusterDelete ... +func (c ConnectedClustersClient) ConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterDeleteOperationResponse, err error) { + req, err := c.preparerForConnectedClusterDelete(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterDelete", nil, "Failure preparing request") + return + } + + result, err = c.senderForConnectedClusterDelete(ctx, req) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterDelete", result.HttpResponse, "Failure sending request") + return + } + + return +} + +// ConnectedClusterDeleteThenPoll performs ConnectedClusterDelete then polls until it's completed +func (c ConnectedClustersClient) ConnectedClusterDeleteThenPoll(ctx context.Context, id ConnectedClusterId) error { + result, err := c.ConnectedClusterDelete(ctx, id) + if err != nil { + return fmt.Errorf("performing ConnectedClusterDelete: %+v", err) + } + + if err := result.Poller.PollUntilDone(); err != nil { + return fmt.Errorf("polling after ConnectedClusterDelete: %+v", err) + } + + return nil +} + +// preparerForConnectedClusterDelete prepares the ConnectedClusterDelete request. +func (c ConnectedClustersClient) preparerForConnectedClusterDelete(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsDelete(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// senderForConnectedClusterDelete sends the ConnectedClusterDelete request. The method will close the +// http.Response Body if it receives an error. +func (c ConnectedClustersClient) senderForConnectedClusterDelete(ctx context.Context, req *http.Request) (future ConnectedClusterDeleteOperationResponse, err error) { + var resp *http.Response + resp, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + return + } + + future.Poller, err = polling.NewPollerFromResponse(ctx, resp, c.Client, req.Method) + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterget_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterget_autorest.go new file mode 100644 index 000000000000..b5150631856c --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterget_autorest.go @@ -0,0 +1,68 @@ +package connectedclusters + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterGetOperationResponse struct { + HttpResponse *http.Response + Model *ConnectedCluster +} + +// ConnectedClusterGet ... +func (c ConnectedClustersClient) ConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (result ConnectedClusterGetOperationResponse, err error) { + req, err := c.preparerForConnectedClusterGet(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterGet", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterGet", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterGet(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterGet", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForConnectedClusterGet prepares the ConnectedClusterGet request. +func (c ConnectedClustersClient) preparerForConnectedClusterGet(ctx context.Context, id ConnectedClusterId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterGet handles the response to the ConnectedClusterGet request. The method always +// closes the http.Response Body. +func (c ConnectedClustersClient) responderForConnectedClusterGet(resp *http.Response) (result ConnectedClusterGetOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbyresourcegroup_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbyresourcegroup_autorest.go new file mode 100644 index 000000000000..ff6e9cc79d71 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbyresourcegroup_autorest.go @@ -0,0 +1,187 @@ +package connectedclusters + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterListByResourceGroupOperationResponse struct { + HttpResponse *http.Response + Model *[]ConnectedCluster + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ConnectedClusterListByResourceGroupOperationResponse, error) +} + +type ConnectedClusterListByResourceGroupCompleteResult struct { + Items []ConnectedCluster +} + +func (r ConnectedClusterListByResourceGroupOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ConnectedClusterListByResourceGroupOperationResponse) LoadMore(ctx context.Context) (resp ConnectedClusterListByResourceGroupOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ConnectedClusterListByResourceGroup ... +func (c ConnectedClustersClient) ConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (resp ConnectedClusterListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForConnectedClusterListByResourceGroup(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForConnectedClusterListByResourceGroup(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListByResourceGroup", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForConnectedClusterListByResourceGroup prepares the ConnectedClusterListByResourceGroup request. +func (c ConnectedClustersClient) preparerForConnectedClusterListByResourceGroup(ctx context.Context, id commonids.ResourceGroupId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Kubernetes/connectedClusters", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForConnectedClusterListByResourceGroupWithNextLink prepares the ConnectedClusterListByResourceGroup request with the given nextLink token. +func (c ConnectedClustersClient) preparerForConnectedClusterListByResourceGroupWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterListByResourceGroup handles the response to the ConnectedClusterListByResourceGroup request. The method always +// closes the http.Response Body. +func (c ConnectedClustersClient) responderForConnectedClusterListByResourceGroup(resp *http.Response) (result ConnectedClusterListByResourceGroupOperationResponse, err error) { + type page struct { + Values []ConnectedCluster `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListByResourceGroupOperationResponse, err error) { + req, err := c.preparerForConnectedClusterListByResourceGroupWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListByResourceGroup", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterListByResourceGroup(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListByResourceGroup", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ConnectedClusterListByResourceGroupComplete retrieves all of the results into a single object +func (c ConnectedClustersClient) ConnectedClusterListByResourceGroupComplete(ctx context.Context, id commonids.ResourceGroupId) (ConnectedClusterListByResourceGroupCompleteResult, error) { + return c.ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx, id, ConnectedClusterOperationPredicate{}) +} + +// ConnectedClusterListByResourceGroupCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ConnectedClustersClient) ConnectedClusterListByResourceGroupCompleteMatchingPredicate(ctx context.Context, id commonids.ResourceGroupId, predicate ConnectedClusterOperationPredicate) (resp ConnectedClusterListByResourceGroupCompleteResult, err error) { + items := make([]ConnectedCluster, 0) + + page, err := c.ConnectedClusterListByResourceGroup(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ConnectedClusterListByResourceGroupCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbysubscription_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbysubscription_autorest.go new file mode 100644 index 000000000000..52786074e08d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistbysubscription_autorest.go @@ -0,0 +1,187 @@ +package connectedclusters + +import ( + "context" + "fmt" + "net/http" + "net/url" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" + "github.com/hashicorp/go-azure-helpers/resourcemanager/commonids" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterListBySubscriptionOperationResponse struct { + HttpResponse *http.Response + Model *[]ConnectedCluster + + nextLink *string + nextPageFunc func(ctx context.Context, nextLink string) (ConnectedClusterListBySubscriptionOperationResponse, error) +} + +type ConnectedClusterListBySubscriptionCompleteResult struct { + Items []ConnectedCluster +} + +func (r ConnectedClusterListBySubscriptionOperationResponse) HasMore() bool { + return r.nextLink != nil +} + +func (r ConnectedClusterListBySubscriptionOperationResponse) LoadMore(ctx context.Context) (resp ConnectedClusterListBySubscriptionOperationResponse, err error) { + if !r.HasMore() { + err = fmt.Errorf("no more pages returned") + return + } + return r.nextPageFunc(ctx, *r.nextLink) +} + +// ConnectedClusterListBySubscription ... +func (c ConnectedClustersClient) ConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (resp ConnectedClusterListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForConnectedClusterListBySubscription(ctx, id) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") + return + } + + resp.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure sending request") + return + } + + resp, err = c.responderForConnectedClusterListBySubscription(resp.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListBySubscription", resp.HttpResponse, "Failure responding to request") + return + } + return +} + +// preparerForConnectedClusterListBySubscription prepares the ConnectedClusterListBySubscription request. +func (c ConnectedClustersClient) preparerForConnectedClusterListBySubscription(ctx context.Context, id commonids.SubscriptionId) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/providers/Microsoft.Kubernetes/connectedClusters", id.ID())), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// preparerForConnectedClusterListBySubscriptionWithNextLink prepares the ConnectedClusterListBySubscription request with the given nextLink token. +func (c ConnectedClustersClient) preparerForConnectedClusterListBySubscriptionWithNextLink(ctx context.Context, nextLink string) (*http.Request, error) { + uri, err := url.Parse(nextLink) + if err != nil { + return nil, fmt.Errorf("parsing nextLink %q: %+v", nextLink, err) + } + queryParameters := map[string]interface{}{} + for k, v := range uri.Query() { + if len(v) == 0 { + continue + } + val := v[0] + val = autorest.Encode("query", val) + queryParameters[k] = val + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsGet(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(uri.Path), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterListBySubscription handles the response to the ConnectedClusterListBySubscription request. The method always +// closes the http.Response Body. +func (c ConnectedClustersClient) responderForConnectedClusterListBySubscription(resp *http.Response) (result ConnectedClusterListBySubscriptionOperationResponse, err error) { + type page struct { + Values []ConnectedCluster `json:"value"` + NextLink *string `json:"nextLink"` + } + var respObj page + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&respObj), + autorest.ByClosing()) + result.HttpResponse = resp + result.Model = &respObj.Values + result.nextLink = respObj.NextLink + if respObj.NextLink != nil { + result.nextPageFunc = func(ctx context.Context, nextLink string) (result ConnectedClusterListBySubscriptionOperationResponse, err error) { + req, err := c.preparerForConnectedClusterListBySubscriptionWithNextLink(ctx, nextLink) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListBySubscription", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterListBySubscription(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListBySubscription", result.HttpResponse, "Failure responding to request") + return + } + + return + } + } + return +} + +// ConnectedClusterListBySubscriptionComplete retrieves all of the results into a single object +func (c ConnectedClustersClient) ConnectedClusterListBySubscriptionComplete(ctx context.Context, id commonids.SubscriptionId) (ConnectedClusterListBySubscriptionCompleteResult, error) { + return c.ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx, id, ConnectedClusterOperationPredicate{}) +} + +// ConnectedClusterListBySubscriptionCompleteMatchingPredicate retrieves all of the results and then applied the predicate +func (c ConnectedClustersClient) ConnectedClusterListBySubscriptionCompleteMatchingPredicate(ctx context.Context, id commonids.SubscriptionId, predicate ConnectedClusterOperationPredicate) (resp ConnectedClusterListBySubscriptionCompleteResult, err error) { + items := make([]ConnectedCluster, 0) + + page, err := c.ConnectedClusterListBySubscription(ctx, id) + if err != nil { + err = fmt.Errorf("loading the initial page: %+v", err) + return + } + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + + for page.HasMore() { + page, err = page.LoadMore(ctx) + if err != nil { + err = fmt.Errorf("loading the next page: %+v", err) + return + } + + if page.Model != nil { + for _, v := range *page.Model { + if predicate.Matches(v) { + items = append(items, v) + } + } + } + } + + out := ConnectedClusterListBySubscriptionCompleteResult{ + Items: items, + } + return out, nil +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistclusterusercredential_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistclusterusercredential_autorest.go new file mode 100644 index 000000000000..ae613bee39f9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterlistclusterusercredential_autorest.go @@ -0,0 +1,70 @@ +package connectedclusters + +import ( + "context" + "fmt" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterListClusterUserCredentialOperationResponse struct { + HttpResponse *http.Response + Model *CredentialResults +} + +// ConnectedClusterListClusterUserCredential ... +func (c ConnectedClustersClient) ConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (result ConnectedClusterListClusterUserCredentialOperationResponse, err error) { + req, err := c.preparerForConnectedClusterListClusterUserCredential(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListClusterUserCredential", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterListClusterUserCredential(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterListClusterUserCredential", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForConnectedClusterListClusterUserCredential prepares the ConnectedClusterListClusterUserCredential request. +func (c ConnectedClustersClient) preparerForConnectedClusterListClusterUserCredential(ctx context.Context, id ConnectedClusterId, input ListClusterUserCredentialProperties) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPost(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(fmt.Sprintf("%s/listClusterUserCredential", id.ID())), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterListClusterUserCredential handles the response to the ConnectedClusterListClusterUserCredential request. The method always +// closes the http.Response Body. +func (c ConnectedClustersClient) responderForConnectedClusterListClusterUserCredential(resp *http.Response) (result ConnectedClusterListClusterUserCredentialOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterupdate_autorest.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterupdate_autorest.go new file mode 100644 index 000000000000..d12988702916 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/method_connectedclusterupdate_autorest.go @@ -0,0 +1,69 @@ +package connectedclusters + +import ( + "context" + "net/http" + + "github.com/Azure/go-autorest/autorest" + "github.com/Azure/go-autorest/autorest/azure" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterUpdateOperationResponse struct { + HttpResponse *http.Response + Model *ConnectedCluster +} + +// ConnectedClusterUpdate ... +func (c ConnectedClustersClient) ConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (result ConnectedClusterUpdateOperationResponse, err error) { + req, err := c.preparerForConnectedClusterUpdate(ctx, id, input) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterUpdate", nil, "Failure preparing request") + return + } + + result.HttpResponse, err = c.Client.Send(req, azure.DoRetryWithRegistration(c.Client)) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure sending request") + return + } + + result, err = c.responderForConnectedClusterUpdate(result.HttpResponse) + if err != nil { + err = autorest.NewErrorWithError(err, "connectedclusters.ConnectedClustersClient", "ConnectedClusterUpdate", result.HttpResponse, "Failure responding to request") + return + } + + return +} + +// preparerForConnectedClusterUpdate prepares the ConnectedClusterUpdate request. +func (c ConnectedClustersClient) preparerForConnectedClusterUpdate(ctx context.Context, id ConnectedClusterId, input ConnectedClusterPatch) (*http.Request, error) { + queryParameters := map[string]interface{}{ + "api-version": defaultApiVersion, + } + + preparer := autorest.CreatePreparer( + autorest.AsContentType("application/json; charset=utf-8"), + autorest.AsPatch(), + autorest.WithBaseURL(c.baseUri), + autorest.WithPath(id.ID()), + autorest.WithJSON(input), + autorest.WithQueryParameters(queryParameters)) + return preparer.Prepare((&http.Request{}).WithContext(ctx)) +} + +// responderForConnectedClusterUpdate handles the response to the ConnectedClusterUpdate request. The method always +// closes the http.Response Body. +func (c ConnectedClustersClient) responderForConnectedClusterUpdate(resp *http.Response) (result ConnectedClusterUpdateOperationResponse, err error) { + err = autorest.Respond( + resp, + azure.WithErrorUnlessStatusCode(http.StatusOK), + autorest.ByUnmarshallingJSON(&result.Model), + autorest.ByClosing()) + result.HttpResponse = resp + + return +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedcluster.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedcluster.go new file mode 100644 index 000000000000..d1f61f12e1a9 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedcluster.go @@ -0,0 +1,20 @@ +package connectedclusters + +import ( + "github.com/hashicorp/go-azure-helpers/resourcemanager/identity" + "github.com/hashicorp/go-azure-helpers/resourcemanager/systemdata" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedCluster struct { + Id *string `json:"id,omitempty"` + Identity identity.SystemAssigned `json:"identity"` + Location string `json:"location"` + Name *string `json:"name,omitempty"` + Properties ConnectedClusterProperties `json:"properties"` + SystemData *systemdata.SystemData `json:"systemData,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` + Type *string `json:"type,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterpatch.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterpatch.go new file mode 100644 index 000000000000..560b8bccc64f --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterpatch.go @@ -0,0 +1,9 @@ +package connectedclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterPatch struct { + Properties *interface{} `json:"properties,omitempty"` + Tags *map[string]string `json:"tags,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterproperties.go new file mode 100644 index 000000000000..eb7e5c945f1d --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_connectedclusterproperties.go @@ -0,0 +1,49 @@ +package connectedclusters + +import ( + "time" + + "github.com/hashicorp/go-azure-helpers/lang/dates" +) + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterProperties struct { + AgentPublicKeyCertificate string `json:"agentPublicKeyCertificate"` + AgentVersion *string `json:"agentVersion,omitempty"` + ConnectivityStatus *ConnectivityStatus `json:"connectivityStatus,omitempty"` + Distribution *string `json:"distribution,omitempty"` + Infrastructure *string `json:"infrastructure,omitempty"` + KubernetesVersion *string `json:"kubernetesVersion,omitempty"` + LastConnectivityTime *string `json:"lastConnectivityTime,omitempty"` + ManagedIdentityCertificateExpirationTime *string `json:"managedIdentityCertificateExpirationTime,omitempty"` + Offering *string `json:"offering,omitempty"` + ProvisioningState *ProvisioningState `json:"provisioningState,omitempty"` + TotalCoreCount *int64 `json:"totalCoreCount,omitempty"` + TotalNodeCount *int64 `json:"totalNodeCount,omitempty"` +} + +func (o *ConnectedClusterProperties) GetLastConnectivityTimeAsTime() (*time.Time, error) { + if o.LastConnectivityTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.LastConnectivityTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ConnectedClusterProperties) SetLastConnectivityTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.LastConnectivityTime = &formatted +} + +func (o *ConnectedClusterProperties) GetManagedIdentityCertificateExpirationTimeAsTime() (*time.Time, error) { + if o.ManagedIdentityCertificateExpirationTime == nil { + return nil, nil + } + return dates.ParseAsFormat(o.ManagedIdentityCertificateExpirationTime, "2006-01-02T15:04:05Z07:00") +} + +func (o *ConnectedClusterProperties) SetManagedIdentityCertificateExpirationTimeAsTime(input time.Time) { + formatted := input.Format("2006-01-02T15:04:05Z07:00") + o.ManagedIdentityCertificateExpirationTime = &formatted +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresult.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresult.go new file mode 100644 index 000000000000..dc74c9fd42e6 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresult.go @@ -0,0 +1,9 @@ +package connectedclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialResult struct { + Name *string `json:"name,omitempty"` + Value *string `json:"value,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresults.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresults.go new file mode 100644 index 000000000000..a64afb76a343 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_credentialresults.go @@ -0,0 +1,9 @@ +package connectedclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type CredentialResults struct { + HybridConnectionConfig *HybridConnectionConfig `json:"hybridConnectionConfig,omitempty"` + Kubeconfigs *[]CredentialResult `json:"kubeconfigs,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_hybridconnectionconfig.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_hybridconnectionconfig.go new file mode 100644 index 000000000000..2f2c102d61a2 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_hybridconnectionconfig.go @@ -0,0 +1,11 @@ +package connectedclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type HybridConnectionConfig struct { + ExpirationTime *int64 `json:"expirationTime,omitempty"` + HybridConnectionName *string `json:"hybridConnectionName,omitempty"` + Relay *string `json:"relay,omitempty"` + Token *string `json:"token,omitempty"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_listclusterusercredentialproperties.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_listclusterusercredentialproperties.go new file mode 100644 index 000000000000..e8e0c57aaab7 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/model_listclusterusercredentialproperties.go @@ -0,0 +1,9 @@ +package connectedclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ListClusterUserCredentialProperties struct { + AuthenticationMethod AuthenticationMethod `json:"authenticationMethod"` + ClientProxy bool `json:"clientProxy"` +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/predicates.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/predicates.go new file mode 100644 index 000000000000..004e1bd53cbd --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/predicates.go @@ -0,0 +1,32 @@ +package connectedclusters + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +type ConnectedClusterOperationPredicate struct { + Id *string + Location *string + Name *string + Type *string +} + +func (p ConnectedClusterOperationPredicate) Matches(input ConnectedCluster) bool { + + if p.Id != nil && (input.Id == nil && *p.Id != *input.Id) { + return false + } + + if p.Location != nil && *p.Location != input.Location { + return false + } + + if p.Name != nil && (input.Name == nil && *p.Name != *input.Name) { + return false + } + + if p.Type != nil && (input.Type == nil && *p.Type != *input.Type) { + return false + } + + return true +} diff --git a/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/version.go b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/version.go new file mode 100644 index 000000000000..078fe01f8f68 --- /dev/null +++ b/vendor/github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters/version.go @@ -0,0 +1,12 @@ +package connectedclusters + +import "fmt" + +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See NOTICE.txt in the project root for license information. + +const defaultApiVersion = "2021-10-01" + +func userAgent() string { + return fmt.Sprintf("hashicorp/go-azure-sdk/connectedclusters/%s", defaultApiVersion) +} diff --git a/vendor/modules.txt b/vendor/modules.txt index cfa1bac39fab..e5881d3a6cd8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -329,6 +329,7 @@ github.com/hashicorp/go-azure-sdk/resource-manager/healthbot/2020-12-08/healthbo github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2022-11-10/machineextensions github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2022-11-10/machines github.com/hashicorp/go-azure-sdk/resource-manager/hybridcompute/2022-11-10/privateendpointconnections +github.com/hashicorp/go-azure-sdk/resource-manager/hybridkubernetes/2021-10-01/connectedclusters github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettings github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-05-01-preview/diagnosticsettingscategories github.com/hashicorp/go-azure-sdk/resource-manager/insights/2021-08-01/scheduledqueryrules diff --git a/website/docs/r/arc_kubernetes_cluster.html.markdown b/website/docs/r/arc_kubernetes_cluster.html.markdown index db28ab3a9d96..1755799e5cd3 100644 --- a/website/docs/r/arc_kubernetes_cluster.html.markdown +++ b/website/docs/r/arc_kubernetes_cluster.html.markdown @@ -10,6 +10,8 @@ description: |- Manages an Arc Kubernetes Cluster. +-> **Note:** To connect an existing Kubernetes cluster to Azure Arc, besides creating an Arc Kubernetes Cluster in Azure, Azure Arc agents are also needed to deploy in the Kubernetes cluster. For more details refer to [Deploy agents to your cluster](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/conceptual-agent-overview#deploy-agents-to-your-cluster). + ## Example Usage ```hcl From 5de386fefd4660790ef4fba83f7e8ef8eb719534 Mon Sep 17 00:00:00 2001 From: Zhenhua Hu Date: Fri, 24 Mar 2023 15:04:29 +0800 Subject: [PATCH 09/11] resolve comments --- examples/arckubernetes/README.md | 24 ++ examples/arckubernetes/main.tf | 154 +++++++++++ .../arckubernetes/testdata/install_agent.py | 249 ++++++++++++++++++ .../testdata/install_agent.sh.tftpl | 38 +++ examples/arckubernetes/testdata/kind.yaml | 20 ++ examples/arckubernetes/variables.tf | 78 ++++++ 6 files changed, 563 insertions(+) create mode 100644 examples/arckubernetes/README.md create mode 100644 examples/arckubernetes/main.tf create mode 100644 examples/arckubernetes/testdata/install_agent.py create mode 100644 examples/arckubernetes/testdata/install_agent.sh.tftpl create mode 100644 examples/arckubernetes/testdata/kind.yaml create mode 100644 examples/arckubernetes/variables.tf diff --git a/examples/arckubernetes/README.md b/examples/arckubernetes/README.md new file mode 100644 index 000000000000..43d21a529b56 --- /dev/null +++ b/examples/arckubernetes/README.md @@ -0,0 +1,24 @@ +## Example: Azure Arc Kubernetes + +This example provisions the following Resources: + +## Creates + +1. A [Resource Group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +2. A [Virtual Network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) +3. A [Subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) +4. A [Linux Virtual Machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) +5. An [Arc Kubernetes Cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/arc_kubernetes_cluster) +6. A [Kind Cluster](https://kind.sigs.k8s.io/) in [Linux Virtual Machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) by [remote-exec Provisioner](https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec) +7. [Azure Arc agents](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/conceptual-agent-overview) in [Kind Cluster](https://kind.sigs.k8s.io/) by [remote-exec Provisioner](https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec) + +~> **NOTE:** To Connect an existing Kubernetes cluster to Azure Arc, the following conditions must be met: + +* An [Arc Kubernetes Cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/arc_kubernetes_cluster) must be created in Azure +* [Azure Arc agents](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/conceptual-agent-overview) must be installed in the Kubernetes cluster which is connected to Azure + +## Usage + +- Provide values to all variables +- Create with `terraform apply` +- Destroy all with `terraform destroy` diff --git a/examples/arckubernetes/main.tf b/examples/arckubernetes/main.tf new file mode 100644 index 000000000000..289fa1e7f36f --- /dev/null +++ b/examples/arckubernetes/main.tf @@ -0,0 +1,154 @@ +provider "azurerm" { + features { + resource_group { + prevent_deletion_if_contains_resources = false + } + } +} + +data "azurerm_subscription" "current" {} +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "example" { + name = "${var.prefix}-rg" + location = var.location +} + +resource "azurerm_virtual_network" "example" { + name = "${var.prefix}-vn" + address_space = ["10.0.0.0/16"] + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_subnet" "example" { + name = "${var.prefix}-subnet" + resource_group_name = azurerm_resource_group.example.name + virtual_network_name = azurerm_virtual_network.example.name + address_prefixes = ["10.0.2.0/24"] +} + +resource "azurerm_public_ip" "example" { + name = "${var.prefix}-pi" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + allocation_method = "Static" +} + +resource "azurerm_network_interface" "example" { + name = "${var.prefix}-ni" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + ip_configuration { + name = "internal" + subnet_id = azurerm_subnet.example.id + private_ip_address_allocation = "Dynamic" + public_ip_address_id = azurerm_public_ip.example.id + } +} + +resource "azurerm_network_security_group" "example" { + name = "${var.prefix}NetworkSecurityGroup" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + security_rule { + name = "SSH" + priority = 1001 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "22" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +resource "azurerm_network_interface_security_group_association" "example" { + network_interface_id = azurerm_network_interface.example.id + network_security_group_id = azurerm_network_security_group.example.id +} + +resource "azurerm_linux_virtual_machine" "example" { + name = "${var.prefix}-lvm" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + size = "Standard_F2" + admin_username = var.user_name + admin_password = var.password + provision_vm_agent = false + allow_extension_operations = false + disable_password_authentication = false + network_interface_ids = [ + azurerm_network_interface.example.id, + ] + os_disk { + caching = "ReadWrite" + storage_account_type = "Standard_LRS" + } + source_image_reference { + publisher = "Canonical" + offer = "UbuntuServer" + sku = "18.04-LTS" + version = "latest" + } +} + + +resource "azurerm_arc_kubernetes_cluster" "example" { + name = "${var.prefix}-akc" + resource_group_name = azurerm_resource_group.example.name + location = azurerm_resource_group.example.location + agent_public_key_certificate = var.public_key + identity { + type = "SystemAssigned" + } + + + connection { + type = "ssh" + host = azurerm_public_ip.example.ip_address + user = var.user_name + password = var.password + } + + provisioner "file" { + content = templatefile("testdata/install_agent.sh.tftpl", { + subscription_id = data.azurerm_subscription.current.subscription_id + resource_group_name = azurerm_resource_group.example.name + cluster_name = azurerm_arc_kubernetes_cluster.example.name + location = azurerm_resource_group.example.location + tenant_id = data.azurerm_client_config.current.tenant_id + working_dir = "/home/${var.user_name}" + }) + destination = "/home/${var.user_name}/install_agent.sh" + } + + provisioner "file" { + source = "testdata/install_agent.py" + destination = "/home/${var.user_name}/install_agent.py" + } + + provisioner "file" { + source = "testdata/kind.yaml" + destination = "/home/${var.user_name}/kind.yaml" + } + + provisioner "file" { + content = var.private_pem + destination = "/home/${var.user_name}/private.pem" + } + + provisioner "remote-exec" { + inline = [ + "sudo sed -i 's/\r$//' /home/${var.user_name}/install_agent.sh", + "sudo chmod +x /home/${var.user_name}/install_agent.sh", + "bash /home/${var.user_name}/install_agent.sh > /home/${var.user_name}/agent_log", + ] + } + + + depends_on = [ + azurerm_linux_virtual_machine.example + ] +} diff --git a/examples/arckubernetes/testdata/install_agent.py b/examples/arckubernetes/testdata/install_agent.py new file mode 100644 index 000000000000..90f1851333ee --- /dev/null +++ b/examples/arckubernetes/testdata/install_agent.py @@ -0,0 +1,249 @@ +import argparse +import json +import logging as logger +import os +import platform +import shutil +import stat +import subprocess +import time +import urllib +from subprocess import PIPE, Popen +from urllib import request + +HELM_VERSION = 'v3.6.3' +HELM_STORAGE_URL = "https://k8connecthelm.azureedge.net" +Pre_Onboarding_Helm_Charts_Folder_Name = 'PreOnboardingChecksCharts' + + +def get_helm_registry(config_dp_endpoint): + # Setting uri + get_chart_location_url = "{}/{}/GetLatestHelmPackagePath?api-version=2019-11-01-preview".format( + config_dp_endpoint, 'azure-arc-k8sagents') + + try: + response = urllib.request.urlopen( + request.Request(get_chart_location_url, method="POST")) + except Exception as e: + raise Exception("Failed to get helm registry." + str(e)) + + try: + return json.load(response).get('repositoryPath') + except Exception as e: + raise Exception( + "Error while fetching helm chart registry path from JSON response: " + str(e)) + + +def pull_helm_chart(registry_path, kube_config, kube_context, helm_client_location, chart_name='azure-arc-k8sagents', retry_count=5, retry_delay=3): + cmd_helm_chart_pull = [helm_client_location, + "chart", "pull", registry_path] + if kube_config: + cmd_helm_chart_pull.extend(["--kubeconfig", kube_config]) + if kube_context: + cmd_helm_chart_pull.extend(["--kube-context", kube_context]) + for i in range(retry_count): + response_helm_chart_pull = subprocess.Popen( + cmd_helm_chart_pull, stdout=PIPE, stderr=PIPE) + _, error_helm_chart_pull = response_helm_chart_pull.communicate() + if response_helm_chart_pull.returncode != 0: + if i == retry_count - 1: + raise Exception("Unable to pull {} helm chart from the registry '{}': ".format( + chart_name, registry_path) + error_helm_chart_pull.decode("ascii")) + time.sleep(retry_delay) + else: + break + + +def export_helm_chart(registry_path, chart_export_path, kube_config, kube_context, helm_client_location, chart_name='azure-arc-k8sagents'): + cmd_helm_chart_export = [helm_client_location, "chart", + "export", registry_path, "--destination", chart_export_path] + if kube_config: + cmd_helm_chart_export.extend(["--kubeconfig", kube_config]) + if kube_context: + cmd_helm_chart_export.extend(["--kube-context", kube_context]) + response_helm_chart_export = subprocess.Popen( + cmd_helm_chart_export, stdout=PIPE, stderr=PIPE) + _, error_helm_chart_export = response_helm_chart_export.communicate() + if response_helm_chart_export.returncode != 0: + raise Exception("Unable to export {} helm chart from the registry '{}': ".format( + chart_name, registry_path) + error_helm_chart_export.decode("ascii")) + + +def get_chart_path(registry_path, kube_config, kube_context, helm_client_location, chart_folder_name='AzureArcCharts', chart_name='azure-arc-k8sagents'): + # Pulling helm chart from registry + os.environ['HELM_EXPERIMENTAL_OCI'] = '1' + pull_helm_chart(registry_path, kube_config, kube_context, + helm_client_location, chart_name) + + # Exporting helm chart after cleanup + chart_export_path = os.path.join( + os.path.expanduser('~'), '.azure', chart_folder_name) + try: + if os.path.isdir(chart_export_path): + shutil.rmtree(chart_export_path) + except: + logger.warning("Unable to cleanup the {} already present on the machine. In case of failure, please cleanup the directory '{}' and try again.".format( + chart_folder_name, chart_export_path)) + + export_helm_chart(registry_path, chart_export_path, kube_config, + kube_context, helm_client_location, chart_name) + + # Returning helm chart path + helm_chart_path = os.path.join(chart_export_path, chart_name) + if chart_folder_name == Pre_Onboarding_Helm_Charts_Folder_Name: + chart_path = helm_chart_path + else: + chart_path = os.getenv('HELMCHART') if os.getenv( + 'HELMCHART') else helm_chart_path + + return chart_path + + +def install_helm_client(): + # Fetch system related info + operating_system = platform.system().lower() + platform.machine() + + # Set helm binary download & install locations + if (operating_system == 'windows'): + download_location_string = f'.azure\\helm\\{HELM_VERSION}\\helm-{HELM_VERSION}-{operating_system}-amd64.zip' + install_location_string = f'.azure\\helm\\{HELM_VERSION}\\{operating_system}-amd64\\helm.exe' + requestUri = f'{HELM_STORAGE_URL}/helm/helm-{HELM_VERSION}-{operating_system}-amd64.zip' + elif (operating_system == 'linux' or operating_system == 'darwin'): + download_location_string = f'.azure/helm/{HELM_VERSION}/helm-{HELM_VERSION}-{operating_system}-amd64.tar.gz' + install_location_string = f'.azure/helm/{HELM_VERSION}/{operating_system}-amd64/helm' + requestUri = f'{HELM_STORAGE_URL}/helm/helm-{HELM_VERSION}-{operating_system}-amd64.tar.gz' + else: + raise Exception( + f'The {operating_system} platform is not currently supported for installing helm client.') + + download_location = os.path.expanduser( + os.path.join('~', download_location_string)) + download_dir = os.path.dirname(download_location) + install_location = os.path.expanduser( + os.path.join('~', install_location_string)) + + # Download compressed halm binary if not already present + if not os.path.isfile(download_location): + # Creating the helm folder if it doesnt exist + if not os.path.exists(download_dir): + try: + os.makedirs(download_dir) + except Exception as e: + raise Exception("Failed to create helm directory." + str(e)) + + # Downloading compressed helm client executable + logger.warning( + "Downloading helm client for first time. This can take few minutes...") + try: + response = urllib.request.urlopen(requestUri) + except Exception as e: + raise Exception("Failed to download helm client." + str(e)) + + responseContent = response.read() + response.close() + + # Creating the compressed helm binaries + try: + with open(download_location, 'wb') as f: + f.write(responseContent) + except Exception as e: + raise Exception("Failed to create helm executable." + str(e)) + + # Extract compressed helm binary + if not os.path.isfile(install_location): + try: + shutil.unpack_archive(download_location, download_dir) + os.chmod(install_location, os.stat( + install_location).st_mode | stat.S_IXUSR) + except Exception as e: + raise Exception("Failed to extract helm executable." + str(e)) + + return install_location + + +def helm_install_release(chart_path, subscription_id, kubernetes_distro, kubernetes_infra, resource_group_name, cluster_name, + location, onboarding_tenant_id, private_key_pem, + no_wait, cloud_name, helm_client_location, onboarding_timeout="600"): + cmd_helm_install = [helm_client_location, "upgrade", "--install", "azure-arc", chart_path, + "--set", "global.subscriptionId={}".format( + subscription_id), + "--set", "global.kubernetesDistro={}".format( + kubernetes_distro), + "--set", "global.kubernetesInfra={}".format( + kubernetes_infra), + "--set", "global.resourceGroupName={}".format( + resource_group_name), + "--set", "global.resourceName={}".format(cluster_name), + "--set", "global.location={}".format(location), + "--set", "global.tenantId={}".format( + onboarding_tenant_id), + "--set", "global.onboardingPrivateKey={}".format( + private_key_pem), + "--set", "systemDefaultValues.spnOnboarding=false", + "--set", "global.azureEnvironment={}".format( + cloud_name), + "--set", "systemDefaultValues.clusterconnect-agent.enabled=true", + "--namespace", "{}".format("azure-arc-release"), + "--create-namespace", + "--output", "json"] + + if not no_wait: + # Change --timeout format for helm client to understand + onboarding_timeout = onboarding_timeout + "s" + cmd_helm_install.extend( + ["--wait", "--timeout", "{}".format(onboarding_timeout)]) + response_helm_install = Popen(cmd_helm_install, stdout=PIPE, stderr=PIPE) + _, error_helm_install = response_helm_install.communicate() + if response_helm_install.returncode != 0: + raise Exception("Unable to install helm release" + error_helm_install.decode("ascii")) + + +def install_agent(): + parser = argparse.ArgumentParser( + description='Install Connected Cluster Agent') + parser.add_argument('--subscriptionId', type=str, required=True) + parser.add_argument('--resourceGroupName', type=str, required=True) + parser.add_argument('--clusterName', type=str, required=True) + parser.add_argument('--location', type=str, required=True) + parser.add_argument('--tenantId', type=str, required=True) + parser.add_argument('--privatePem', type=str, required=True) + + try: + args = parser.parse_args() + except Exception as e: + raise Exception("Failed to parse arguments." + str(e)) + + try: + with open(args.privatePem, "r") as f: + privateKey = f.read() + except Exception as e: + raise Exception("Failed to get private key." + str(e)) + + # Install helm client + helm_client_location = install_helm_client() + + # Retrieving Helm chart OCI Artifact location + registry_path = get_helm_registry("https://westeurope.dp.kubernetesconfiguration.azure.com") + + # Get helm chart path + chart_path = get_chart_path( + registry_path, None, None, helm_client_location) + + helm_install_release(chart_path, + args.subscriptionId, + "generic", + "generic", + args.resourceGroupName, + args.clusterName, + args.location, + args.tenantId, + privateKey, + # private_key_pem2, + False, + "AZUREPUBLICCLOUD", + helm_client_location) + + +if __name__ == "__main__": + install_agent() diff --git a/examples/arckubernetes/testdata/install_agent.sh.tftpl b/examples/arckubernetes/testdata/install_agent.sh.tftpl new file mode 100644 index 000000000000..9bb2cbcbd0bf --- /dev/null +++ b/examples/arckubernetes/testdata/install_agent.sh.tftpl @@ -0,0 +1,38 @@ +#!/bin/bash + +# install docker +sudo apt-get update +sudo apt-get -y install ca-certificates curl gnupg lsb-release +sudo mkdir -m 0755 -p /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg +echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null +sudo chmod a+r /etc/apt/keyrings/docker.gpg +sudo apt-get update +sudo apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +#Manage Docker as a non-root user +sudo groupadd docker || true +sudo usermod -aG docker $USER +newgrp docker << END + +#install golang and kind +sudo snap install go --classic +sudo go install sigs.k8s.io/kind@latest + +#create a new cluster +export PATH="$HOME/go/bin:$PATH" +export KUBECONFIG="${working_dir}/kind-config" +kind create cluster --name arc-kind --config kind.yaml --kubeconfig kind-config + +#install agent +python3 "${working_dir}/install_agent.py" \ +--subscriptionId "${subscription_id}" \ +--resourceGroupName "${resource_group_name}" \ +--clusterName "${cluster_name}" \ +--location "${location}" \ +--tenantId "${tenant_id}" \ +--privatePem "${working_dir}/private.pem" + +END \ No newline at end of file diff --git a/examples/arckubernetes/testdata/kind.yaml b/examples/arckubernetes/testdata/kind.yaml new file mode 100644 index 000000000000..fe336a44025d --- /dev/null +++ b/examples/arckubernetes/testdata/kind.yaml @@ -0,0 +1,20 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane + kubeadmConfigPatches: + - | + kind: InitConfiguration + nodeRegistration: + kubeletExtraArgs: + node-labels: "ingress-ready=true" + # port forward 80 on the host to 80 on this node + extraPortMappings: + - containerPort: 81 + hostPort: 81 + listenAddress: "127.0.0.1" + protocol: TCP + - containerPort: 443 + hostPort: 443 + listenAddress: "127.0.0.1" + protocol: TCP diff --git a/examples/arckubernetes/variables.tf b/examples/arckubernetes/variables.tf new file mode 100644 index 000000000000..b4e2e9888cf4 --- /dev/null +++ b/examples/arckubernetes/variables.tf @@ -0,0 +1,78 @@ +variable "prefix" { + description = "The prefix used for all resources in this example" +} + +variable "location" { + description = "The Azure location where all resources in this example should be created" +} + +variable "user_name" { + description = "The user name of virtual machine" +} + +variable "password" { + description = "The password of virtual machine" + sensitive = true +} + +variable "private_pem" { + description = "The private certificate used by the agent" + default = < Date: Wed, 5 Apr 2023 19:07:09 +0800 Subject: [PATCH 10/11] resolve comments --- examples/arckubernetes/README.md | 2 +- .../arckubernetes/testdata/install_agent.py | 1 - examples/arckubernetes/variables.tf | 56 +------------------ .../arc_kubernetes_cluster_resource.go | 30 +++++----- .../arckubernetes/testdata/install_agent.py | 1 - .../r/arc_kubernetes_cluster.html.markdown | 2 + 6 files changed, 19 insertions(+), 73 deletions(-) diff --git a/examples/arckubernetes/README.md b/examples/arckubernetes/README.md index 43d21a529b56..17b079fcb2d9 100644 --- a/examples/arckubernetes/README.md +++ b/examples/arckubernetes/README.md @@ -12,7 +12,7 @@ This example provisions the following Resources: 6. A [Kind Cluster](https://kind.sigs.k8s.io/) in [Linux Virtual Machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) by [remote-exec Provisioner](https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec) 7. [Azure Arc agents](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/conceptual-agent-overview) in [Kind Cluster](https://kind.sigs.k8s.io/) by [remote-exec Provisioner](https://developer.hashicorp.com/terraform/language/resources/provisioners/remote-exec) -~> **NOTE:** To Connect an existing Kubernetes cluster to Azure Arc, the following conditions must be met: +~> **NOTE:** To connect an existing Kubernetes cluster to Azure Arc, the following conditions must be met: * An [Arc Kubernetes Cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/arc_kubernetes_cluster) must be created in Azure * [Azure Arc agents](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/conceptual-agent-overview) must be installed in the Kubernetes cluster which is connected to Azure diff --git a/examples/arckubernetes/testdata/install_agent.py b/examples/arckubernetes/testdata/install_agent.py index 90f1851333ee..c4623d8b2e25 100644 --- a/examples/arckubernetes/testdata/install_agent.py +++ b/examples/arckubernetes/testdata/install_agent.py @@ -239,7 +239,6 @@ def install_agent(): args.location, args.tenantId, privateKey, - # private_key_pem2, False, "AZUREPUBLICCLOUD", helm_client_location) diff --git a/examples/arckubernetes/variables.tf b/examples/arckubernetes/variables.tf index b4e2e9888cf4..908fb80ad802 100644 --- a/examples/arckubernetes/variables.tf +++ b/examples/arckubernetes/variables.tf @@ -15,64 +15,12 @@ variable "password" { sensitive = true } +# Refer to https://github.com/Azure/azure-cli-extensions/blob/ed3f463e9ef7980eff196504a8bb29800c123eba/src/connectedk8s/azext_connectedk8s/custom.py#L365 to generate the private key variable "private_pem" { description = "The private certificate used by the agent" - default = < **Note:** An extensive example on connecting the `azurerm_arc_kubernetes_cluster` to an external kubernetes cluster can be found in [the `./examples/arckubernetes` directory within the GitHub Repository](https://github.com/hashicorp/terraform-provider-azurerm/tree/main/examples/arckubernetes). + ## Arguments Reference The following arguments are supported: From 40f8d9868e1bc11accb434581cd260cbb8fc8cd6 Mon Sep 17 00:00:00 2001 From: Steph Date: Thu, 6 Apr 2023 13:24:19 +0200 Subject: [PATCH 11/11] tweak arc kubernetes note on docs --- website/docs/r/arc_kubernetes_cluster.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/arc_kubernetes_cluster.html.markdown b/website/docs/r/arc_kubernetes_cluster.html.markdown index 3b37a8219ae3..c426dd146f6e 100644 --- a/website/docs/r/arc_kubernetes_cluster.html.markdown +++ b/website/docs/r/arc_kubernetes_cluster.html.markdown @@ -10,7 +10,7 @@ description: |- Manages an Arc Kubernetes Cluster. --> **Note:** To connect an existing Kubernetes cluster to Azure Arc, besides creating an Arc Kubernetes Cluster in Azure, Azure Arc agents are also needed to deploy in the Kubernetes cluster. For more details refer to [Deploy agents to your cluster](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/conceptual-agent-overview#deploy-agents-to-your-cluster). +-> **Note:** Installing and configuring the Azure Arc Agent on your Kubernetes Cluster to establish connectivity is outside the scope of this document. For more details refer to [Deploy agents to your cluster](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/conceptual-agent-overview#deploy-agents-to-your-cluster) and [Connect an existing Kubernetes Cluster](https://learn.microsoft.com/en-us/azure/azure-arc/kubernetes/quickstart-connect-cluster?tabs=azure-cli#connect-an-existing-kubernetes-cluster). If you encounter issues connecting your Kubernetes Cluster to Azure Arc, we'd recommend opening a ticket with Microsoft Support. ## Example Usage