forked from hashicorp/terraform-provider-google-beta
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresource_artifact_registry_repository.go
2834 lines (2550 loc) · 114 KB
/
resource_artifact_registry_repository.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: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This code is generated by Magic Modules using the following:
//
// Configuration: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/products/artifactregistry/Repository.yaml
// Template: https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/resource.go.tmpl
//
// DO NOT EDIT this file directly. Any changes made to this file will be
// overwritten during the next generation cycle.
//
// ----------------------------------------------------------------------------
package artifactregistry
import (
"fmt"
"log"
"net/http"
"reflect"
"strconv"
"strings"
"time"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/verify"
)
func upstreamPoliciesDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
o, n := d.GetChange("virtual_repository_config.0.upstream_policies")
oldPolicies, ok := o.([]any)
if !ok {
return false
}
newPolicies, ok := n.([]any)
if !ok {
return false
}
var oldHashes, newHashes []interface{}
for _, policy := range oldPolicies {
data, ok := policy.(map[string]any)
if !ok {
return false
}
hashStr := fmt.Sprintf("[id:%v priority:%v repository:%v]", data["id"], data["priority"], data["repository"])
oldHashes = append(oldHashes, hashStr)
}
for _, policy := range newPolicies {
data, ok := policy.(map[string]any)
if !ok {
return false
}
hashStr := fmt.Sprintf("[id:%v priority:%v repository:%v]", data["id"], data["priority"], data["repository"])
newHashes = append(newHashes, hashStr)
}
oldSet := schema.NewSet(schema.HashString, oldHashes)
newSet := schema.NewSet(schema.HashString, newHashes)
return oldSet.Equal(newSet)
}
func parseDurationAsSeconds(v string) (int, bool) {
if len(v) == 0 {
return 0, false
}
n, err := strconv.Atoi(v[:len(v)-1])
if err != nil {
return 0, false
}
switch v[len(v)-1] {
case 's':
return n, true
case 'm':
return n * 60, true
case 'h':
return n * 3600, true
case 'd':
return n * 86400, true
default:
return 0, false
}
}
// Like tpgresource.DurationDiffSuppress, but supports 'd'
func durationDiffSuppress(k, oldr, newr string, d *schema.ResourceData) bool {
o, n := d.GetChange(k)
old, ok := o.(string)
if !ok {
return false
}
new, ok := n.(string)
if !ok {
return false
}
if old == new {
return true
}
oldSeconds, ok := parseDurationAsSeconds(old)
if !ok {
return false
}
newSeconds, ok := parseDurationAsSeconds(new)
if !ok {
return false
}
return oldSeconds == newSeconds
}
func mapHashID(v any) int {
obj, ok := v.(map[string]any)
if !ok {
return 0
}
s, ok := obj["id"].(string)
if !ok {
return 0
}
return schema.HashString(s)
}
func isDefaultEnum(val any) bool {
s, ok := val.(string)
if !ok {
return false
}
return s == "" || strings.HasSuffix(s, "_UNSPECIFIED")
}
// emptyMavenConfigDiffSuppress generates a config from defaults if it or any
// properties are unset. Missing, empty and default configs are all equivalent.
func emptyMavenConfigDiffSuppress(k, old, new string, d *schema.ResourceData) bool {
oSnap, nSnap := d.GetChange("maven_config.0.allow_snapshot_overwrites")
if oSnap.(bool) != nSnap.(bool) {
return false
}
oPolicy, nPolicy := d.GetChange("maven_config.0.version_policy")
return isDefaultEnum(oPolicy) && isDefaultEnum(nPolicy)
}
func ResourceArtifactRegistryRepository() *schema.Resource {
return &schema.Resource{
Create: resourceArtifactRegistryRepositoryCreate,
Read: resourceArtifactRegistryRepositoryRead,
Update: resourceArtifactRegistryRepositoryUpdate,
Delete: resourceArtifactRegistryRepositoryDelete,
Importer: &schema.ResourceImporter{
State: resourceArtifactRegistryRepositoryImport,
},
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.SetLabelsDiff,
tpgresource.DefaultProviderProject,
),
Schema: map[string]*schema.Schema{
"format": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: tpgresource.CaseDiffSuppress,
Description: `The format of packages that are stored in the repository. Supported formats
can be found [here](https://cloud.google.com/artifact-registry/docs/supported-formats).
You can only create alpha formats if you are a member of the
[alpha user group](https://cloud.google.com/artifact-registry/docs/supported-formats#alpha-access).`,
},
"repository_id": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `The last part of the repository name, for example:
"repo1"`,
},
"cleanup_policies": {
Type: schema.TypeSet,
Optional: true,
Description: `Cleanup policies for this repository. Cleanup policies indicate when
certain package versions can be automatically deleted.
Map keys are policy IDs supplied by users during policy creation. They must
unique within a repository and be under 128 characters in length.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Required: true,
},
"action": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"DELETE", "KEEP", ""}),
Description: `Policy action. Possible values: ["DELETE", "KEEP"]`,
},
"condition": {
Type: schema.TypeList,
Optional: true,
Description: `Policy condition for matching versions.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"newer_than": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: durationDiffSuppress,
Description: `Match versions newer than a duration.`,
},
"older_than": {
Type: schema.TypeString,
Optional: true,
DiffSuppressFunc: durationDiffSuppress,
Description: `Match versions older than a duration.`,
},
"package_name_prefixes": {
Type: schema.TypeList,
Optional: true,
Description: `Match versions by package prefix. Applied on any prefix match.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"tag_prefixes": {
Type: schema.TypeList,
Optional: true,
Description: `Match versions by tag prefix. Applied on any prefix match.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"tag_state": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"TAGGED", "UNTAGGED", "ANY", ""}),
Description: `Match versions by tag status. Default value: "ANY" Possible values: ["TAGGED", "UNTAGGED", "ANY"]`,
Default: "ANY",
},
"version_name_prefixes": {
Type: schema.TypeList,
Optional: true,
Description: `Match versions by version name prefix. Applied on any prefix match.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
"most_recent_versions": {
Type: schema.TypeList,
Optional: true,
Description: `Policy condition for retaining a minimum number of versions. May only be
specified with a Keep action.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"keep_count": {
Type: schema.TypeInt,
Optional: true,
Description: `Minimum number of versions to keep.`,
},
"package_name_prefixes": {
Type: schema.TypeList,
Optional: true,
Description: `Match versions by package prefix. Applied on any prefix match.`,
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},
},
},
Set: mapHashID,
},
"cleanup_policy_dry_run": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, the cleanup pipeline is prevented from deleting versions in this
repository.`,
},
"description": {
Type: schema.TypeString,
Optional: true,
Description: `The user-provided description of the repository.`,
},
"docker_config": {
Type: schema.TypeList,
Optional: true,
Description: `Docker repository config contains repository level configuration for the repositories of docker type.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"immutable_tags": {
Type: schema.TypeBool,
Optional: true,
Description: `The repository which enabled this flag prevents all tags from being modified, moved or deleted. This does not prevent tags from being created.`,
},
},
},
},
"kms_key_name": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The Cloud KMS resource name of the customer managed encryption key that’s
used to encrypt the contents of the Repository. Has the form:
'projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key'.
This value may not be changed after the Repository has been created.`,
},
"labels": {
Type: schema.TypeMap,
Optional: true,
Description: `Labels with user-defined metadata.
This field may contain up to 64 entries. Label keys and values may be no
longer than 63 characters. Label keys must begin with a lowercase letter
and may only contain lowercase letters, numeric characters, underscores,
and dashes.
**Note**: This field is non-authoritative, and will only manage the labels present in your configuration.
Please refer to the field 'effective_labels' for all of the labels present on the resource.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"location": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: `The name of the repository's location. In addition to specific regions,
special values for multi-region locations are 'asia', 'europe', and 'us'.
See [here](https://cloud.google.com/artifact-registry/docs/repositories/repo-locations),
or use the
[google_artifact_registry_locations](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/artifact_registry_locations)
data source for possible values.`,
},
"maven_config": {
Type: schema.TypeList,
Optional: true,
DiffSuppressFunc: emptyMavenConfigDiffSuppress,
Description: `MavenRepositoryConfig is maven related repository details.
Provides additional configuration details for repositories of the maven
format type.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"allow_snapshot_overwrites": {
Type: schema.TypeBool,
Optional: true,
ForceNew: true,
Description: `The repository with this flag will allow publishing the same
snapshot versions.`,
},
"version_policy": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"VERSION_POLICY_UNSPECIFIED", "RELEASE", "SNAPSHOT", ""}),
Description: `Version policy defines the versions that the registry will accept. Default value: "VERSION_POLICY_UNSPECIFIED" Possible values: ["VERSION_POLICY_UNSPECIFIED", "RELEASE", "SNAPSHOT"]`,
Default: "VERSION_POLICY_UNSPECIFIED",
},
},
},
},
"mode": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"STANDARD_REPOSITORY", "VIRTUAL_REPOSITORY", "REMOTE_REPOSITORY", ""}),
Description: `The mode configures the repository to serve artifacts from different sources. Default value: "STANDARD_REPOSITORY" Possible values: ["STANDARD_REPOSITORY", "VIRTUAL_REPOSITORY", "REMOTE_REPOSITORY"]`,
Default: "STANDARD_REPOSITORY",
},
"remote_repository_config": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Configuration specific for a Remote Repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"apt_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Specific settings for an Apt remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"public_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `One of the publicly available Apt repositories supported by Artifact Registry.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repository_base": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"DEBIAN", "UBUNTU"}),
Description: `A common public repository base for Apt, e.g. '"debian/dists/buster"' Possible values: ["DEBIAN", "UBUNTU"]`,
},
"repository_path": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Specific repository from the base.`,
},
},
},
},
},
},
ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"},
},
"common_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Specific settings for an Artifact Registory remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uri": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `One of:
a. Artifact Registry Repository resource, e.g. 'projects/UPSTREAM_PROJECT_ID/locations/REGION/repositories/UPSTREAM_REPOSITORY'
b. URI to the registry, e.g. '"https://registry-1.docker.io"'
c. URI to Artifact Registry Repository, e.g. '"https://REGION-docker.pkg.dev/UPSTREAM_PROJECT_ID/UPSTREAM_REPOSITORY"'`,
},
},
},
ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"},
},
"description": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The description of the remote source.`,
},
"disable_upstream_validation": {
Type: schema.TypeBool,
Optional: true,
Description: `If true, the remote repository upstream and upstream credentials will
not be validated.`,
},
"docker_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Specific settings for a Docker remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uri": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Specific uri to the registry, e.g. '"https://registry-1.docker.io"'`,
},
},
},
ConflictsWith: []string{"remote_repository_config.0.docker_repository.0.public_repository"},
},
"public_repository": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"DOCKER_HUB", ""}),
Description: `Address of the remote repository. Default value: "DOCKER_HUB" Possible values: ["DOCKER_HUB"]`,
Default: "DOCKER_HUB",
ConflictsWith: []string{"remote_repository_config.0.docker_repository.0.custom_repository"},
},
},
},
ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"},
},
"maven_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Specific settings for a Maven remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uri": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Specific uri to the registry, e.g. '"https://repo.maven.apache.org/maven2"'`,
},
},
},
ConflictsWith: []string{"remote_repository_config.0.maven_repository.0.public_repository"},
},
"public_repository": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"MAVEN_CENTRAL", ""}),
Description: `Address of the remote repository. Default value: "MAVEN_CENTRAL" Possible values: ["MAVEN_CENTRAL"]`,
Default: "MAVEN_CENTRAL",
ConflictsWith: []string{"remote_repository_config.0.maven_repository.0.custom_repository"},
},
},
},
ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"},
},
"npm_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Specific settings for an Npm remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uri": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Specific uri to the registry, e.g. '"https://registry.npmjs.org"'`,
},
},
},
ConflictsWith: []string{"remote_repository_config.0.npm_repository.0.public_repository"},
},
"public_repository": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"NPMJS", ""}),
Description: `Address of the remote repository. Default value: "NPMJS" Possible values: ["NPMJS"]`,
Default: "NPMJS",
ConflictsWith: []string{"remote_repository_config.0.npm_repository.0.custom_repository"},
},
},
},
ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"},
},
"python_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Specific settings for a Python remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"custom_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `[Deprecated, please use commonRepository instead] Settings for a remote repository with a custom uri.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"uri": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `Specific uri to the registry, e.g. '"https://pypi.io"'`,
},
},
},
ConflictsWith: []string{"remote_repository_config.0.python_repository.0.public_repository"},
},
"public_repository": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"PYPI", ""}),
Description: `Address of the remote repository. Default value: "PYPI" Possible values: ["PYPI"]`,
Default: "PYPI",
ConflictsWith: []string{"remote_repository_config.0.python_repository.0.custom_repository"},
},
},
},
ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"},
},
"upstream_credentials": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `The credentials used to access the remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"username_password_credentials": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Use username and password to access the remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"password_secret_version": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The Secret Manager key version that holds the password to access the
remote repository. Must be in the format of
'projects/{project}/secrets/{secret}/versions/{version}'.`,
},
"username": {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Description: `The username to access the remote repository.`,
},
},
},
},
},
},
},
"yum_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `Specific settings for an Yum remote repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"public_repository": {
Type: schema.TypeList,
Optional: true,
ForceNew: true,
Description: `One of the publicly available Yum repositories supported by Artifact Registry.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"repository_base": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: verify.ValidateEnum([]string{"CENTOS", "CENTOS_DEBUG", "CENTOS_VAULT", "CENTOS_STREAM", "ROCKY", "EPEL"}),
Description: `A common public repository base for Yum. Possible values: ["CENTOS", "CENTOS_DEBUG", "CENTOS_VAULT", "CENTOS_STREAM", "ROCKY", "EPEL"]`,
},
"repository_path": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: `Specific repository from the base, e.g. '"pub/rocky/9/BaseOS/x86_64/os"'`,
},
},
},
},
},
},
ExactlyOneOf: []string{"remote_repository_config.0.apt_repository", "remote_repository_config.0.docker_repository", "remote_repository_config.0.maven_repository", "remote_repository_config.0.npm_repository", "remote_repository_config.0.python_repository", "remote_repository_config.0.yum_repository", "remote_repository_config.0.common_repository"},
},
},
},
ConflictsWith: []string{"virtual_repository_config"},
},
"virtual_repository_config": {
Type: schema.TypeList,
Optional: true,
Description: `Configuration specific for a Virtual Repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"upstream_policies": {
Type: schema.TypeList,
Optional: true,
DiffSuppressFunc: upstreamPoliciesDiffSuppress,
Description: `Policies that configure the upstream artifacts distributed by the Virtual
Repository. Upstream policies cannot be set on a standard repository.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Optional: true,
Description: `The user-provided ID of the upstream policy.`,
},
"priority": {
Type: schema.TypeInt,
Optional: true,
Description: `Entries with a greater priority value take precedence in the pull order.`,
},
"repository": {
Type: schema.TypeString,
Optional: true,
Description: `A reference to the repository resource, for example:
"projects/p1/locations/us-central1/repository/repo1".`,
},
},
},
},
},
},
ConflictsWith: []string{"remote_repository_config"},
},
"vulnerability_scanning_config": {
Type: schema.TypeList,
Computed: true,
Optional: true,
Description: `Configuration for vulnerability scanning of artifacts stored in this repository.`,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"enablement_config": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: verify.ValidateEnum([]string{"INHERITED", "DISABLED", ""}),
Description: `This configures whether vulnerability scanning is automatically performed for artifacts pushed to this repository. Possible values: ["INHERITED", "DISABLED"]`,
},
"enablement_state": {
Type: schema.TypeString,
Computed: true,
Description: `This field returns whether scanning is active for this repository.`,
},
"enablement_state_reason": {
Type: schema.TypeString,
Computed: true,
Description: `This provides an explanation for the state of scanning on this repository.`,
},
},
},
},
"create_time": {
Type: schema.TypeString,
Computed: true,
Description: `The time when the repository was created.`,
},
"effective_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `All of labels (key/value pairs) present on the resource in GCP, including the labels configured through Terraform, other clients and services.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: `The name of the repository, for example:
"repo1"`,
},
"terraform_labels": {
Type: schema.TypeMap,
Computed: true,
Description: `The combination of labels configured directly on the resource
and default labels configured on the provider.`,
Elem: &schema.Schema{Type: schema.TypeString},
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Description: `The time when the repository was last updated.`,
},
"project": {
Type: schema.TypeString,
Optional: true,
Computed: true,
ForceNew: true,
},
},
UseJSONNumber: true,
}
}
func resourceArtifactRegistryRepositoryCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
obj := make(map[string]interface{})
formatProp, err := expandArtifactRegistryRepositoryFormat(d.Get("format"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("format"); !tpgresource.IsEmptyValue(reflect.ValueOf(formatProp)) && (ok || !reflect.DeepEqual(v, formatProp)) {
obj["format"] = formatProp
}
descriptionProp, err := expandArtifactRegistryRepositoryDescription(d.Get("description"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("description"); !tpgresource.IsEmptyValue(reflect.ValueOf(descriptionProp)) && (ok || !reflect.DeepEqual(v, descriptionProp)) {
obj["description"] = descriptionProp
}
kmsKeyNameProp, err := expandArtifactRegistryRepositoryKmsKeyName(d.Get("kms_key_name"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("kms_key_name"); !tpgresource.IsEmptyValue(reflect.ValueOf(kmsKeyNameProp)) && (ok || !reflect.DeepEqual(v, kmsKeyNameProp)) {
obj["kmsKeyName"] = kmsKeyNameProp
}
dockerConfigProp, err := expandArtifactRegistryRepositoryDockerConfig(d.Get("docker_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("docker_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(dockerConfigProp)) && (ok || !reflect.DeepEqual(v, dockerConfigProp)) {
obj["dockerConfig"] = dockerConfigProp
}
mavenConfigProp, err := expandArtifactRegistryRepositoryMavenConfig(d.Get("maven_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("maven_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(mavenConfigProp)) && (ok || !reflect.DeepEqual(v, mavenConfigProp)) {
obj["mavenConfig"] = mavenConfigProp
}
modeProp, err := expandArtifactRegistryRepositoryMode(d.Get("mode"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("mode"); !tpgresource.IsEmptyValue(reflect.ValueOf(modeProp)) && (ok || !reflect.DeepEqual(v, modeProp)) {
obj["mode"] = modeProp
}
virtualRepositoryConfigProp, err := expandArtifactRegistryRepositoryVirtualRepositoryConfig(d.Get("virtual_repository_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("virtual_repository_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(virtualRepositoryConfigProp)) && (ok || !reflect.DeepEqual(v, virtualRepositoryConfigProp)) {
obj["virtualRepositoryConfig"] = virtualRepositoryConfigProp
}
cleanupPoliciesProp, err := expandArtifactRegistryRepositoryCleanupPolicies(d.Get("cleanup_policies"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("cleanup_policies"); !tpgresource.IsEmptyValue(reflect.ValueOf(cleanupPoliciesProp)) && (ok || !reflect.DeepEqual(v, cleanupPoliciesProp)) {
obj["cleanupPolicies"] = cleanupPoliciesProp
}
remoteRepositoryConfigProp, err := expandArtifactRegistryRepositoryRemoteRepositoryConfig(d.Get("remote_repository_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("remote_repository_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(remoteRepositoryConfigProp)) && (ok || !reflect.DeepEqual(v, remoteRepositoryConfigProp)) {
obj["remoteRepositoryConfig"] = remoteRepositoryConfigProp
}
cleanupPolicyDryRunProp, err := expandArtifactRegistryRepositoryCleanupPolicyDryRun(d.Get("cleanup_policy_dry_run"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("cleanup_policy_dry_run"); !tpgresource.IsEmptyValue(reflect.ValueOf(cleanupPolicyDryRunProp)) && (ok || !reflect.DeepEqual(v, cleanupPolicyDryRunProp)) {
obj["cleanupPolicyDryRun"] = cleanupPolicyDryRunProp
}
vulnerabilityScanningConfigProp, err := expandArtifactRegistryRepositoryVulnerabilityScanningConfig(d.Get("vulnerability_scanning_config"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("vulnerability_scanning_config"); !tpgresource.IsEmptyValue(reflect.ValueOf(vulnerabilityScanningConfigProp)) && (ok || !reflect.DeepEqual(v, vulnerabilityScanningConfigProp)) {
obj["vulnerabilityScanningConfig"] = vulnerabilityScanningConfigProp
}
labelsProp, err := expandArtifactRegistryRepositoryEffectiveLabels(d.Get("effective_labels"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("effective_labels"); !tpgresource.IsEmptyValue(reflect.ValueOf(labelsProp)) && (ok || !reflect.DeepEqual(v, labelsProp)) {
obj["labels"] = labelsProp
}
obj, err = resourceArtifactRegistryRepositoryEncoder(d, meta, obj)
if err != nil {
return err
}
url, err := tpgresource.ReplaceVars(d, config, "{{ArtifactRegistryBasePath}}projects/{{project}}/locations/{{location}}/repositories?repository_id={{repository_id}}")
if err != nil {
return err
}
log.Printf("[DEBUG] Creating new Repository: %#v", obj)
billingProject := ""
project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Repository: %s", err)
}
billingProject = project
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}
headers := make(http.Header)
// This file should be deleted in the next major terraform release, alongside
// the default values for 'publicRepository'.
// deletePublicRepoIfCustom deletes the publicRepository key for a given
// pkg type from the remote repository config if customRepository is set.
deletePublicRepoIfCustom := func(pkgType string) {
if _, ok := d.GetOk(fmt.Sprintf("remote_repository_config.0.%s_repository.0.custom_repository", pkgType)); ok {
rrcfg := obj["remoteRepositoryConfig"].(map[string]interface{})
repo := rrcfg[fmt.Sprintf("%sRepository", pkgType)].(map[string]interface{})
delete(repo, "publicRepository")
}
}
// Call above func for all pkg types that support custom remote repos.
deletePublicRepoIfCustom("docker")
deletePublicRepoIfCustom("maven")
deletePublicRepoIfCustom("npm")
deletePublicRepoIfCustom("python")
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: config,
Method: "POST",
Project: billingProject,
RawURL: url,
UserAgent: userAgent,
Body: obj,
Timeout: d.Timeout(schema.TimeoutCreate),
Headers: headers,
})
if err != nil {
return fmt.Errorf("Error creating Repository: %s", err)
}
// Store the ID now
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
// Use the resource in the operation response to populate
// identity fields and d.Id() before read
var opRes map[string]interface{}
err = ArtifactRegistryOperationWaitTimeWithResponse(
config, res, &opRes, project, "Creating Repository", userAgent,
d.Timeout(schema.TimeoutCreate))
if err != nil {
// The resource didn't actually create
d.SetId("")
return fmt.Errorf("Error waiting to create Repository: %s", err)
}
if err := d.Set("name", flattenArtifactRegistryRepositoryName(opRes["name"], d, config)); err != nil {
return err
}
// This may have caused the ID to update - update it if so.
id, err = tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}")
if err != nil {
return fmt.Errorf("Error constructing id: %s", err)
}
d.SetId(id)
log.Printf("[DEBUG] Finished creating Repository %q: %#v", d.Id(), res)
return resourceArtifactRegistryRepositoryRead(d, meta)
}
func resourceArtifactRegistryRepositoryRead(d *schema.ResourceData, meta interface{}) error {
config := meta.(*transport_tpg.Config)
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
if err != nil {
return err
}
url, err := tpgresource.ReplaceVars(d, config, "{{ArtifactRegistryBasePath}}projects/{{project}}/locations/{{location}}/repositories/{{repository_id}}")
if err != nil {
return err
}
billingProject := ""
project, err := tpgresource.GetProject(d, config)
if err != nil {
return fmt.Errorf("Error fetching project for Repository: %s", err)
}
billingProject = project
// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
billingProject = bp
}