forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_container_aws_node_pool.go
1176 lines (1034 loc) · 40.4 KB
/
resource_container_aws_node_pool.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: DCL ***
//
// ----------------------------------------------------------------------------
//
// This file is managed by Magic Modules (https://github.com/GoogleCloudPlatform/magic-modules)
// and is based on the DCL (https://github.com/GoogleCloudPlatform/declarative-resource-client-library).
// Changes will need to be made to the DCL or Magic Modules instead of here.
//
// We are not currently able to accept contributions to this file. If changes
// are required, please file an issue at https://github.com/hashicorp/terraform-provider-google/issues/new/choose
//
// ----------------------------------------------------------------------------
package containeraws
import (
"context"
"fmt"
"log"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
containeraws "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/containeraws"
"github.com/hashicorp/terraform-provider-google/google/tpgdclresource"
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)
func ResourceContainerAwsNodePool() *schema.Resource {
return &schema.Resource{
Create: resourceContainerAwsNodePoolCreate,
Read: resourceContainerAwsNodePoolRead,
Update: resourceContainerAwsNodePoolUpdate,
Delete: resourceContainerAwsNodePoolDelete,
Importer: &schema.ResourceImporter{
State: resourceContainerAwsNodePoolImport,
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(20 * time.Minute),
Update: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(20 * time.Minute),
},
CustomizeDiff: customdiff.All(
tpgresource.DefaultProviderProject,
tpgresource.SetAnnotationsDiff,
),
Schema: map[string]*schema.Schema{
"autoscaling": {
Type: schema.TypeList,
Required: true,
Description: "Autoscaler configuration for this node pool.",
MaxItems: 1,
Elem: ContainerAwsNodePoolAutoscalingSchema(),
},
"cluster": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: "The awsCluster for the resource",
},
"config": {
Type: schema.TypeList,
Required: true,
Description: "The configuration of the node pool.",
MaxItems: 1,
Elem: ContainerAwsNodePoolConfigSchema(),
},
"location": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The location for the resource",
},
"max_pods_constraint": {
Type: schema.TypeList,
Required: true,
ForceNew: true,
Description: "The constraint on the maximum number of pods that can be run simultaneously on a node in the node pool.",
MaxItems: 1,
Elem: ContainerAwsNodePoolMaxPodsConstraintSchema(),
},
"name": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The name of this resource.",
},
"subnet_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "The subnet where the node pool node run.",
},
"version": {
Type: schema.TypeString,
Required: true,
Description: "The Kubernetes version to run on this node pool (e.g. `1.19.10-gke.1000`). You can list all supported versions on a given Google Cloud region by calling GetAwsServerConfig.",
},
"effective_annotations": {
Type: schema.TypeMap,
Computed: true,
Description: "All of annotations (key/value pairs) present on the resource in GCP, including the annotations configured through Terraform, other clients and services.",
},
"management": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: "The Management configuration for this node pool.",
MaxItems: 1,
Elem: ContainerAwsNodePoolManagementSchema(),
},
"project": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
Description: "The project for the resource",
},
"update_settings": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: "Optional. Update settings control the speed and disruption of the node pool update.",
MaxItems: 1,
Elem: ContainerAwsNodePoolUpdateSettingsSchema(),
},
"annotations": {
Type: schema.TypeMap,
Optional: true,
Description: "Optional. Annotations on the node pool. This field has the same restrictions as Kubernetes annotations. The total size of all keys and values combined is limited to 256k. Key can have 2 segments: prefix (optional) and name (required), separated by a slash (/). Prefix must be a DNS subdomain. Name must be 63 characters or less, begin and end with alphanumerics, with dashes (-), underscores (_), dots (.), and alphanumerics between.\n\n**Note**: This field is non-authoritative, and will only manage the annotations present in your configuration.\nPlease refer to the field `effective_annotations` for all of the annotations present on the resource.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: "Output only. The time at which this node pool was created.",
},
"etag": {
Type: schema.TypeString,
Computed: true,
Description: "Allows clients to perform consistent read-modify-writes through optimistic concurrency control. May be sent on update and delete requests to ensure the client has an up-to-date value before proceeding.",
},
"reconciling": {
Type: schema.TypeBool,
Computed: true,
Description: "Output only. If set, there are currently changes in flight to the node pool.",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "Output only. The lifecycle state of the node pool. Possible values: STATE_UNSPECIFIED, PROVISIONING, RUNNING, RECONCILING, STOPPING, ERROR, DEGRADED",
},
"uid": {
Type: schema.TypeString,
Computed: true,
Description: "Output only. A globally unique identifier for the node pool.",
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: "Output only. The time at which this node pool was last updated.",
},
},
}
}
func ContainerAwsNodePoolAutoscalingSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"max_node_count": {
Type: schema.TypeInt,
Required: true,
Description: "Maximum number of nodes in the NodePool. Must be >= min_node_count.",
},
"min_node_count": {
Type: schema.TypeInt,
Required: true,
Description: "Minimum number of nodes in the NodePool. Must be >= 1 and <= max_node_count.",
},
},
}
}
func ContainerAwsNodePoolConfigSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"config_encryption": {
Type: schema.TypeList,
Required: true,
Description: "The ARN of the AWS KMS key used to encrypt node pool configuration.",
MaxItems: 1,
Elem: ContainerAwsNodePoolConfigConfigEncryptionSchema(),
},
"iam_instance_profile": {
Type: schema.TypeString,
Required: true,
Description: "The name of the AWS IAM role assigned to nodes in the pool.",
},
"autoscaling_metrics_collection": {
Type: schema.TypeList,
Optional: true,
Description: "Optional. Configuration related to CloudWatch metrics collection on the Auto Scaling group of the node pool. When unspecified, metrics collection is disabled.",
MaxItems: 1,
Elem: ContainerAwsNodePoolConfigAutoscalingMetricsCollectionSchema(),
},
"instance_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
Description: "Optional. The AWS instance type. When unspecified, it defaults to `m5.large`.",
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: "Optional. The initial labels assigned to nodes of this node pool. An object containing a list of \"key\": value pairs. Example: { \"name\": \"wrench\", \"mass\": \"1.3kg\", \"count\": \"3\" }.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"proxy_config": {
Type: schema.TypeList,
Optional: true,
Description: "Proxy configuration for outbound HTTP(S) traffic.",
MaxItems: 1,
Elem: ContainerAwsNodePoolConfigProxyConfigSchema(),
},
"root_volume": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: "Optional. Template for the root volume provisioned for node pool nodes. Volumes will be provisioned in the availability zone assigned to the node pool subnet. When unspecified, it defaults to 32 GiB with the GP2 volume type.",
MaxItems: 1,
Elem: ContainerAwsNodePoolConfigRootVolumeSchema(),
},
"security_group_ids": {
Type: schema.TypeList,
Optional: true,
Description: "Optional. The IDs of additional security groups to add to nodes in this pool. The manager will automatically create security groups with minimum rules needed for a functioning cluster.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"ssh_config": {
Type: schema.TypeList,
Optional: true,
Description: "Optional. The SSH configuration.",
MaxItems: 1,
Elem: ContainerAwsNodePoolConfigSshConfigSchema(),
},
"tags": {
Type: schema.TypeMap,
Optional: true,
Description: "Optional. Key/value metadata to assign to each underlying AWS resource. Specify at most 50 pairs containing alphanumerics, spaces, and symbols (.+-=_:@/). Keys can be up to 127 Unicode characters. Values can be up to 255 Unicode characters.",
Elem: &schema.Schema{Type: schema.TypeString},
},
"taints": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: "Optional. The initial taints assigned to nodes of this node pool.",
Elem: ContainerAwsNodePoolConfigTaintsSchema(),
},
},
}
}
func ContainerAwsNodePoolConfigConfigEncryptionSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"kms_key_arn": {
Type: schema.TypeString,
Required: true,
Description: "The ARN of the AWS KMS key used to encrypt node pool configuration.",
},
},
}
}
func ContainerAwsNodePoolConfigAutoscalingMetricsCollectionSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"granularity": {
Type: schema.TypeString,
Required: true,
Description: "The frequency at which EC2 Auto Scaling sends aggregated data to AWS CloudWatch. The only valid value is \"1Minute\".",
},
"metrics": {
Type: schema.TypeList,
Optional: true,
Description: "The metrics to enable. For a list of valid metrics, see https://docs.aws.amazon.com/autoscaling/ec2/APIReference/API_EnableMetricsCollection.html. If you specify granularity and don't specify any metrics, all metrics are enabled.",
Elem: &schema.Schema{Type: schema.TypeString},
},
},
}
}
func ContainerAwsNodePoolConfigProxyConfigSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"secret_arn": {
Type: schema.TypeString,
Required: true,
Description: "The ARN of the AWS Secret Manager secret that contains the HTTP(S) proxy configuration.",
},
"secret_version": {
Type: schema.TypeString,
Required: true,
Description: "The version string of the AWS Secret Manager secret that contains the HTTP(S) proxy configuration.",
},
},
}
}
func ContainerAwsNodePoolConfigRootVolumeSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"iops": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Optional. The number of I/O operations per second (IOPS) to provision for GP3 volume.",
},
"kms_key_arn": {
Type: schema.TypeString,
Optional: true,
Description: "Optional. The Amazon Resource Name (ARN) of the Customer Managed Key (CMK) used to encrypt AWS EBS volumes. If not specified, the default Amazon managed key associated to the AWS region where this cluster runs will be used.",
},
"size_gib": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Optional. The size of the volume, in GiBs. When unspecified, a default value is provided. See the specific reference in the parent resource.",
},
"throughput": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Optional. The throughput to provision for the volume, in MiB/s. Only valid if the volume type is GP3. If volume type is gp3 and throughput is not specified, the throughput will defaults to 125.",
},
"volume_type": {
Type: schema.TypeString,
Computed: true,
Optional: true,
DiffSuppressFunc: tpgresource.CaseDiffSuppress,
Description: "Optional. Type of the EBS volume. When unspecified, it defaults to GP2 volume. Possible values: VOLUME_TYPE_UNSPECIFIED, GP2, GP3",
},
},
}
}
func ContainerAwsNodePoolConfigSshConfigSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"ec2_key_pair": {
Type: schema.TypeString,
Required: true,
Description: "The name of the EC2 key pair used to login into cluster machines.",
},
},
}
}
func ContainerAwsNodePoolConfigTaintsSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"effect": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CaseDiffSuppress,
Description: "The taint effect. Possible values: EFFECT_UNSPECIFIED, NO_SCHEDULE, PREFER_NO_SCHEDULE, NO_EXECUTE",
},
"key": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Key for the taint.",
},
"value": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "Value for the taint.",
},
},
}
}
func ContainerAwsNodePoolMaxPodsConstraintSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"max_pods_per_node": {
Type: schema.TypeInt,
Required: true,
ForceNew: true,
Description: "The maximum number of pods to schedule on a single node.",
},
},
}
}
func ContainerAwsNodePoolManagementSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"auto_repair": {
Type: schema.TypeBool,
Computed: true,
Optional: true,
Description: "Optional. Whether or not the nodes will be automatically repaired.",
},
},
}
}
func ContainerAwsNodePoolUpdateSettingsSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"surge_settings": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: "Optional. Settings for surge update.",
MaxItems: 1,
Elem: ContainerAwsNodePoolUpdateSettingsSurgeSettingsSchema(),
},
},
}
}
func ContainerAwsNodePoolUpdateSettingsSurgeSettingsSchema() *schema.Resource {
return &schema.Resource{
Schema: map[string]*schema.Schema{
"max_surge": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Optional. The maximum number of nodes that can be created beyond the current size of the node pool during the update process.",
},
"max_unavailable": {
Type: schema.TypeInt,
Computed: true,
Optional: true,
Description: "Optional. The maximum number of nodes that can be simultaneously unavailable during the update process. A node is considered unavailable if its status is not Ready.",
},
},
}
}
func resourceContainerAwsNodePoolCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
project, err := tpgresource.GetProject(d, config)
if err != nil {
return err
}
obj := &containeraws.NodePool{
Autoscaling: expandContainerAwsNodePoolAutoscaling(d.Get("autoscaling")),
Cluster: dcl.String(d.Get("cluster").(string)),
Config: expandContainerAwsNodePoolConfig(d.Get("config")),
Location: dcl.String(d.Get("location").(string)),
MaxPodsConstraint: expandContainerAwsNodePoolMaxPodsConstraint(d.Get("max_pods_constraint")),
Name: dcl.String(d.Get("name").(string)),
SubnetId: dcl.String(d.Get("subnet_id").(string)),
Version: dcl.String(d.Get("version").(string)),
Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")),
Management: expandContainerAwsNodePoolManagement(d.Get("management")),
Project: dcl.String(project),
UpdateSettings: expandContainerAwsNodePoolUpdateSettings(d.Get("update_settings")),
}
id, err := obj.ID()
if err != nil {
return fmt.Errorf("error constructing id: %s", err)
}
d.SetId(id)
directive := tpgdclresource.CreateDirective
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
billingProject := project
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
client := transport_tpg.NewDCLContainerAwsClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutCreate))
if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil {
d.SetId("")
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err)
} else {
client.Config.BasePath = bp
}
res, err := client.ApplyNodePool(context.Background(), obj, directive...)
if _, ok := err.(dcl.DiffAfterApplyError); ok {
log.Printf("[DEBUG] Diff after apply returned from the DCL: %s", err)
} else if err != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error creating NodePool: %s", err)
}
log.Printf("[DEBUG] Finished creating NodePool %q: %#v", d.Id(), res)
return resourceContainerAwsNodePoolRead(d, meta)
}
func resourceContainerAwsNodePoolRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
project, err := tpgresource.GetProject(d, config)
if err != nil {
return err
}
obj := &containeraws.NodePool{
Autoscaling: expandContainerAwsNodePoolAutoscaling(d.Get("autoscaling")),
Cluster: dcl.String(d.Get("cluster").(string)),
Config: expandContainerAwsNodePoolConfig(d.Get("config")),
Location: dcl.String(d.Get("location").(string)),
MaxPodsConstraint: expandContainerAwsNodePoolMaxPodsConstraint(d.Get("max_pods_constraint")),
Name: dcl.String(d.Get("name").(string)),
SubnetId: dcl.String(d.Get("subnet_id").(string)),
Version: dcl.String(d.Get("version").(string)),
Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")),
Management: expandContainerAwsNodePoolManagement(d.Get("management")),
Project: dcl.String(project),
UpdateSettings: expandContainerAwsNodePoolUpdateSettings(d.Get("update_settings")),
}
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
billingProject := project
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
client := transport_tpg.NewDCLContainerAwsClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutRead))
if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil {
d.SetId("")
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err)
} else {
client.Config.BasePath = bp
}
res, err := client.GetNodePool(context.Background(), obj)
if err != nil {
resourceName := fmt.Sprintf("ContainerAwsNodePool %q", d.Id())
return tpgdclresource.HandleNotFoundDCLError(err, d, resourceName)
}
if err = d.Set("autoscaling", flattenContainerAwsNodePoolAutoscaling(res.Autoscaling)); err != nil {
return fmt.Errorf("error setting autoscaling in state: %s", err)
}
if err = d.Set("cluster", res.Cluster); err != nil {
return fmt.Errorf("error setting cluster in state: %s", err)
}
if err = d.Set("config", flattenContainerAwsNodePoolConfig(res.Config)); err != nil {
return fmt.Errorf("error setting config in state: %s", err)
}
if err = d.Set("location", res.Location); err != nil {
return fmt.Errorf("error setting location in state: %s", err)
}
if err = d.Set("max_pods_constraint", flattenContainerAwsNodePoolMaxPodsConstraint(res.MaxPodsConstraint)); err != nil {
return fmt.Errorf("error setting max_pods_constraint in state: %s", err)
}
if err = d.Set("name", res.Name); err != nil {
return fmt.Errorf("error setting name in state: %s", err)
}
if err = d.Set("subnet_id", res.SubnetId); err != nil {
return fmt.Errorf("error setting subnet_id in state: %s", err)
}
if err = d.Set("version", res.Version); err != nil {
return fmt.Errorf("error setting version in state: %s", err)
}
if err = d.Set("effective_annotations", res.Annotations); err != nil {
return fmt.Errorf("error setting effective_annotations in state: %s", err)
}
if err = d.Set("management", tpgresource.FlattenContainerAwsNodePoolManagement(res.Management, d, config)); err != nil {
return fmt.Errorf("error setting management in state: %s", err)
}
if err = d.Set("project", res.Project); err != nil {
return fmt.Errorf("error setting project in state: %s", err)
}
if err = d.Set("update_settings", flattenContainerAwsNodePoolUpdateSettings(res.UpdateSettings)); err != nil {
return fmt.Errorf("error setting update_settings in state: %s", err)
}
if err = d.Set("annotations", flattenContainerAwsNodePoolAnnotations(res.Annotations, d)); err != nil {
return fmt.Errorf("error setting annotations in state: %s", err)
}
if err = d.Set("create_time", res.CreateTime); err != nil {
return fmt.Errorf("error setting create_time in state: %s", err)
}
if err = d.Set("etag", res.Etag); err != nil {
return fmt.Errorf("error setting etag in state: %s", err)
}
if err = d.Set("reconciling", res.Reconciling); err != nil {
return fmt.Errorf("error setting reconciling in state: %s", err)
}
if err = d.Set("state", res.State); err != nil {
return fmt.Errorf("error setting state in state: %s", err)
}
if err = d.Set("uid", res.Uid); err != nil {
return fmt.Errorf("error setting uid in state: %s", err)
}
if err = d.Set("update_time", res.UpdateTime); err != nil {
return fmt.Errorf("error setting update_time in state: %s", err)
}
return nil
}
func resourceContainerAwsNodePoolUpdate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
project, err := tpgresource.GetProject(d, config)
if err != nil {
return err
}
obj := &containeraws.NodePool{
Autoscaling: expandContainerAwsNodePoolAutoscaling(d.Get("autoscaling")),
Cluster: dcl.String(d.Get("cluster").(string)),
Config: expandContainerAwsNodePoolConfig(d.Get("config")),
Location: dcl.String(d.Get("location").(string)),
MaxPodsConstraint: expandContainerAwsNodePoolMaxPodsConstraint(d.Get("max_pods_constraint")),
Name: dcl.String(d.Get("name").(string)),
SubnetId: dcl.String(d.Get("subnet_id").(string)),
Version: dcl.String(d.Get("version").(string)),
Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")),
Management: expandContainerAwsNodePoolManagement(d.Get("management")),
Project: dcl.String(project),
UpdateSettings: expandContainerAwsNodePoolUpdateSettings(d.Get("update_settings")),
}
directive := tpgdclresource.UpdateDirective
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
billingProject := ""
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
client := transport_tpg.NewDCLContainerAwsClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutUpdate))
if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil {
d.SetId("")
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err)
} else {
client.Config.BasePath = bp
}
res, err := client.ApplyNodePool(context.Background(), obj, directive...)
if _, ok := err.(dcl.DiffAfterApplyError); ok {
log.Printf("[DEBUG] Diff after apply returned from the DCL: %s", err)
} else if err != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error updating NodePool: %s", err)
}
log.Printf("[DEBUG] Finished creating NodePool %q: %#v", d.Id(), res)
return resourceContainerAwsNodePoolRead(d, meta)
}
func resourceContainerAwsNodePoolDelete(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
project, err := tpgresource.GetProject(d, config)
if err != nil {
return err
}
obj := &containeraws.NodePool{
Autoscaling: expandContainerAwsNodePoolAutoscaling(d.Get("autoscaling")),
Cluster: dcl.String(d.Get("cluster").(string)),
Config: expandContainerAwsNodePoolConfig(d.Get("config")),
Location: dcl.String(d.Get("location").(string)),
MaxPodsConstraint: expandContainerAwsNodePoolMaxPodsConstraint(d.Get("max_pods_constraint")),
Name: dcl.String(d.Get("name").(string)),
SubnetId: dcl.String(d.Get("subnet_id").(string)),
Version: dcl.String(d.Get("version").(string)),
Annotations: tpgresource.CheckStringMap(d.Get("effective_annotations")),
Management: expandContainerAwsNodePoolManagement(d.Get("management")),
Project: dcl.String(project),
UpdateSettings: expandContainerAwsNodePoolUpdateSettings(d.Get("update_settings")),
}
log.Printf("[DEBUG] Deleting NodePool %q", d.Id())
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
billingProject := project
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
client := transport_tpg.NewDCLContainerAwsClient(config, userAgent, billingProject, d.Timeout(schema.TimeoutDelete))
if bp, err := tpgresource.ReplaceVars(d, config, client.Config.BasePath); err != nil {
d.SetId("")
return fmt.Errorf("Could not format %q: %w", client.Config.BasePath, err)
} else {
client.Config.BasePath = bp
}
if err := client.DeleteNodePool(context.Background(), obj); err != nil {
return fmt.Errorf("Error deleting NodePool: %s", err)
}
log.Printf("[DEBUG] Finished deleting NodePool %q", d.Id())
return nil
}
func resourceContainerAwsNodePoolImport(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
config := meta.(*transport_tpg.Config)
if err := tpgresource.ParseImportId([]string{
"projects/(?P<project>[^/]+)/locations/(?P<location>[^/]+)/awsClusters/(?P<cluster>[^/]+)/awsNodePools/(?P<name>[^/]+)",
"(?P<project>[^/]+)/(?P<location>[^/]+)/(?P<cluster>[^/]+)/(?P<name>[^/]+)",
"(?P<location>[^/]+)/(?P<cluster>[^/]+)/(?P<name>[^/]+)",
}, d, config); err != nil {
return nil, err
}
// Replace import id for the resource id
id, err := tpgresource.ReplaceVarsForId(d, config, "projects/{{project}}/locations/{{location}}/awsClusters/{{cluster}}/awsNodePools/{{name}}")
if err != nil {
return nil, fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
return []*schema.ResourceData{d}, nil
}
func expandContainerAwsNodePoolAutoscaling(o interface{}) *containeraws.NodePoolAutoscaling {
if o == nil {
return containeraws.EmptyNodePoolAutoscaling
}
objArr := o.([]interface{})
if len(objArr) == 0 || objArr[0] == nil {
return containeraws.EmptyNodePoolAutoscaling
}
obj := objArr[0].(map[string]interface{})
return &containeraws.NodePoolAutoscaling{
MaxNodeCount: dcl.Int64(int64(obj["max_node_count"].(int))),
MinNodeCount: dcl.Int64(int64(obj["min_node_count"].(int))),
}
}
func flattenContainerAwsNodePoolAutoscaling(obj *containeraws.NodePoolAutoscaling) interface{} {
if obj == nil || obj.Empty() {
return nil
}
transformed := map[string]interface{}{
"max_node_count": obj.MaxNodeCount,
"min_node_count": obj.MinNodeCount,
}
return []interface{}{transformed}
}
func expandContainerAwsNodePoolConfig(o interface{}) *containeraws.NodePoolConfig {
if o == nil {
return containeraws.EmptyNodePoolConfig
}
objArr := o.([]interface{})
if len(objArr) == 0 || objArr[0] == nil {
return containeraws.EmptyNodePoolConfig
}
obj := objArr[0].(map[string]interface{})
return &containeraws.NodePoolConfig{
ConfigEncryption: expandContainerAwsNodePoolConfigConfigEncryption(obj["config_encryption"]),
IamInstanceProfile: dcl.String(obj["iam_instance_profile"].(string)),
AutoscalingMetricsCollection: expandContainerAwsNodePoolConfigAutoscalingMetricsCollection(obj["autoscaling_metrics_collection"]),
InstanceType: dcl.StringOrNil(obj["instance_type"].(string)),
Labels: tpgresource.CheckStringMap(obj["labels"]),
ProxyConfig: expandContainerAwsNodePoolConfigProxyConfig(obj["proxy_config"]),
RootVolume: expandContainerAwsNodePoolConfigRootVolume(obj["root_volume"]),
SecurityGroupIds: tpgdclresource.ExpandStringArray(obj["security_group_ids"]),
SshConfig: expandContainerAwsNodePoolConfigSshConfig(obj["ssh_config"]),
Tags: tpgresource.CheckStringMap(obj["tags"]),
Taints: expandContainerAwsNodePoolConfigTaintsArray(obj["taints"]),
}
}
func flattenContainerAwsNodePoolConfig(obj *containeraws.NodePoolConfig) interface{} {
if obj == nil || obj.Empty() {
return nil
}
transformed := map[string]interface{}{
"config_encryption": flattenContainerAwsNodePoolConfigConfigEncryption(obj.ConfigEncryption),
"iam_instance_profile": obj.IamInstanceProfile,
"autoscaling_metrics_collection": flattenContainerAwsNodePoolConfigAutoscalingMetricsCollection(obj.AutoscalingMetricsCollection),
"instance_type": obj.InstanceType,
"labels": obj.Labels,
"proxy_config": flattenContainerAwsNodePoolConfigProxyConfig(obj.ProxyConfig),
"root_volume": flattenContainerAwsNodePoolConfigRootVolume(obj.RootVolume),
"security_group_ids": obj.SecurityGroupIds,
"ssh_config": flattenContainerAwsNodePoolConfigSshConfig(obj.SshConfig),
"tags": obj.Tags,
"taints": flattenContainerAwsNodePoolConfigTaintsArray(obj.Taints),
}
return []interface{}{transformed}
}
func expandContainerAwsNodePoolConfigConfigEncryption(o interface{}) *containeraws.NodePoolConfigConfigEncryption {
if o == nil {
return containeraws.EmptyNodePoolConfigConfigEncryption
}
objArr := o.([]interface{})
if len(objArr) == 0 || objArr[0] == nil {
return containeraws.EmptyNodePoolConfigConfigEncryption
}
obj := objArr[0].(map[string]interface{})
return &containeraws.NodePoolConfigConfigEncryption{
KmsKeyArn: dcl.String(obj["kms_key_arn"].(string)),
}
}
func flattenContainerAwsNodePoolConfigConfigEncryption(obj *containeraws.NodePoolConfigConfigEncryption) interface{} {
if obj == nil || obj.Empty() {
return nil
}
transformed := map[string]interface{}{
"kms_key_arn": obj.KmsKeyArn,
}
return []interface{}{transformed}
}
func expandContainerAwsNodePoolConfigAutoscalingMetricsCollection(o interface{}) *containeraws.NodePoolConfigAutoscalingMetricsCollection {
if o == nil {
return containeraws.EmptyNodePoolConfigAutoscalingMetricsCollection
}
objArr := o.([]interface{})
if len(objArr) == 0 || objArr[0] == nil {
return containeraws.EmptyNodePoolConfigAutoscalingMetricsCollection
}
obj := objArr[0].(map[string]interface{})
return &containeraws.NodePoolConfigAutoscalingMetricsCollection{
Granularity: dcl.String(obj["granularity"].(string)),
Metrics: tpgdclresource.ExpandStringArray(obj["metrics"]),
}
}
func flattenContainerAwsNodePoolConfigAutoscalingMetricsCollection(obj *containeraws.NodePoolConfigAutoscalingMetricsCollection) interface{} {
if obj == nil || obj.Empty() {
return nil
}
transformed := map[string]interface{}{
"granularity": obj.Granularity,
"metrics": obj.Metrics,
}
return []interface{}{transformed}
}
func expandContainerAwsNodePoolConfigProxyConfig(o interface{}) *containeraws.NodePoolConfigProxyConfig {
if o == nil {
return containeraws.EmptyNodePoolConfigProxyConfig
}
objArr := o.([]interface{})
if len(objArr) == 0 || objArr[0] == nil {
return containeraws.EmptyNodePoolConfigProxyConfig
}
obj := objArr[0].(map[string]interface{})
return &containeraws.NodePoolConfigProxyConfig{
SecretArn: dcl.String(obj["secret_arn"].(string)),
SecretVersion: dcl.String(obj["secret_version"].(string)),
}
}
func flattenContainerAwsNodePoolConfigProxyConfig(obj *containeraws.NodePoolConfigProxyConfig) interface{} {
if obj == nil || obj.Empty() {
return nil
}
transformed := map[string]interface{}{
"secret_arn": obj.SecretArn,
"secret_version": obj.SecretVersion,
}
return []interface{}{transformed}
}
func expandContainerAwsNodePoolConfigRootVolume(o interface{}) *containeraws.NodePoolConfigRootVolume {
if o == nil {
return nil
}
objArr := o.([]interface{})
if len(objArr) == 0 || objArr[0] == nil {
return nil
}
obj := objArr[0].(map[string]interface{})
return &containeraws.NodePoolConfigRootVolume{
Iops: dcl.Int64OrNil(int64(obj["iops"].(int))),
KmsKeyArn: dcl.String(obj["kms_key_arn"].(string)),
SizeGib: dcl.Int64OrNil(int64(obj["size_gib"].(int))),
Throughput: dcl.Int64OrNil(int64(obj["throughput"].(int))),
VolumeType: containeraws.NodePoolConfigRootVolumeVolumeTypeEnumRef(obj["volume_type"].(string)),
}
}
func flattenContainerAwsNodePoolConfigRootVolume(obj *containeraws.NodePoolConfigRootVolume) interface{} {
if obj == nil || obj.Empty() {
return nil
}
transformed := map[string]interface{}{
"iops": obj.Iops,
"kms_key_arn": obj.KmsKeyArn,
"size_gib": obj.SizeGib,
"throughput": obj.Throughput,
"volume_type": obj.VolumeType,
}
return []interface{}{transformed}
}
func expandContainerAwsNodePoolConfigSshConfig(o interface{}) *containeraws.NodePoolConfigSshConfig {
if o == nil {
return containeraws.EmptyNodePoolConfigSshConfig
}
objArr := o.([]interface{})
if len(objArr) == 0 || objArr[0] == nil {
return containeraws.EmptyNodePoolConfigSshConfig
}
obj := objArr[0].(map[string]interface{})
return &containeraws.NodePoolConfigSshConfig{
Ec2KeyPair: dcl.String(obj["ec2_key_pair"].(string)),
}
}
func flattenContainerAwsNodePoolConfigSshConfig(obj *containeraws.NodePoolConfigSshConfig) interface{} {
if obj == nil || obj.Empty() {
return nil
}
transformed := map[string]interface{}{
"ec2_key_pair": obj.Ec2KeyPair,
}
return []interface{}{transformed}
}
func expandContainerAwsNodePoolConfigTaintsArray(o interface{}) []containeraws.NodePoolConfigTaints {
if o == nil {
return make([]containeraws.NodePoolConfigTaints, 0)
}