-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New Data Source -
azurerm_kubernetes_fleet_manager
(#28278)
* Add kubernetes_fleet_manager datasource * fix formatting * Update internal/services/containers/kubernetes_fleet_manager_data_source_test.go Co-authored-by: stephybun <[email protected]> --------- Co-authored-by: stephybun <[email protected]>
- Loading branch information
1 parent
14f86b4
commit 8649171
Showing
5 changed files
with
181 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
internal/services/containers/kubernetes_fleet_manager_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}, | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
internal/services/containers/kubernetes_fleet_manager_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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(` | ||
%s | ||
data "azurerm_kubernetes_fleet_manager" "test" { | ||
name = azurerm_kubernetes_fleet_manager.test.name | ||
resource_group_name = azurerm_kubernetes_fleet_manager.test.resource_group_name | ||
} | ||
`, KubernetesFleetManagerTestResource{}.complete(data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |