Skip to content

Commit

Permalink
Allow overriding the base path for a URL with custom endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
rileykarson authored and modular-magician committed Jun 10, 2019
1 parent 80df1bf commit ff6dadd
Show file tree
Hide file tree
Showing 147 changed files with 1,095 additions and 370 deletions.
257 changes: 194 additions & 63 deletions google/config.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion google/data_source_google_composer_image_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func dataSourceGoogleComposerImageVersionsRead(d *schema.ResourceData, meta inte
return err
}

url, err := replaceVars(d, config, "https://composer.googleapis.com/v1/projects/{{project}}/locations/{{region}}/imageVersions")
url, err := replaceVars(d, config, "{{ComposerBasePath}}projects/{{project}}/locations/{{region}}/imageVersions")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion google/data_source_tpu_tensorflow_versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func dataSourceTpuTensorFlowVersionsRead(d *schema.ResourceData, meta interface{
return err
}

url, err := replaceVars(d, config, "https://tpu.googleapis.com/v1/projects/{{project}}/locations/{{zone}}/tensorflowVersions")
url, err := replaceVars(d, config, "{{TpuBasePath}}projects/{{project}}/locations/{{zone}}/tensorflowVersions")
if err != nil {
return err
}
Expand Down
83 changes: 83 additions & 0 deletions google/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,54 @@ func Provider() terraform.ResourceProvider {
"CLOUDSDK_COMPUTE_ZONE",
}, nil),
},

"scopes": {
Type: schema.TypeList,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

// Generated Products
AccessContextManagerCustomEndpointEntryKey: AccessContextManagerCustomEndpointEntry,
AppEngineCustomEndpointEntryKey: AppEngineCustomEndpointEntry,
ComputeCustomEndpointEntryKey: ComputeCustomEndpointEntry,
CloudBuildCustomEndpointEntryKey: CloudBuildCustomEndpointEntry,
CloudSchedulerCustomEndpointEntryKey: CloudSchedulerCustomEndpointEntry,
DnsCustomEndpointEntryKey: DnsCustomEndpointEntry,
FilestoreCustomEndpointEntryKey: FilestoreCustomEndpointEntry,
FirestoreCustomEndpointEntryKey: FirestoreCustomEndpointEntry,
KmsCustomEndpointEntryKey: KmsCustomEndpointEntry,
PubsubCustomEndpointEntryKey: PubsubCustomEndpointEntry,
RedisCustomEndpointEntryKey: RedisCustomEndpointEntry,
ResourceManagerCustomEndpointEntryKey: ResourceManagerCustomEndpointEntry,
SourceRepoCustomEndpointEntryKey: SourceRepoCustomEndpointEntry,
SpannerCustomEndpointEntryKey: SpannerCustomEndpointEntry,
SqlCustomEndpointEntryKey: SqlCustomEndpointEntry,
StorageCustomEndpointEntryKey: StorageCustomEndpointEntry,
TpuCustomEndpointEntryKey: TpuCustomEndpointEntry,
MonitoringCustomEndpointEntryKey: MonitoringCustomEndpointEntry,

// Handwritten Products / Versioned / Atypical Entries
CloudBillingCustomEndpointEntryKey: CloudBillingCustomEndpointEntry,
ComposerCustomEndpointEntryKey: ComposerCustomEndpointEntry,
ComputeBetaCustomEndpointEntryKey: ComputeBetaCustomEndpointEntry,
ContainerCustomEndpointEntryKey: ContainerCustomEndpointEntry,
ContainerBetaCustomEndpointEntryKey: ContainerBetaCustomEndpointEntry,
DataprocCustomEndpointEntryKey: DataprocCustomEndpointEntry,
DataflowCustomEndpointEntryKey: DataflowCustomEndpointEntry,
DnsBetaCustomEndpointEntryKey: DnsBetaCustomEndpointEntry,
IamCredentialsCustomEndpointEntryKey: IamCredentialsCustomEndpointEntry,
LoggingCustomEndpointEntryKey: LoggingCustomEndpointEntry,
ResourceManagerV2Beta1CustomEndpointEntryKey: ResourceManagerV2Beta1CustomEndpointEntry,
RuntimeconfigCustomEndpointEntryKey: RuntimeconfigCustomEndpointEntry,
IAMCustomEndpointEntryKey: IAMCustomEndpointEntry,
ServiceManagementCustomEndpointEntryKey: ServiceManagementCustomEndpointEntry,
ServiceUsageCustomEndpointEntryKey: ServiceUsageCustomEndpointEntry,
BigQueryCustomEndpointEntryKey: BigQueryCustomEndpointEntry,
CloudFunctionsCustomEndpointEntryKey: CloudFunctionsCustomEndpointEntry,
CloudIoTCustomEndpointEntryKey: CloudIoTCustomEndpointEntry,
ServiceNetworkingCustomEndpointEntryKey: ServiceNetworkingCustomEndpointEntry,
StorageTransferCustomEndpointEntryKey: StorageTransferCustomEndpointEntry,
},

DataSourcesMap: map[string]*schema.Resource{
Expand Down Expand Up @@ -304,6 +347,46 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
config.Scopes[i] = scope.(string)
}

config.AccessContextManagerBasePath = d.Get(AccessContextManagerCustomEndpointEntryKey).(string)
config.AppEngineBasePath = d.Get(AppEngineCustomEndpointEntryKey).(string)
config.ComputeBasePath = d.Get(ComputeCustomEndpointEntryKey).(string)
config.CloudBuildBasePath = d.Get(CloudBuildCustomEndpointEntryKey).(string)
config.CloudSchedulerBasePath = d.Get(CloudSchedulerCustomEndpointEntryKey).(string)
config.DnsBasePath = d.Get(DnsCustomEndpointEntryKey).(string)
config.FilestoreBasePath = d.Get(FilestoreCustomEndpointEntryKey).(string)
config.FirestoreBasePath = d.Get(FirestoreCustomEndpointEntryKey).(string)
config.KmsBasePath = d.Get(KmsCustomEndpointEntryKey).(string)
config.PubsubBasePath = d.Get(PubsubCustomEndpointEntryKey).(string)
config.RedisBasePath = d.Get(RedisCustomEndpointEntryKey).(string)
config.ResourceManagerBasePath = d.Get(ResourceManagerCustomEndpointEntryKey).(string)
config.SourceRepoBasePath = d.Get(SourceRepoCustomEndpointEntryKey).(string)
config.SpannerBasePath = d.Get(SpannerCustomEndpointEntryKey).(string)
config.SqlBasePath = d.Get(SqlCustomEndpointEntryKey).(string)
config.StorageBasePath = d.Get(StorageCustomEndpointEntryKey).(string)
config.TpuBasePath = d.Get(TpuCustomEndpointEntryKey).(string)
config.MonitoringBasePath = d.Get(MonitoringCustomEndpointEntryKey).(string)

config.CloudBillingBasePath = d.Get(CloudBillingCustomEndpointEntryKey).(string)
config.ComposerBasePath = d.Get(ComposerCustomEndpointEntryKey).(string)
config.ComputeBetaBasePath = d.Get(ComputeBetaCustomEndpointEntryKey).(string)
config.ContainerBasePath = d.Get(ContainerCustomEndpointEntryKey).(string)
config.ContainerBetaBasePath = d.Get(ContainerBetaCustomEndpointEntryKey).(string)
config.DataprocBasePath = d.Get(DataprocCustomEndpointEntryKey).(string)
config.DataflowBasePath = d.Get(DataflowCustomEndpointEntryKey).(string)
config.DnsBetaBasePath = d.Get(DnsBetaCustomEndpointEntryKey).(string)
config.IamCredentialsBasePath = d.Get(IamCredentialsCustomEndpointEntryKey).(string)
config.LoggingBasePath = d.Get(LoggingCustomEndpointEntryKey).(string)
config.ResourceManagerV2Beta1BasePath = d.Get(ResourceManagerV2Beta1CustomEndpointEntryKey).(string)
config.RuntimeconfigBasePath = d.Get(RuntimeconfigCustomEndpointEntryKey).(string)
config.IAMBasePath = d.Get(IAMCustomEndpointEntryKey).(string)
config.ServiceManagementBasePath = d.Get(ServiceManagementCustomEndpointEntryKey).(string)
config.ServiceUsageBasePath = d.Get(ServiceUsageCustomEndpointEntryKey).(string)
config.BigQueryBasePath = d.Get(BigQueryCustomEndpointEntryKey).(string)
config.CloudFunctionsBasePath = d.Get(CloudFunctionsCustomEndpointEntryKey).(string)
config.CloudIoTBasePath = d.Get(CloudIoTCustomEndpointEntryKey).(string)
config.ServiceNetworkingBasePath = d.Get(ServiceNetworkingCustomEndpointEntryKey).(string)
config.StorageTransferBasePath = d.Get(StorageTransferCustomEndpointEntryKey).(string)

if err := config.LoadAndValidate(); err != nil {
return nil, err
}
Expand Down
11 changes: 11 additions & 0 deletions google/provider_access_context_manager_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var AccessContextManagerDefaultBasePath = "https://accesscontextmanager.googleapis.com/v1/"
var AccessContextManagerCustomEndpointEntryKey = "access_context_manager_custom_endpoint"
var AccessContextManagerCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_ACCESS_CONTEXT_MANAGER_CUSTOM_ENDPOINT",
}, AccessContextManagerDefaultBasePath),
}

var GeneratedAccessContextManagerResourcesMap = map[string]*schema.Resource{
"google_access_context_manager_access_policy": resourceAccessContextManagerAccessPolicy(),
"google_access_context_manager_access_level": resourceAccessContextManagerAccessLevel(),
Expand Down
11 changes: 11 additions & 0 deletions google/provider_app_engine_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var AppEngineDefaultBasePath = "https://appengine.googleapis.com/v1/"
var AppEngineCustomEndpointEntryKey = "app_engine_custom_endpoint"
var AppEngineCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_APP_ENGINE_CUSTOM_ENDPOINT",
}, AppEngineDefaultBasePath),
}

var GeneratedAppEngineResourcesMap = map[string]*schema.Resource{
"google_app_engine_firewall_rule": resourceAppEngineFirewallRule(),
}
11 changes: 11 additions & 0 deletions google/provider_cloud_build_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var CloudBuildDefaultBasePath = "https://cloudbuild.googleapis.com/v1/"
var CloudBuildCustomEndpointEntryKey = "cloud_build_custom_endpoint"
var CloudBuildCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_CLOUD_BUILD_CUSTOM_ENDPOINT",
}, CloudBuildDefaultBasePath),
}

var GeneratedCloudBuildResourcesMap = map[string]*schema.Resource{
"google_cloudbuild_trigger": resourceCloudBuildTrigger(),
}
11 changes: 11 additions & 0 deletions google/provider_cloud_scheduler_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var CloudSchedulerDefaultBasePath = "https://cloudscheduler.googleapis.com/v1/"
var CloudSchedulerCustomEndpointEntryKey = "cloud_scheduler_custom_endpoint"
var CloudSchedulerCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_CLOUD_SCHEDULER_CUSTOM_ENDPOINT",
}, CloudSchedulerDefaultBasePath),
}

var GeneratedCloudSchedulerResourcesMap = map[string]*schema.Resource{
"google_cloud_scheduler_job": resourceCloudSchedulerJob(),
}
11 changes: 11 additions & 0 deletions google/provider_compute_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var ComputeDefaultBasePath = "https://www.googleapis.com/compute/v1/"
var ComputeCustomEndpointEntryKey = "compute_custom_endpoint"
var ComputeCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_COMPUTE_CUSTOM_ENDPOINT",
}, ComputeDefaultBasePath),
}

var GeneratedComputeResourcesMap = map[string]*schema.Resource{
"google_compute_address": resourceComputeAddress(),
"google_compute_autoscaler": resourceComputeAutoscaler(),
Expand Down
11 changes: 11 additions & 0 deletions google/provider_dns_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var DnsDefaultBasePath = "https://www.googleapis.com/dns/v1/"
var DnsCustomEndpointEntryKey = "dns_custom_endpoint"
var DnsCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_DNS_CUSTOM_ENDPOINT",
}, DnsDefaultBasePath),
}

var GeneratedDnsResourcesMap = map[string]*schema.Resource{
"google_dns_managed_zone": resourceDnsManagedZone(),
}
11 changes: 11 additions & 0 deletions google/provider_filestore_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var FilestoreDefaultBasePath = "https://file.googleapis.com/v1/"
var FilestoreCustomEndpointEntryKey = "filestore_custom_endpoint"
var FilestoreCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_FILESTORE_CUSTOM_ENDPOINT",
}, FilestoreDefaultBasePath),
}

var GeneratedFilestoreResourcesMap = map[string]*schema.Resource{
"google_filestore_instance": resourceFilestoreInstance(),
}
11 changes: 11 additions & 0 deletions google/provider_firestore_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ package google

import "github.com/hashicorp/terraform/helper/schema"

var FirestoreDefaultBasePath = "https://firestore.googleapis.com/v1/"
var FirestoreCustomEndpointEntryKey = "firestore_custom_endpoint"
var FirestoreCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_FIRESTORE_CUSTOM_ENDPOINT",
}, FirestoreDefaultBasePath),
}

var GeneratedFirestoreResourcesMap = map[string]*schema.Resource{
"google_firestore_index": resourceFirestoreIndex(),
}
Loading

0 comments on commit ff6dadd

Please sign in to comment.