11package containers
22
3- // NOTE: this file is generated - manual changes will be overwritten.
4- // Copyright (c) Microsoft Corporation. All rights reserved.
5- // Licensed under the MIT License. See NOTICE.txt in the project root for license information.
63import (
74 "context"
85 "fmt"
6+ "regexp"
97 "time"
108
9+ "github.com/hashicorp/go-azure-helpers/lang/pointer"
1110 "github.com/hashicorp/go-azure-helpers/lang/response"
1211 "github.com/hashicorp/go-azure-helpers/resourcemanager/commonschema"
1312 "github.com/hashicorp/go-azure-helpers/resourcemanager/location"
14- "github.com/hashicorp/go-azure-helpers/resourcemanager/tags"
1513 "github.com/hashicorp/go-azure-sdk/resource-manager/containerservice/2024-04-01/fleets"
1614 "github.com/hashicorp/terraform-provider-azurerm/internal/sdk"
1715 "github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
16+ "github.com/hashicorp/terraform-provider-azurerm/internal/tf/validation"
1817)
1918
20- var (
21- _ sdk.Resource = KubernetesFleetManagerResource {}
22- _ sdk.ResourceWithUpdate = KubernetesFleetManagerResource {}
23- )
19+ type KubernetesFleetManagerModel struct {
20+ Name string `tfschema:"name"`
21+ ResourceGroupName string `tfschema:"resource_group_name"`
22+ Location string `tfschema:"location"`
23+ HubProfile []FleetHubProfileModel `tfschema:"hub_profile"`
24+ Tags map [string ]string `tfschema:"tags"`
25+ }
26+
27+ type FleetHubProfileModel struct {
28+ DnsPrefix string `tfschema:"dns_prefix"`
29+ Fqdn string `tfschema:"fqdn"`
30+ KubernetesVersion string `tfschema:"kubernetes_version"`
31+ PortalFqdn string `tfschema:"portal_fqdn"`
32+ }
2433
2534type KubernetesFleetManagerResource struct {}
2635
27- func (r KubernetesFleetManagerResource ) ModelObject () interface {} {
28- return & KubernetesFleetManagerResourceSchema {}
36+ var _ sdk.ResourceWithUpdate = KubernetesFleetManagerResource {}
37+
38+ func (r KubernetesFleetManagerResource ) ResourceType () string {
39+ return "azurerm_kubernetes_fleet_manager"
2940}
3041
31- type KubernetesFleetManagerResourceSchema struct {
32- Location string `tfschema:"location"`
33- Name string `tfschema:"name"`
34- ResourceGroupName string `tfschema:"resource_group_name"`
35- Tags map [string ]interface {} `tfschema:"tags"`
42+ func (r KubernetesFleetManagerResource ) ModelObject () interface {} {
43+ return & KubernetesFleetManagerModel {}
3644}
3745
3846func (r KubernetesFleetManagerResource ) IDValidationFunc () pluginsdk.SchemaValidateFunc {
3947 return fleets .ValidateFleetID
4048}
4149
42- func (r KubernetesFleetManagerResource ) ResourceType () string {
43- return "azurerm_kubernetes_fleet_manager"
44- }
45-
4650func (r KubernetesFleetManagerResource ) Arguments () map [string ]* pluginsdk.Schema {
4751 return map [string ]* pluginsdk.Schema {
48- "location" : commonschema .Location (),
4952 "name" : {
50- ForceNew : true ,
51- Required : true ,
52- Type : pluginsdk .TypeString ,
53+ Type : pluginsdk .TypeString ,
54+ Required : true ,
55+ ForceNew : true ,
56+ ValidateFunc : validation .StringIsNotEmpty ,
5357 },
58+
5459 "resource_group_name" : commonschema .ResourceGroupName (),
60+
61+ "location" : commonschema .Location (),
62+
5563 "hub_profile" : {
56- Deprecated : "The service team has indicated this field is now deprecated and not to be used, as such we are marking it as such and no longer sending it to the API, please see url: https://learn.microsoft.com/en-us/azure/kubernetes-fleet/architectural-overview" ,
64+ Type : pluginsdk .TypeList ,
65+ Optional : true ,
66+ ForceNew : true ,
67+ MaxItems : 1 ,
5768 Elem : & pluginsdk.Resource {
5869 Schema : map [string ]* pluginsdk.Schema {
5970 "dns_prefix" : {
60- Required : true ,
6171 Type : pluginsdk .TypeString ,
72+ Optional : true ,
73+ ForceNew : true ,
74+ ValidateFunc : validation .All (
75+ validation .StringLenBetween (1 , 54 ),
76+ validation .StringMatch (regexp .MustCompile (`^[a-zA-Z0-9]$|^[a-zA-Z0-9][a-zA-Z0-9-]{0,52}[a-zA-Z0-9]$` ), "must match the pattern ^[a-zA-Z0-9]$|^[a-zA-Z0-9][a-zA-Z0-9-]{0,52}[a-zA-Z0-9]$" ),
77+ ),
6278 },
79+
6380 "fqdn" : {
64- Computed : true ,
6581 Type : pluginsdk .TypeString ,
82+ Computed : true ,
6683 },
84+
6785 "kubernetes_version" : {
86+ Type : pluginsdk .TypeString ,
6887 Computed : true ,
88+ },
89+
90+ "portal_fqdn" : {
6991 Type : pluginsdk .TypeString ,
92+ Computed : true ,
7093 },
7194 },
7295 },
73- ForceNew : true ,
74- MaxItems : 1 ,
75- Optional : true ,
76- Type : pluginsdk .TypeList ,
7796 },
97+
7898 "tags" : commonschema .Tags (),
7999 }
80100}
@@ -88,30 +108,33 @@ func (r KubernetesFleetManagerResource) Create() sdk.ResourceFunc {
88108 Timeout : 30 * time .Minute ,
89109 Func : func (ctx context.Context , metadata sdk.ResourceMetaData ) error {
90110 client := metadata .Client .ContainerService .V20240401 .Fleets
111+ subscriptionId := metadata .Client .Account .SubscriptionId
91112
92- var config KubernetesFleetManagerResourceSchema
93- if err := metadata .Decode (& config ); err != nil {
113+ var model KubernetesFleetManagerModel
114+ if err := metadata .Decode (& model ); err != nil {
94115 return fmt .Errorf ("decoding: %+v" , err )
95116 }
96117
97- subscriptionId := metadata .Client .Account .SubscriptionId
98-
99- id := fleets .NewFleetID (subscriptionId , config .ResourceGroupName , config .Name )
118+ id := fleets .NewFleetID (subscriptionId , model .ResourceGroupName , model .Name )
100119
101120 existing , err := client .Get (ctx , id )
102- if err != nil {
103- if ! response .WasNotFound (existing .HttpResponse ) {
104- return fmt .Errorf ("checking for the presence of an existing %s: %+v" , id , err )
105- }
121+ if err != nil && ! response .WasNotFound (existing .HttpResponse ) {
122+ return fmt .Errorf ("checking for presence of existing %s: %+v" , id , err )
106123 }
124+
107125 if ! response .WasNotFound (existing .HttpResponse ) {
108126 return metadata .ResourceRequiresImport (r .ResourceType (), id )
109127 }
110128
111- var payload fleets.Fleet
112- r .mapKubernetesFleetManagerResourceSchemaToFleet (config , & payload )
129+ params := fleets.Fleet {
130+ Location : location .Normalize (model .Location ),
131+ Tags : pointer .To (model .Tags ),
132+ Properties : & fleets.FleetProperties {
133+ HubProfile : expandFleetHubProfileModel (model .HubProfile ),
134+ },
135+ }
113136
114- if err := client .CreateOrUpdateThenPoll (ctx , id , payload , fleets .DefaultCreateOrUpdateOperationOptions ()); err != nil {
137+ if err := client .CreateOrUpdateThenPoll (ctx , id , params , fleets .DefaultCreateOrUpdateOperationOptions ()); err != nil {
115138 return fmt .Errorf ("creating %s: %+v" , id , err )
116139 }
117140
@@ -121,40 +144,47 @@ func (r KubernetesFleetManagerResource) Create() sdk.ResourceFunc {
121144 }
122145}
123146
124- func (r KubernetesFleetManagerResource ) Read () sdk.ResourceFunc {
147+ func (r KubernetesFleetManagerResource ) Update () sdk.ResourceFunc {
125148 return sdk.ResourceFunc {
126- Timeout : 5 * time .Minute ,
149+ Timeout : 30 * time .Minute ,
127150 Func : func (ctx context.Context , metadata sdk.ResourceMetaData ) error {
128151 client := metadata .Client .ContainerService .V20240401 .Fleets
129- schema := KubernetesFleetManagerResourceSchema {}
130152
131153 id , err := fleets .ParseFleetID (metadata .ResourceData .Id ())
132154 if err != nil {
133155 return err
134156 }
135157
158+ var model KubernetesFleetManagerModel
159+ if err := metadata .Decode (& model ); err != nil {
160+ return fmt .Errorf ("decoding: %+v" , err )
161+ }
162+
136163 resp , err := client .Get (ctx , * id )
137164 if err != nil {
138- if response .WasNotFound (resp .HttpResponse ) {
139- return metadata .MarkAsGone (* id )
140- }
141165 return fmt .Errorf ("retrieving %s: %+v" , * id , err )
142166 }
143167
144- if model := resp .Model ; model != nil {
145- schema .Name = id .FleetName
146- schema .ResourceGroupName = id .ResourceGroupName
147- r .mapFleetToKubernetesFleetManagerResourceSchema (* model , & schema )
168+ if resp .Model == nil {
169+ return fmt .Errorf ("retrieving %s: `model` was nil" , * id )
170+ }
171+
172+ payload := resp .Model
173+ if metadata .ResourceData .HasChange ("tags" ) {
174+ payload .Tags = pointer .To (model .Tags )
175+ }
176+ if err := client .CreateOrUpdateThenPoll (ctx , * id , * payload , fleets .DefaultCreateOrUpdateOperationOptions ()); err != nil {
177+ return fmt .Errorf ("updating %s: %+v" , * id , err )
148178 }
149179
150- return metadata . Encode ( & schema )
180+ return nil
151181 },
152182 }
153183}
154184
155- func (r KubernetesFleetManagerResource ) Delete () sdk.ResourceFunc {
185+ func (r KubernetesFleetManagerResource ) Read () sdk.ResourceFunc {
156186 return sdk.ResourceFunc {
157- Timeout : 30 * time .Minute ,
187+ Timeout : 5 * time .Minute ,
158188 Func : func (ctx context.Context , metadata sdk.ResourceMetaData ) error {
159189 client := metadata .Client .ContainerService .V20240401 .Fleets
160190
@@ -163,16 +193,36 @@ func (r KubernetesFleetManagerResource) Delete() sdk.ResourceFunc {
163193 return err
164194 }
165195
166- if err := client .DeleteThenPoll (ctx , * id , fleets .DefaultDeleteOperationOptions ()); err != nil {
167- return fmt .Errorf ("deleting %s: %+v" , * id , err )
196+ resp , err := client .Get (ctx , * id )
197+ if err != nil {
198+ if response .WasNotFound (resp .HttpResponse ) {
199+ return metadata .MarkAsGone (id )
200+ }
201+
202+ return fmt .Errorf ("retrieving %s: %+v" , * id , err )
168203 }
169204
170- return nil
205+ state := KubernetesFleetManagerModel {
206+ Name : id .FleetName ,
207+ ResourceGroupName : id .ResourceGroupName ,
208+ }
209+
210+ if model := resp .Model ; model != nil {
211+ state .Location = location .Normalize (model .Location )
212+
213+ if properties := model .Properties ; properties != nil {
214+ state .HubProfile = flattenFleetHubProfileModel (properties .HubProfile )
215+ }
216+
217+ state .Tags = pointer .From (model .Tags )
218+ }
219+
220+ return metadata .Encode (& state )
171221 },
172222 }
173223}
174224
175- func (r KubernetesFleetManagerResource ) Update () sdk.ResourceFunc {
225+ func (r KubernetesFleetManagerResource ) Delete () sdk.ResourceFunc {
176226 return sdk.ResourceFunc {
177227 Timeout : 30 * time .Minute ,
178228 Func : func (ctx context.Context , metadata sdk.ResourceMetaData ) error {
@@ -183,45 +233,39 @@ func (r KubernetesFleetManagerResource) Update() sdk.ResourceFunc {
183233 return err
184234 }
185235
186- var config KubernetesFleetManagerResourceSchema
187- if err := metadata .Decode (& config ); err != nil {
188- return fmt .Errorf ("decoding: %+v" , err )
189- }
190-
191- existing , err := client .Get (ctx , * id )
192- if err != nil {
193- return fmt .Errorf ("retrieving existing %s: %+v" , * id , err )
194- }
195- if existing .Model == nil {
196- return fmt .Errorf ("retrieving existing %s: properties was nil" , * id )
197- }
198- payload := * existing .Model
199-
200- r .mapKubernetesFleetManagerResourceSchemaToFleet (config , & payload )
201-
202- if err := client .CreateOrUpdateThenPoll (ctx , * id , payload , fleets .DefaultCreateOrUpdateOperationOptions ()); err != nil {
203- return fmt .Errorf ("updating %s: %+v" , * id , err )
236+ if err := client .DeleteThenPoll (ctx , * id , fleets .DefaultDeleteOperationOptions ()); err != nil {
237+ return fmt .Errorf ("deleting %s: %+v" , id , err )
204238 }
205239
206240 return nil
207241 },
208242 }
209243}
210244
211- func (r KubernetesFleetManagerResource ) mapKubernetesFleetManagerResourceSchemaToFleet (input KubernetesFleetManagerResourceSchema , output * fleets.Fleet ) {
212- output .Location = location .Normalize (input .Location )
213- output .Tags = tags .Expand (input .Tags )
245+ func expandFleetHubProfileModel (inputList []FleetHubProfileModel ) * fleets.FleetHubProfile {
246+ if len (inputList ) == 0 {
247+ return nil
248+ }
214249
215- if output .Properties == nil {
216- output .Properties = & fleets.FleetProperties {}
250+ input := inputList [0 ]
251+ output := & fleets.FleetHubProfile {
252+ DnsPrefix : pointer .To (input .DnsPrefix ),
217253 }
254+
255+ return output
218256}
219257
220- func (r KubernetesFleetManagerResource ) mapFleetToKubernetesFleetManagerResourceSchema (input fleets.Fleet , output * KubernetesFleetManagerResourceSchema ) {
221- output .Location = location .Normalize (input .Location )
222- output .Tags = tags .Flatten (input .Tags )
258+ func flattenFleetHubProfileModel (input * fleets.FleetHubProfile ) []FleetHubProfileModel {
259+ if input == nil {
260+ return []FleetHubProfileModel {}
261+ }
223262
224- if input .Properties == nil {
225- input .Properties = & fleets.FleetProperties {}
263+ output := FleetHubProfileModel {
264+ DnsPrefix : pointer .From (input .DnsPrefix ),
265+ Fqdn : pointer .From (input .Fqdn ),
266+ KubernetesVersion : pointer .From (input .KubernetesVersion ),
267+ PortalFqdn : pointer .From (input .PortalFqdn ),
226268 }
269+
270+ return []FleetHubProfileModel {output }
227271}
0 commit comments