-
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.
azurerm_kubernetes_cluster_node_pool
- support for the `source_snap…
…shot_id` property (#21511) * `azurerm_kubernetes_cluster_node_pool` - `source_snapshot_id` * update * update
- Loading branch information
Showing
25 changed files
with
1,583 additions
and
0 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
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
108 changes: 108 additions & 0 deletions
108
internal/services/containers/kubernetes_snapshot_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,108 @@ | ||
package containers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"github.com/hashicorp/go-azure-helpers/lang/response" | ||
"github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/agentpools" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2023-02-02-preview/snapshots" | ||
"github.com/hashicorp/terraform-provider-azurerm/internal/sdk" | ||
"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" | ||
) | ||
|
||
type KubernetesSnapshotDataSourceModel struct { | ||
Name string `tfschema:"name"` | ||
ResourceGroup string `tfschema:"resource_group_name"` | ||
SourceResourceId string `tfschema:"source_resource_id"` | ||
Tags map[string]string `tfschema:"tags"` | ||
} | ||
|
||
type KubernetesSnapshotDataSource struct{} | ||
|
||
var _ sdk.DataSource = KubernetesSnapshotDataSource{} | ||
|
||
func (r KubernetesSnapshotDataSource) ResourceType() string { | ||
return "azurerm_kubernetes_snapshot" | ||
} | ||
|
||
func (r KubernetesSnapshotDataSource) ModelObject() interface{} { | ||
return &KubernetesSnapshotDataSourceModel{} | ||
} | ||
|
||
func (r KubernetesSnapshotDataSource) IDValidationFunc() pluginsdk.SchemaValidateFunc { | ||
return snapshots.ValidateSnapshotID | ||
} | ||
|
||
func (r KubernetesSnapshotDataSource) 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 (r KubernetesSnapshotDataSource) Attributes() map[string]*pluginsdk.Schema { | ||
return map[string]*pluginsdk.Schema{ | ||
"source_resource_id": { | ||
Type: pluginsdk.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"tags": tags.SchemaDataSource(), | ||
} | ||
} | ||
|
||
func (r KubernetesSnapshotDataSource) Read() sdk.ResourceFunc { | ||
return sdk.ResourceFunc{ | ||
Timeout: 5 * time.Minute, | ||
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error { | ||
client := metadata.Client.Containers.SnapshotClient | ||
subscriptionId := metadata.Client.Account.SubscriptionId | ||
|
||
var state KubernetesSnapshotDataSourceModel | ||
if err := metadata.Decode(&state); err != nil { | ||
return fmt.Errorf("decoding: %+v", err) | ||
} | ||
|
||
id := snapshots.NewSnapshotID(subscriptionId, state.ResourceGroup, 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) | ||
} | ||
|
||
state.Name = id.SnapshotName | ||
|
||
if model := resp.Model; model != nil { | ||
state.Tags = pointer.From(model.Tags) | ||
|
||
if props := model.Properties; props != nil { | ||
if props.CreationData != nil && props.CreationData.SourceResourceId != nil { | ||
nodePoolId, err := agentpools.ParseAgentPoolIDInsensitively(*props.CreationData.SourceResourceId) | ||
if err != nil { | ||
return err | ||
} | ||
state.SourceResourceId = nodePoolId.ID() | ||
} | ||
} | ||
} | ||
|
||
metadata.SetID(id) | ||
|
||
return metadata.Encode(&state) | ||
}, | ||
} | ||
} |
Oops, something went wrong.