-
Notifications
You must be signed in to change notification settings - Fork 54
/
Copy pathresources.go
2926 lines (2779 loc) · 118 KB
/
resources.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 2016-2018, Pulumi Corporation. All rights reserved.
package gcp
import (
"context"
"fmt"
"log"
"path"
"strings"
"sync/atomic"
"unicode"
// Allow embedding metadata in the provider
_ "embed"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
gcpPFProvider "github.com/hashicorp/terraform-provider-google-beta/google-beta/fwprovider"
gcpProvider "github.com/hashicorp/terraform-provider-google-beta/google-beta/provider"
tpg_transport "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"google.golang.org/api/compute/v1"
"google.golang.org/api/option"
pf "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/pf/tfbridge"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge"
info "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/info"
tks "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfbridge/tokens"
shim "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim"
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/walk"
"github.com/pulumi/pulumi/pkg/v3/resource/provider"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/resource"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/pulumi/pulumi-gcp/provider/v8/pkg/version"
)
// all of the Google Cloud Platform token components used below.
const (
// packages:
gcpPackage = "gcp"
// modules; in general, we took naming inspiration from the Google Cloud SDK for Go:
// https://github.com/GoogleCloudPlatform/google-cloud-go
gcpAccessApproval = "AccessApproval" // Access Approval resources
gcpAccessContextManager = "AccessContextManager" // Access Context Manager resources
gcpActiveDirectory = "ActiveDirectory" // Active Directory resources
gcpAlloydb = "Alloydb" // Alloydb resources
// nolint:revive
gcpApiGateway = "ApiGateway" // ApiGateway resources
gcpApigee = "Apigee" // Apigee resources
gcpAppEngine = "AppEngine" // AppEngine resources
gcpApplicationIntegration = "ApplicationIntegration" // Application Integration
gcpArtifactRegistry = "ArtifactRegistry" // ArtifactRegistry resources
gcpAssuredWorkloads = "AssuredWorkloads" // AssuredWorkloads resources
gcpBackupDR = "BackupDisasterRecovery" // Backup and Disaster Recovery resources
gcpBeyondcorp = "Beyondcorp" // Beyondcorp resources
gcpBigLake = "BigLake" // BigLake resources
gcpBigQuery = "BigQuery" // BigQuery resources
gcpBigQueryAnalyticsHub = "BigQueryAnalyticsHub" // BigQuery Analytics Hub resources
gcpBigQueryDataPolicy = "BigQueryDataPolicy" // BigQuery Data Policy resources
gcpBigTable = "BigTable" // BitTable resources
gcpBilling = "Billing" // Billing resources
gcpBinaryAuthorization = "BinaryAuthorization" // Binary Authorization resources
gcpBlockchainNodeEngine = "BlockchainNodeEngine" // Blockchain Node Engine resources
gcpCertificateAuthority = "CertificateAuthority" // CertificateAuthority resources
gcpCertificateManager = "CertificateManager" // CertificateManager resources
gcpCloudAsset = "CloudAsset" // CloudAsset resources
gcpCloudBuild = "CloudBuild" // CloudBuild resources
gcpCloudBuildV2 = "CloudBuildV2" // CloudBuild (2nd Gen) resources
gcpCloudDeploy = "CloudDeploy" // CloudDeploy resources
gcpCloudFunctions = "CloudFunctions" // CloudFunction resources
gcpCloudFunctionsV2 = "CloudFunctionsV2" // CloudFunction (2nd Gen) resources
gcpCloudIdentity = "CloudIdentity" // CloudIdentity resources
gcpCloudIDs = "CloudIds" // CloudIds resources
gcpCloudRun = "CloudRun" // CloudRun resources
gcpCloudRunV2 = "CloudRunV2" // CloudRun (2nd Gen) resources
gcpCloudScheduler = "CloudScheduler" // Cloud Scheduler resources
gcpCloudTasks = "CloudTasks" // Cloud Tasks resources
gcpComposer = "Composer" // Cloud Composer resources
gcpCompute = "Compute" // Compute resources
gcpContainerAnalysis = "ContainerAnalysis" // Container Analysis resources
gcpDNS = "Dns" // DNS resources
gcpDeveloperConnect = "DeveloperConnect" // Developer Connect
gcpDataCatalog = "DataCatalog" // Data Catalog resources
gcpDataFlow = "Dataflow" // DataFlow resources
gcpDataFusion = "DataFusion" // DataFusion resources
gcpDataLoss = "DataLoss" // DataLoss resources
gcpDataPlex = "DataPlex" // DataPlex
gcpDataProc = "Dataproc" // DataProc resources
gcpDatabaseMigrationService = "DatabaseMigrationService" // Database Migration Service resources
gcpDataform = "Dataform" // Dataform resources
gcpDatastore = "Datastore" // Datastore resources
gcpDatastream = "Datastream" // Datastream resources
gcpDeploymentManager = "DeploymentManager" // DeploymentManager resources
gcpDiagflow = "Diagflow" // Diagflow resources
gcpDiscoveryEngine = "DiscoveryEngine" // Discovery Engine
gcpEdgeNetwork = "EdgeNetwork" // Distributed Cloud Edge Network resources
gcpEdgecontainer = "EdgeContainer" // Cloud Edge Container resources
gcpEndPoints = "Endpoints" // End Point resources
gcpEssentialContacts = "EssentialContacts" // Essential Contacts resources
gcpEventarc = "Eventarc" // Eventarc
gcpFilestore = "Filestore" // Filestore resources
gcpFirebase = "Firebase" // Firebase resources
gcpFirebaserules = "Firebaserules" // FirebaseRules resources
gcpFirestore = "Firestore" // Firestore resources
gcpFolder = "Folder" // Folder resources
gcpGameServices = "GameServices" // Game Services resources
gcpGkeBackup = "GkeBackup" // Gke Backup resources
gcpGkeHub = "GkeHub" // Gke Hub resources
gcpGkeOnPrem = "GkeOnPrem" // Gke On Prem resources
gcpHealthcare = "Healthcare" // Healthcare resources
gcpIAM = "Iam" // IAM resources
gcpIAP = "Iap" // IAP resources
gcpIdentityPlatform = "IdentityPlatform" // IdentityPlatform resources
gcpIntegrationConnectors = "IntegrationConnectors" // Integration Connectors resources
gcpIot = "Iot" // Iot resources
gcpKMS = "Kms" // KMS resources
gcpKubernetes = "Container" // Kubernetes Engine resources
gcpLogging = "Logging" // Logging resources
gcpLooker = "Looker" // Looker resources
gcpMachingLearning = "ML" // Machine Learning
gcpManagedKafka = "ManagedKafka" // Managed Kafka
gcpMemcache = "Memcache" // Memcache resources
gcpMemorystore = "MemoryStore" // Memory Store
gcpMigrationCenter = "MigrationCenter" // Migration Center
gcpMonitoring = "Monitoring" // Monitoring resources
gcpNetapp = "Netapp" // Netapp
gcpNetworkConnectivity = "NetworkConnectivity" // Network Connectivity resources
gcpNetworkManagement = "NetworkManagement" // Network Management resources
gcpNetworkSecurity = "NetworkSecurity" // Network Security resources
gcpNetworkServices = "NetworkServices" // Network Services resources
gcpNotebooks = "Notebooks" // Notebooks resources
gcpOracleDatabase = "OracleDatabase" // Oracle Database
gcpOrgPolicy = "OrgPolicy" // Org Policy
gcpOrganization = "Organizations" // Organization resources
gcpOsConfig = "OsConfig" // OsConfig resources
gcpOsLogin = "OsLogin" // OsLogin resources
gcpParallelStore = "ParallelStore" // ParallelStore resources
gcpPrivilegedAccessManager = "PrivilegedAccessManager" // Privileged Access Manager
gcpProject = "Projects" // Project resources
gcpPubSub = "PubSub" // PubSub resources
gcpRecaptcha = "Recaptcha" // Recaptcha resources
gcpRedis = "Redis" // Redis resources
gcpResourceManager = "ResourceManager" // Resource Manager resources
gcpRuntimeConfig = "RuntimeConfig" // Runtime Config resources
gcpSQL = "Sql" // SQL resources
gcpSecretManager = "SecretManager" // Secret Manager resources
gcpSecureSourceManager = "SecureSourceManager" // Secure Source Manager
gcpSecurityCenter = "SecurityCenter" // Security Center
gcpSecurityPosture = "SecurityPosture" // Security Posture
gcpServiceAccount = "ServiceAccount" // Service Account resources
gcpServiceDirectory = "ServiceDirectory" // Service Directory resources
gcpServiceNetworking = "ServiceNetworking" // Service Networking resources
gcpServiceUsage = "ServiceUsage" // Service Usage resources
gcpSiteVerification = "SiteVerification" // Site Verification
gcpSourceRepo = "SourceRepo" // Source Repo resources
gcpSpanner = "Spanner" // Spanner Resources
gcpStorage = "Storage" // Storage resources
gcpTPU = "Tpu" // Tensor Processing Units
gcpTags = "Tags" // Tags
gcpTranscoder = "Transcoder" // Transcoder
gcpVMwareEngine = "VMwareEngine" // VMWare Engine
gcpVertex = "Vertex" // Vertex
gcpVpcAccess = "VpcAccess" // VPC Access
gcpWorkbench = "Workbench" // Workbench
gcpWorkflows = "Workflows" // Workflows
gcpWorkstations = "Workstations" // Workstations
)
var moduleMapping = map[string]string{
"access_approval": gcpAccessApproval,
"access_context_manager": gcpAccessContextManager,
"active_directory": gcpActiveDirectory,
"alloydb": gcpAlloydb,
"api_gateway": gcpApiGateway,
"apigee": gcpApigee,
"app_engine": gcpAppEngine,
"apphub": "Apphub",
"artifact_registry": gcpArtifactRegistry,
"assured_workloads": gcpAssuredWorkloads,
"backup_dr": gcpBackupDR,
"beyondcorp": gcpBeyondcorp,
"biglake": gcpBigLake,
"bigquery": gcpBigQuery,
"integrations": gcpApplicationIntegration,
"bigquery_analytics_hub": gcpBigQueryAnalyticsHub,
"bigquery_datapolicy_data_policy": gcpBigQueryDataPolicy,
"bigtable": gcpBigTable,
"billing": gcpBilling,
"blockchain_node_engine": gcpBlockchainNodeEngine,
"binary_authorization": gcpBinaryAuthorization,
"certificate_manager": gcpCertificateManager,
"cloud_asset": gcpCloudAsset,
"cloud_identity": gcpCloudIdentity,
"cloud_ids": gcpCloudIDs,
"cloud_quota": "CloudQuota",
"cloud_run": gcpCloudRun,
"cloud_run_v2": gcpCloudRunV2,
"cloud_scheduler": gcpCloudScheduler,
"cloud_tasks": gcpCloudTasks,
"cloudbuild": gcpCloudBuild,
"cloudbuildv2": gcpCloudBuildV2,
"clouddeploy": gcpCloudDeploy,
"clouddomains": "CloudDomains",
"cloudfunctions": gcpCloudFunctions,
"cloudfunctions2": gcpCloudFunctionsV2,
"cloudiot": gcpIot,
"composer": gcpComposer,
"compute": gcpCompute,
"container": gcpKubernetes,
"container_analysis": gcpContainerAnalysis,
"data_catalog": gcpDataCatalog,
"data_fusion": gcpDataFusion,
"data_loss": gcpDataLoss,
// Intentionally the same as "dataflow" since in Google's docs, data pipelines are nested under DataFlow.
"data_pipeline": gcpDataFlow,
"database_migration_service": gcpDatabaseMigrationService,
"dataflow": gcpDataFlow,
"dataform": gcpDataform,
"dataplex": gcpDataPlex,
"dataproc": gcpDataProc,
"datastore": gcpDatastore,
"datastream": gcpDatastream,
"deployment_manager": gcpDeploymentManager,
"developer_connect": gcpDeveloperConnect,
"dialogflow": gcpDiagflow,
"discovery_engine": gcpDiscoveryEngine,
"dns": gcpDNS,
"edgecontainer": gcpEdgecontainer,
"edgenetwork": gcpEdgeNetwork,
"endpoints": gcpEndPoints,
"essential_contacts": gcpEssentialContacts,
"eventarc": gcpEventarc,
"filestore": gcpFilestore,
"firebase": gcpFirebase,
"firebaserules": gcpFirebaserules,
"firestore": gcpFirestore,
"folder": gcpFolder,
"game_services": gcpGameServices,
"gke_backup": gcpGkeBackup,
"gke_hub": gcpGkeHub,
"gkeonprem": gcpGkeOnPrem,
"healthcare": gcpHealthcare,
"iam": gcpIAM,
"iap": gcpIAP,
"identity_platform": gcpIdentityPlatform,
"integration_connectors": gcpIntegrationConnectors,
"kms": gcpKMS,
"logging": gcpLogging,
"looker": gcpLooker,
"managed_kafka": gcpManagedKafka,
"memcache": gcpMemcache,
"memorystore": gcpMemorystore,
"migration_center": gcpMigrationCenter,
"ml": gcpMachingLearning,
"monitoring": gcpMonitoring,
"netapp": gcpNetapp,
"network_connectivity": gcpNetworkConnectivity,
"network_management": gcpNetworkManagement,
"network_security": gcpNetworkSecurity,
"network_services": gcpNetworkServices,
"notebooks": gcpNotebooks,
"org_policy": gcpOrgPolicy,
"oracle_database": gcpOracleDatabase,
"organization": gcpOrganization,
"os_config": gcpOsConfig,
"os_login": gcpOsLogin,
"parallelstore": gcpParallelStore,
"privateca": gcpCertificateAuthority,
"privileged_access_manager": gcpPrivilegedAccessManager,
"project": gcpProject,
"public": gcpCompute,
"pubsub": gcpPubSub,
"recaptcha": gcpRecaptcha,
"redis": gcpRedis,
"resource_manager": gcpResourceManager,
"runtimeconfig": gcpRuntimeConfig,
"scc": gcpSecurityCenter,
"secret_manager": gcpSecretManager,
"secure_source_manager": gcpSecureSourceManager,
"securityposture": gcpSecurityPosture,
"service_account": gcpServiceAccount,
"service_directory": gcpServiceDirectory,
"service_networking": gcpServiceNetworking,
"service_usage": gcpServiceUsage,
"site_verification": gcpSiteVerification,
"sourcerepo": gcpSourceRepo,
"spanner": gcpSpanner,
"sql": gcpSQL,
"storage": gcpStorage,
"tags": gcpTags,
"transcoder": gcpTranscoder,
"tpu": gcpTPU,
"vertex": gcpVertex,
"vmwareengine": gcpVMwareEngine,
"vpc_access": gcpVpcAccess,
"workbench": gcpWorkbench,
"workflows": gcpWorkflows,
"workstations": gcpWorkstations,
}
var namespaceMap = map[string]string{
"gcp": "Gcp",
}
// gcpMember manufactures a type token for the GCP package and the given module and
// type. It automatically uses the GCP package and names the file by simply lower
// casing the resource's first character.
func gcpMember(moduleTitle string, mem string) tokens.ModuleMember {
moduleName := strings.ToLower(moduleTitle)
namespaceMap[moduleName] = moduleTitle
fn := string(unicode.ToLower(rune(mem[0]))) + mem[1:]
token := moduleName + "/" + fn
return tokens.ModuleMember(gcpPackage + ":" + token + ":" + mem)
}
// gcpType manufactures a type token for the GCP package and the given module and type.
func gcpType(mod string, typ string) tokens.Type {
return tokens.Type(gcpMember(mod, typ))
}
// gcpDataSource manufactures a standard member given a module and resource name.
func gcpDataSource(mod string, res string) tokens.ModuleMember {
return gcpMember(mod, res)
}
// gcpResource manufactures a standard resource token given a module and resource name.
func gcpResource(mod string, res string) tokens.Type {
return gcpType(mod, res)
}
// lowercaseAutoName provides a schema info with autonaming set to lowercase names
// for resources that don't support capital casing in names. This seems to be the
// case for many resources where a name ends up being in HTTP URLs.
func lowercaseAutoName() *tfbridge.SchemaInfo {
return tfbridge.AutoNameWithCustomOptions("name", tfbridge.AutoNameOptions{
Separator: "-",
Maxlen: 63,
Randlen: 7,
Transform: strings.ToLower,
})
}
func nameField(info *tfbridge.SchemaInfo) map[string]*tfbridge.SchemaInfo {
return map[string]*tfbridge.SchemaInfo{
"name": info,
}
}
func getRegionsList(ctx context.Context, project string, clientOpts []option.ClientOption) ([]string, error) {
computeService, err := compute.NewService(ctx, clientOpts...)
if err != nil {
return nil, fmt.Errorf("failed to create compute service: %w", err)
}
regionsService := compute.NewRegionsService(computeService)
regionList, err := regionsService.List(project).Do()
if err != nil {
return nil, fmt.Errorf("failed to list regions: %w", err)
}
var regions []string
for _, region := range regionList.Items {
regions = append(regions, region.Name)
}
return regions, nil
}
//go:embed errors/no_credentials.txt
var noCredentialsErr string
//go:embed errors/wrong_region.txt
var wrongRegionErr string
//go:embed errors/no_project.txt
var noProjectErr string
func logOrPrint(ctx context.Context, host *provider.HostClient, msg string) {
// host is unavailable in tests, so we revert to normal logging.
if host != nil {
// the URN will default to the root stack name which is exactly what we want
_ = host.Log(ctx, diag.Warning, "", msg)
} else {
log.Print(msg)
}
}
// gcpClientOpts is used to pass in options during testing.
func preConfigureCallbackWithLogger(credentialsValidationRun *atomic.Bool, gcpClientOpts []option.ClientOption) func(
ctx context.Context, host *provider.HostClient, vars resource.PropertyMap, c shim.ResourceConfig,
) error {
return func(ctx context.Context, host *provider.HostClient, vars resource.PropertyMap, _ shim.ResourceConfig) error {
if !credentialsValidationRun.CompareAndSwap(false, true) {
return nil
}
project := tfbridge.ConfigStringValue(vars, "project", []string{
"GOOGLE_PROJECT",
"GOOGLE_CLOUD_PROJECT",
"GCLOUD_PROJECT",
"CLOUDSDK_CORE_PROJECT",
})
if project == "" {
logOrPrint(ctx, host, noProjectErr)
return nil
}
config := tpg_transport.Config{
AccessToken: tfbridge.ConfigStringValue(vars,
"accessToken", []string{"GOOGLE_OAUTH_ACCESS_TOKEN"}),
Credentials: tfbridge.ConfigStringValue(vars, "credentials", []string{
"GOOGLE_CREDENTIALS",
"GOOGLE_CLOUD_KEYFILE_JSON",
"GCLOUD_KEYFILE_JSON",
}),
ImpersonateServiceAccount: tfbridge.ConfigStringValue(vars,
"impersonateServiceAccount", []string{"GOOGLE_IMPERSONATE_SERVICE_ACCOUNT"}),
Project: tfbridge.ConfigStringValue(vars, "project", []string{
"GOOGLE_PROJECT",
"GOOGLE_CLOUD_PROJECT",
"GCLOUD_PROJECT",
"CLOUDSDK_CORE_PROJECT",
}),
Region: tfbridge.ConfigStringValue(vars, "region", []string{
"GOOGLE_REGION",
"GCLOUD_REGION",
"CLOUDSDK_COMPUTE_REGION",
}),
Zone: tfbridge.ConfigStringValue(vars, "zone", []string{
"GOOGLE_ZONE",
"GCLOUD_ZONE",
"CLOUDSDK_COMPUTE_ZONE",
}),
}
// validate the gcloud config
err := config.LoadAndValidate(ctx)
if err != nil {
return fmt.Errorf(noCredentialsErr, err)
}
skipRegionValidation := tfbridge.ConfigBoolValue(
vars, "skipRegionValidation", []string{"PULUMI_GCP_SKIP_REGION_VALIDATION"},
)
if !skipRegionValidation && config.Region != "" && config.Project != "" {
regionList, err := getRegionsList(ctx, config.Project, gcpClientOpts)
if err != nil {
logOrPrint(ctx, host, fmt.Sprintf("failed to get regions list: %v", err))
return nil
}
for _, region := range regionList {
if region == config.Region {
return nil
}
}
logOrPrint(ctx, host, fmt.Sprintf(wrongRegionErr, config.Region, config.Project))
}
return nil
}
}
//go:embed cmd/pulumi-resource-gcp/bridge-metadata.json
var metadata []byte
// Provider returns additional overlaid schema and metadata associated with the gcp package.
//
//nolint:lll
func Provider() tfbridge.ProviderInfo {
p := pf.MuxShimWithDisjointgPF(
context.Background(),
shimv2.NewProvider(gcpProvider.Provider(),
shimv2.WithPlanStateEdit(fixEmptyLabels),
),
gcpPFProvider.New())
// We should only run the validation once to avoid duplicating the reported errors.
var credentialsValidationRun atomic.Bool
prov := tfbridge.ProviderInfo{
P: p,
Name: "google-beta",
ResourcePrefix: "google",
GitHubOrg: "hashicorp",
Description: "A Pulumi package for creating and managing Google Cloud Platform resources.",
Keywords: []string{"pulumi", "gcp"},
License: "Apache-2.0",
Homepage: "https://pulumi.io",
Repository: "https://github.com/pulumi/pulumi-gcp",
Version: version.Version,
MetadataInfo: tfbridge.NewProviderMetadata(metadata),
UpstreamRepoPath: "./upstream",
DocRules: &tfbridge.DocRuleInfo{EditRules: editRules},
Config: map[string]*tfbridge.SchemaInfo{
"project": {
Default: &tfbridge.DefaultInfo{
EnvVars: []string{
"GOOGLE_PROJECT",
"GOOGLE_CLOUD_PROJECT",
"GCLOUD_PROJECT",
"CLOUDSDK_CORE_PROJECT",
},
},
},
"region": {
Default: &tfbridge.DefaultInfo{
EnvVars: []string{
"GOOGLE_REGION",
"GCLOUD_REGION",
"CLOUDSDK_COMPUTE_REGION",
},
},
},
"zone": {
Default: &tfbridge.DefaultInfo{
EnvVars: []string{
"GOOGLE_ZONE",
"GCLOUD_ZONE",
"CLOUDSDK_COMPUTE_ZONE",
},
},
},
"access_token": {
Secret: tfbridge.True(),
},
"add_terraform_attribution_label": {
Name: "addPulumiAttributionLabel",
},
"terraform_attribution_label_addition_strategy": {
Name: "pulumiAttributionLabelAdditionStrategy",
},
},
ExtraConfig: map[string]*tfbridge.ConfigInfo{
"skipRegionValidation": {
Schema: shimv2.NewSchema(&schema.Schema{
Type: schema.TypeBool,
Optional: true,
}),
Info: &tfbridge.SchemaInfo{
Default: &tfbridge.DefaultInfo{
Value: false,
EnvVars: []string{"PULUMI_GCP_SKIP_REGION_VALIDATION"},
},
},
},
},
PreConfigureCallbackWithLogger: preConfigureCallbackWithLogger(&credentialsValidationRun, nil),
Resources: map[string]*tfbridge.ResourceInfo{
// Access Context Manager
"google_access_context_manager_access_level": {
Tok: gcpResource(gcpAccessContextManager, "AccessLevel"),
},
"google_access_context_manager_access_policy": {
Tok: gcpResource(gcpAccessContextManager, "AccessPolicy"),
},
"google_access_context_manager_service_perimeter": {
Tok: gcpResource(gcpAccessContextManager, "ServicePerimeter"),
},
"google_access_context_manager_service_perimeter_resource": {
Tok: gcpResource(gcpAccessContextManager, "ServicePerimeterResource"),
},
"google_access_context_manager_service_perimeters": {
Tok: gcpResource(gcpAccessContextManager, "ServicePerimeters"),
Fields: map[string]*tfbridge.SchemaInfo{
"service_perimeters": {
CSharpName: "ServicePerimeterDetails",
},
},
},
"google_access_context_manager_access_levels": {
Tok: gcpResource(gcpAccessContextManager, "AccessLevels"),
Fields: map[string]*tfbridge.SchemaInfo{
"access_levels": {
CSharpName: "AccessLevelDetails",
},
},
},
"google_access_context_manager_access_level_condition": {
Tok: gcpResource(gcpAccessContextManager, "AccessLevelCondition"),
},
"google_access_context_manager_gcp_user_access_binding": {
Tok: gcpResource(gcpAccessContextManager, "GcpUserAccessBinding"),
},
"google_access_context_manager_authorized_orgs_desc": {
Tok: gcpResource(gcpAccessContextManager, "AuthorizedOrgsDesc"),
},
"google_access_context_manager_ingress_policy": {
Tok: gcpResource(gcpAccessContextManager, "IngressPolicy"),
},
// Alloydb
"google_alloydb_backup": {Tok: gcpResource(gcpAlloydb, "Backup")},
"google_alloydb_cluster": {Tok: gcpResource(gcpAlloydb, "Cluster")},
"google_alloydb_instance": {Tok: gcpResource(gcpAlloydb, "Instance")},
// AppEngine
"google_app_engine_application": {Tok: gcpResource(gcpAppEngine, "Application")},
"google_app_engine_firewall_rule": {
Tok: gcpResource(gcpAppEngine, "FirewallRule"),
Docs: &tfbridge.DocInfo{
Source: "appengine_firewall_rule.html.markdown",
},
},
"google_app_engine_standard_app_version": {Tok: gcpResource(gcpAppEngine, "StandardAppVersion")},
"google_app_engine_domain_mapping": {Tok: gcpResource(gcpAppEngine, "DomainMapping")},
"google_app_engine_application_url_dispatch_rules": {
Tok: gcpResource(gcpAppEngine, "ApplicationUrlDispatchRules"),
},
"google_app_engine_service_split_traffic": {Tok: gcpResource(gcpAppEngine, "EngineSplitTraffic")},
// BigQuery Data Policy
"google_bigquery_datapolicy_data_policy": {Tok: gcpResource(gcpBigQueryDataPolicy, "DataPolicy")},
"google_bigquery_datapolicy_data_policy_iam_binding": {
Tok: gcpResource(gcpBigQueryDataPolicy, "DataPolicyIamBinding"),
Docs: &tfbridge.DocInfo{
Source: "bigquery_datapolicy_data_policy_iam.html.markdown",
},
},
"google_bigquery_datapolicy_data_policy_iam_member": {
Tok: gcpResource(gcpBigQueryDataPolicy, "DataPolicyIamMember"),
Docs: &tfbridge.DocInfo{
Source: "bigquery_datapolicy_data_policy_iam.html.markdown",
},
},
"google_bigquery_datapolicy_data_policy_iam_policy": {
Tok: gcpResource(gcpBigQueryDataPolicy, "DataPolicyIamPolicy"),
Docs: &tfbridge.DocInfo{
Source: "bigquery_datapolicy_data_policy_iam.html.markdown",
},
},
// BigQuery
// Note: the TF type token says bigtable (not bigquery) so this token cannot be auto-mapped.
"google_bigtable_app_profile": {Tok: gcpResource(gcpBigQuery, "AppProfile")},
"google_bigquery_dataset_access": {
Tok: gcpResource(gcpBigQuery, "DatasetAccess"),
// The upstream provider has nested attributes, both called "dataset", which causes a panic in the
// bridge due to the duplicated names. In order to resolve the panic (and also to clarify the meaning of
// the field), we use the name "authorizedDataset", which is derived from the title of the example code
// in the upstream docs:
// https://registry.terraform.io/providers/hashicorp/google-beta/latest/docs/resources/bigquery_dataset_access#example-usage---bigquery-dataset-access-authorized-dataset
Fields: map[string]*tfbridge.SchemaInfo{
"dataset": {
Name: "authorizedDataset",
},
},
},
"google_bigquery_table_iam_policy": {
Tok: gcpResource(gcpBigQuery, "IamPolicy"),
Docs: &tfbridge.DocInfo{
Source: "bigquery_table_iam.html.markdown",
},
},
"google_bigquery_table_iam_binding": {
Tok: gcpResource(gcpBigQuery, "IamBinding"),
Docs: &tfbridge.DocInfo{
Source: "bigquery_table_iam.html.markdown",
},
},
"google_bigquery_table_iam_member": {
Tok: gcpResource(gcpBigQuery, "IamMember"),
Docs: &tfbridge.DocInfo{
Source: "bigquery_table_iam.html.markdown",
},
},
"google_bigquery_routine": {Tok: gcpResource(gcpBigQuery, "Routine")},
"google_bigquery_reservation_assignment": {Tok: gcpResource(gcpBigQuery, "ReservationAssignment")},
"google_bigquery_capacity_commitment": {
Tok: gcpResource(gcpBigQuery, "CapacityCommitment"),
},
// BigTable
"google_bigtable_gc_policy": {
Tok: gcpResource(gcpBigTable, "GCPolicy"),
Docs: &tfbridge.DocInfo{
Source: "bigtable_gc_policy.html.markdown",
},
},
// Billing
"google_billing_subaccount": {Tok: gcpResource(gcpBilling, "SubAccount")},
// Binary Authorization
"google_binary_authorization_attestor": {
Tok: gcpResource(gcpBinaryAuthorization, "Attestor"),
Docs: &tfbridge.DocInfo{
Source: "binaryauthorization_attestor.html.markdown",
},
},
"google_binary_authorization_policy": {
Tok: gcpResource(gcpBinaryAuthorization, "Policy"),
Docs: &tfbridge.DocInfo{
Source: "binaryauthorization_policy.html.markdown",
},
},
// Cloud Build
"google_cloudbuild_trigger": {
Tok: gcpResource(gcpCloudBuild, "Trigger"),
Docs: &tfbridge.DocInfo{
Source: "cloud_build_trigger.html.markdown",
},
},
// Cloud Build V2
"google_cloudbuildv2_connection_iam_binding": {
Tok: gcpResource(gcpCloudBuildV2, "ConnectionIAMBinding"),
Docs: &tfbridge.DocInfo{
Source: "cloudbuildv2_connection_iam.html.markdown",
},
},
"google_cloudbuildv2_connection_iam_member": {
Tok: gcpResource(gcpCloudBuildV2, "ConnectionIAMMember"),
Docs: &tfbridge.DocInfo{
Source: "cloudbuildv2_connection_iam.html.markdown",
},
},
"google_cloudbuildv2_connection_iam_policy": {
Tok: gcpResource(gcpCloudBuildV2, "ConnectionIAMPolicy"),
Docs: &tfbridge.DocInfo{
Source: "cloudbuildv2_connection_iam.html.markdown",
},
},
// Cloud Functions
"google_cloudfunctions_function": {
Tok: gcpResource(gcpCloudFunctions, "Function"),
Fields: map[string]*tfbridge.SchemaInfo{
// Name must start with a letter followed by up to 62 letters, numbers, or
// hyphens, and cannot end with a hyphen
"name": tfbridge.AutoName("name", 63, "-"),
},
},
// Core functions
"google_folder": {
Tok: gcpResource(gcpOrganization, "Folder"),
Docs: &tfbridge.DocInfo{
Source: "google_folder.html.markdown",
},
},
"google_folder_iam_binding": {
Tok: gcpResource(gcpFolder, "IAMBinding"),
Docs: &tfbridge.DocInfo{
Source: "google_folder_iam.html.markdown",
},
},
"google_folder_iam_member": {
Tok: gcpResource(gcpFolder, "IAMMember"),
Docs: &tfbridge.DocInfo{
Source: "google_folder_iam.html.markdown",
},
},
"google_folder_iam_policy": {
Tok: gcpResource(gcpFolder, "IAMPolicy"),
Docs: &tfbridge.DocInfo{
Source: "google_folder_iam.html.markdown",
},
},
"google_folder_organization_policy": {
Tok: gcpResource(gcpFolder, "OrganizationPolicy"),
Docs: &tfbridge.DocInfo{
Source: "google_folder_organization_policy.html.markdown",
},
},
"google_folder_iam_audit_config": {
Tok: gcpResource(gcpFolder, "IamAuditConfig"),
Docs: &tfbridge.DocInfo{
Source: "google_folder_iam.html.markdown",
},
},
"google_organization_policy": {
Tok: gcpResource(gcpOrganization, "Policy"),
Docs: &tfbridge.DocInfo{
Source: "google_organization_policy.html.markdown",
},
},
"google_organization_iam_binding": {
Tok: gcpResource(gcpOrganization, "IAMBinding"),
Docs: &tfbridge.DocInfo{
Source: "google_organization_iam.html.markdown",
},
},
"google_organization_iam_custom_role": {
Tok: gcpResource(gcpOrganization, "IAMCustomRole"),
Fields: map[string]*tfbridge.SchemaInfo{
"role_id": info.AutoName("", 255, "-"),
},
Docs: &tfbridge.DocInfo{
Source: "google_organization_iam_custom_role.html.markdown",
},
},
"google_organization_iam_member": {
Tok: gcpResource(gcpOrganization, "IAMMember"),
Docs: &tfbridge.DocInfo{
Source: "google_organization_iam.html.markdown",
},
},
"google_organization_iam_policy": {
Tok: gcpResource(gcpOrganization, "IAMPolicy"),
Docs: &tfbridge.DocInfo{
Source: "google_organization_iam.html.markdown",
},
},
"google_organization_iam_audit_config": {
Tok: gcpResource(gcpOrganization, "IamAuditConfig"),
Docs: &tfbridge.DocInfo{
Source: "google_organization_iam.html.markdown",
},
},
"google_organization_access_approval_settings": {
Tok: gcpResource(gcpOrganization, "AccessApprovalSettings"),
},
"google_project": {
Tok: gcpResource(gcpOrganization, "Project"),
Fields: map[string]*tfbridge.SchemaInfo{
// A project ID is a unique string used to differentiate your project from all
// others in Google Cloud. After you enter a project name, the Google Cloud
// console generates a unique project ID that can be a combination of letters,
// numbers, and hyphens. We recommend you use the generated project ID, but you
// can edit it during project creation. After the project has been created, the
// project ID is permanent.
//
// A project ID has the following requirements:
//
// - Must be 6 to 30 characters in length.
// - Can only contain lowercase letters, numbers, and hyphens.
// - Must start with a letter.
// - Cannot end with a hyphen.
// - Cannot be in use or previously used; this includes deleted projects.
// - Cannot contain restricted strings, such as google, null, undefined, and ssl.
//
// From https://cloud.google.com/resource-manager/docs/creating-managing-projects
"project_id": tfbridge.AutoNameWithCustomOptions("",
tfbridge.AutoNameOptions{
Separator: "-",
Maxlen: 30,
Randlen: 7,
Transform: strings.ToLower,
}),
"name": tfbridge.AutoNameWithCustomOptions("name",
// Name is auto-named without any suffix.
tfbridge.AutoNameOptions{Randlen: 0}),
},
Docs: &tfbridge.DocInfo{
Source: "google_project.html.markdown",
},
},
"google_project_iam_audit_config": {
Tok: gcpResource(gcpProject, "IAMAuditConfig"),
Docs: &tfbridge.DocInfo{
Source: "google_project_iam.html.markdown",
},
},
"google_project_iam_binding": {
Tok: gcpResource(gcpProject, "IAMBinding"),
Docs: &tfbridge.DocInfo{
Source: "google_project_iam.html.markdown",
},
},
"google_project_iam_custom_role": {
Tok: gcpResource(gcpProject, "IAMCustomRole"),
Fields: map[string]*tfbridge.SchemaInfo{
"role_id": info.AutoName("", 255, "-"),
},
Docs: &tfbridge.DocInfo{
Source: "google_project_iam_custom_role.html.markdown",
},
},
"google_project_iam_member": {
Tok: gcpResource(gcpProject, "IAMMember"),
Docs: &tfbridge.DocInfo{
Source: "google_project_iam.html.markdown",
},
DeleteBeforeReplace: true,
},
"google_project_iam_policy": {
Tok: gcpResource(gcpProject, "IAMPolicy"),
Docs: &tfbridge.DocInfo{
Source: "google_project_iam.html.markdown",
},
DeleteBeforeReplace: true,
},
"google_project_organization_policy": {
Tok: gcpResource(gcpProject, "OrganizationPolicy"),
Docs: &tfbridge.DocInfo{
Source: "google_project_organization_policy.html.markdown",
},
},
"google_project_service": {
Tok: gcpResource(gcpProject, "Service"),
Docs: &tfbridge.DocInfo{
Source: "google_project_service.html.markdown",
},
Fields: map[string]*tfbridge.SchemaInfo{
"service": {
CSharpName: "ServiceName",
},
},
},
"google_project_usage_export_bucket": {
Tok: gcpResource(gcpProject, "UsageExportBucket"),
Docs: &tfbridge.DocInfo{
Source: "google_project.html.markdown",
},
},
"google_project_access_approval_settings": {
Tok: gcpResource(gcpProject, "AccessApprovalSettings"),
},
// This resource is in the root namespace in the TF provider at the time of writing. The GCP SDK does not
// give an obvious namespace choice either. Since an API key authenticates an application, we put it under
// the gcpProject module:
"google_apikeys_key": {Tok: gcpResource(gcpProject, "ApiKey")},
"google_service_account": {
Tok: gcpResource(gcpServiceAccount, "Account"),
Fields: map[string]*tfbridge.SchemaInfo{
"account_id": info.AutoName("", 30, "-"),
},
Docs: &tfbridge.DocInfo{
Source: "google_service_account.html.markdown",
},
},
"google_service_account_iam_binding": {
Tok: gcpResource(gcpServiceAccount, "IAMBinding"),
Docs: &tfbridge.DocInfo{
Source: "google_service_account_iam.html.markdown",
},
},
"google_service_account_iam_member": {
Tok: gcpResource(gcpServiceAccount, "IAMMember"),
Docs: &tfbridge.DocInfo{
Source: "google_service_account_iam.html.markdown",
},
},
"google_service_account_iam_policy": {
Tok: gcpResource(gcpServiceAccount, "IAMPolicy"),
Docs: &tfbridge.DocInfo{
Source: "google_service_account_iam.html.markdown",
},
},
"google_service_account_key": {
Tok: gcpResource(gcpServiceAccount, "Key"),
Docs: &tfbridge.DocInfo{
Source: "google_service_account_key.html.markdown",
},
},
// Service Usage
"google_service_usage_consumer_quota_override": {
Tok: gcpResource(gcpServiceUsage, "ConsumerQuotaOverride"),
},
// Compute
"google_compute_address": {
Tok: gcpResource(gcpCompute, "Address"),
Docs: &tfbridge.DocInfo{
Source: "compute_address.html.markdown",
},
Fields: map[string]*tfbridge.SchemaInfo{
"address": {
CSharpName: "IPAddress",
},
},
},
"google_compute_attached_disk": {
Tok: gcpResource(gcpCompute, "AttachedDisk"),
Docs: &tfbridge.DocInfo{
Source: "compute_attached_disk.html.markdown",
},
},
"google_compute_autoscaler": {
Tok: gcpResource(gcpCompute, "Autoscaler"),
Docs: &tfbridge.DocInfo{
Source: "compute_autoscaler.html.markdown",
},
},
"google_compute_backend_bucket": {
Tok: gcpResource(gcpCompute, "BackendBucket"),
Docs: &tfbridge.DocInfo{
Source: "compute_backend_bucket.html.markdown",
},
},
"google_compute_backend_bucket_signed_url_key": {
Tok: gcpResource(gcpCompute, "BackendBucketSignedUrlKey"),
Docs: &tfbridge.DocInfo{
Source: "compute_backend_bucket_signed_url_key.html.markdown",
},
},
"google_compute_backend_service": {
Docs: &tfbridge.DocInfo{
Source: "compute_backend_service.html.markdown",
},
Fields: nameField(lowercaseAutoName()),
},
"google_compute_backend_service_signed_url_key": {
Tok: gcpResource(gcpCompute, "BackendServiceSignedUrlKey"),
Docs: &tfbridge.DocInfo{