Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Data Source - azurerm_kubernetes_fleet_manager #28278

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/labeler-issue-triage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,4 @@ service/vmware:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(vmware_cluster\W+|vmware_express_route_authorization\W+|vmware_netapp_volume_attachment\W+|vmware_private_cloud\W+|voice_services_communications_gateway\W+|voice_services_communications_gateway_test_line\W+)((.|\n)*)###'

service/workloads:
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(chaos_studio_|container_connected_registry\W+|container_registry_cache_rule\W+|container_registry_cache_rule\W+|container_registry_task\W+|container_registry_task_schedule_run_now\W+|container_registry_token_password\W+|kubernetes_cluster_extension\W+|kubernetes_cluster_trusted_access_role_binding\W+|kubernetes_fleet_manager\W+|kubernetes_fleet_member\W+|kubernetes_fleet_update_run\W+|kubernetes_fleet_update_strategy\W+|kubernetes_flux_configuration\W+|kubernetes_node_pool_snapshot\W+|workloads_sap_)((.|\n)*)###'
- '### (|New or )Affected Resource\(s\)\/Data Source\(s\)((.|\n)*)azurerm_(chaos_studio_|container_connected_registry\W+|container_registry_cache_rule\W+|container_registry_cache_rule\W+|container_registry_task\W+|container_registry_task_schedule_run_now\W+|container_registry_token_password\W+|kubernetes_cluster_extension\W+|kubernetes_cluster_trusted_access_role_binding\W+|kubernetes_fleet_manager\W+|kubernetes_fleet_manager\W+|kubernetes_fleet_member\W+|kubernetes_fleet_update_run\W+|kubernetes_fleet_update_strategy\W+|kubernetes_flux_configuration\W+|kubernetes_node_pool_snapshot\W+|workloads_sap_)((.|\n)*)###'
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package containers

import (
"context"
"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/location"
"github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2024-04-01/fleets"
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
)

var _ sdk.DataSource = KubernetesFleetManagerDataSource{}

type KubernetesFleetManagerDataSource struct{}

type KubernetesFleetManagerDataSourceModel struct {
Location string `tfschema:"location"`
Name string `tfschema:"name"`
ResourceGroupName string `tfschema:"resource_group_name"`
Tags map[string]interface{} `tfschema:"tags"`
}

func (KubernetesFleetManagerDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"name": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringIsNotEmpty,
},
"resource_group_name": commonschema.ResourceGroupNameForDataSource(),
}
}

func (KubernetesFleetManagerDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"location": commonschema.LocationComputed(),
"tags": commonschema.TagsDataSource(),
}
}

func (KubernetesFleetManagerDataSource) ModelObject() interface{} {
return &KubernetesFleetManagerDataSourceModel{}
}

func (KubernetesFleetManagerDataSource) ResourceType() string {
return "azurerm_kubernetes_fleet_manager"
}

func (KubernetesFleetManagerDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.ContainerService.V20231015.Fleets
subscriptionId := metadata.Client.Account.SubscriptionId

var state KubernetesFleetManagerDataSourceModel
if err := metadata.Decode(&state); err != nil {
return fmt.Errorf("decoding: %+v", err)
}

id := fleets.NewFleetID(subscriptionId, state.ResourceGroupName, state.Name)

resp, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return fmt.Errorf("%s was not found", id)
}

return fmt.Errorf("retrieving %s: %+v", id, err)
}

metadata.SetID(id)

if model := resp.Model; model != nil {
state.Location = location.Normalize(model.Location)
state.Tags = tags.Flatten(model.Tags)
}

return metadata.Encode(&state)
},
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package containers_test

import (
"fmt"
"testing"

"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance"
"github.com/hashicorp/terraform-provider-azurerm/internal/acceptance/check"
)

type KubernetesFleetManagerDataSource struct{}

func TestAccKubernetesFleetManagerDataSource_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "data.azurerm_kubernetes_fleet_manager", "test")
d := KubernetesFleetManagerDataSource{}

data.DataSourceTest(t, []acceptance.TestStep{
{
Config: d.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).Key("location").HasValue(location.Normalize(data.Locations.Primary)),
check.That(data.ResourceName).Key("tags.%").HasValue("2"),
check.That(data.ResourceName).Key("tags.environment").HasValue("terraform-acctests"),
check.That(data.ResourceName).Key("tags.some_key").HasValue("some-value"),
),
},
})
}

func (KubernetesFleetManagerDataSource) basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "test" {
location = "%s"
name = "acctestrg-%d"
}

resource "azurerm_kubernetes_fleet_manager" "test" {
location = azurerm_resource_group.test.location
name = "acctestkfm-%s"
resource_group_name = azurerm_resource_group.test.name
tags = {
environment = "terraform-acctests"
some_key = "some-value"
}
}

data "azurerm_kubernetes_fleet_manager" "test" {
name = azurerm_kubernetes_fleet_manager.test.name
resource_group_name = azurerm_kubernetes_fleet_manager.test.resource_group_name
}
`, data.Locations.Primary, data.RandomInteger, data.RandomString)
}
sreallymatt marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 4 additions & 3 deletions internal/services/containers/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,26 @@ func (r Registration) SupportedResources() map[string]*pluginsdk.Resource {

func (r Registration) DataSources() []sdk.DataSource {
dataSources := []sdk.DataSource{
KubernetesNodePoolSnapshotDataSource{},
ContainerRegistryCacheRuleDataSource{},
KubernetesFleetManagerDataSource{},
KubernetesNodePoolSnapshotDataSource{},
}
dataSources = append(dataSources, r.autoRegistration.DataSources()...)
return dataSources
}

func (r Registration) Resources() []sdk.Resource {
resources := []sdk.Resource{
ContainerConnectedRegistryResource{},
ContainerRegistryCacheRule{},
ContainerRegistryTaskResource{},
ContainerRegistryTaskScheduleResource{},
ContainerRegistryTokenPasswordResource{},
ContainerConnectedRegistryResource{},
KubernetesClusterExtensionResource{},
KubernetesFluxConfigurationResource{},
KubernetesFleetManagerResource{},
KubernetesFleetUpdateRunResource{},
KubernetesFleetUpdateStrategyResource{},
KubernetesFluxConfigurationResource{},
}
resources = append(resources, r.autoRegistration.Resources()...)
return resources
Expand Down
48 changes: 48 additions & 0 deletions website/docs/d/kubernetes_fleet_manager.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
subcategory: "Container"
layout: "azurerm"
page_title: "Azure Resource Manager: Data Source: azurerm_kubernetes_fleet_manager"
description: |-
Gets information about an existing Kubernetes Fleet Manager.
---

# Data Source: azurerm_kubernetes_fleet_manager

Use this data source to access information about an existing Kubernetes Fleet Manager.

## Example Usage

```hcl
data "azurerm_kubernetes_fleet_manager" "example" {
name = "example"
resource_group_name = "example-resource-group"
}
output "id" {
value = data.azurerm_kubernetes_fleet_manager.example.id
}
```

## Arguments Reference

The following arguments are supported:

* `name` - (Required) The name of this Kubernetes Fleet Manager.

* `resource_group_name` - (Required) The name of the Resource Group where the Kubernetes Fleet Manager exists.

## Attributes Reference

In addition to the Arguments listed above - the following Attributes are exported:

* `id` - The ID of the Kubernetes Fleet Manager.

* `location` - The Azure Region where the Kubernetes Fleet Manager exists.

* `tags` - A mapping of tags assigned to the Kubernetes Fleet Manager.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Kubernetes Fleet Manager.
Loading