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 <[email protected]>
  • Loading branch information
rileykarson authored and modular-magician committed Jun 11, 2019
1 parent ab9c623 commit c8e0416
Show file tree
Hide file tree
Showing 168 changed files with 1,374 additions and 425 deletions.
281 changes: 216 additions & 65 deletions google-beta/config.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion google-beta/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-beta/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
2 changes: 2 additions & 0 deletions google-beta/gcp_sweeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,7 @@ func sharedConfigForRegion(region string) (*Config, error) {
Project: project,
}

BasePathsConfigure(conf)

return conf, nil
}
143 changes: 143 additions & 0 deletions google-beta/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,59 @@ func Provider() terraform.ResourceProvider {
"CLOUDSDK_COMPUTE_ZONE",
}, nil),
},

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

// Generated Products
// start beta-only products
BinaryAuthorizationCustomEndpointEntryKey: BinaryAuthorizationCustomEndpointEntry,
ContainerAnalysisCustomEndpointEntryKey: ContainerAnalysisCustomEndpointEntry,
SecurityScannerCustomEndpointEntryKey: SecurityScannerCustomEndpointEntry,
// end beta-only products
AccessContextManagerCustomEndpointEntryKey: AccessContextManagerCustomEndpointEntry,
AppEngineCustomEndpointEntryKey: AppEngineCustomEndpointEntry,
ComputeCustomEndpointEntryKey: ComputeCustomEndpointEntry,
CloudBuildCustomEndpointEntryKey: CloudBuildCustomEndpointEntry,
CloudSchedulerCustomEndpointEntryKey: CloudSchedulerCustomEndpointEntry,
DnsCustomEndpointEntryKey: DnsCustomEndpointEntry,
FilestoreCustomEndpointEntryKey: FilestoreCustomEndpointEntry,
FirestoreCustomEndpointEntryKey: FirestoreCustomEndpointEntry,
KmsCustomEndpointEntryKey: KmsCustomEndpointEntry,
PubsubCustomEndpointEntryKey: PubsubCustomEndpointEntry,
ResourceManagerCustomEndpointEntryKey: ResourceManagerCustomEndpointEntry,
SourceRepoCustomEndpointEntryKey: SourceRepoCustomEndpointEntry,
SpannerCustomEndpointEntryKey: SpannerCustomEndpointEntry,
SqlCustomEndpointEntryKey: SqlCustomEndpointEntry,
StorageCustomEndpointEntryKey: StorageCustomEndpointEntry,

// Handwritten Products / Versioned / Atypical Entries
// start beta-only products
IAPCustomEndpointEntryKey: IAPCustomEndpointEntry,
ServiceNetworkingCustomEndpointEntryKey: ServiceNetworkingCustomEndpointEntry,
// end beta-only products
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,
StorageTransferCustomEndpointEntryKey: StorageTransferCustomEndpointEntry,
},

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

config.BinaryAuthorizationBasePath = d.Get(BinaryAuthorizationCustomEndpointEntryKey).(string)
config.ContainerAnalysisBasePath = d.Get(ContainerAnalysisCustomEndpointEntryKey).(string)
config.SecurityScannerBasePath = d.Get(SecurityScannerCustomEndpointEntryKey).(string)

config.AccessContextManagerBasePath = d.Get(AccessContextManagerCustomEndpointEntryKey).(string)
config.CloudSchedulerBasePath = d.Get(CloudSchedulerCustomEndpointEntryKey).(string)
config.FirestoreBasePath = d.Get(FirestoreCustomEndpointEntryKey).(string)

config.AppEngineBasePath = d.Get(AppEngineCustomEndpointEntryKey).(string)
config.ComputeBasePath = d.Get(ComputeCustomEndpointEntryKey).(string)
config.CloudBuildBasePath = d.Get(CloudBuildCustomEndpointEntryKey).(string)
config.DnsBasePath = d.Get(DnsCustomEndpointEntryKey).(string)
config.FilestoreBasePath = d.Get(FilestoreCustomEndpointEntryKey).(string)
config.KmsBasePath = d.Get(KmsCustomEndpointEntryKey).(string)
config.PubsubBasePath = d.Get(PubsubCustomEndpointEntryKey).(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.IAPBasePath = d.Get(IAPCustomEndpointEntryKey).(string)
config.ServiceNetworkingBasePath = d.Get(ServiceNetworkingCustomEndpointEntryKey).(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.StorageTransferBasePath = d.Get(StorageTransferCustomEndpointEntryKey).(string)

if err := config.LoadAndValidate(); err != nil {
return nil, err
}

return &config, nil
}

// For a consumer of config.go that isn't a full fledged provider and doesn't
// have its own endpoint mechanism such as sweepers, init {{service}}BasePath
// values to a default. After using this, you should call config.LoadAndValidate.
func BasePathsConfigure(c *Config) {
// Generated Products
// start beta-only products
c.BinaryAuthorizationBasePath = BinaryAuthorizationDefaultBasePath
c.ContainerAnalysisBasePath = ContainerAnalysisDefaultBasePath
c.SecurityScannerBasePath = SecurityScannerDefaultBasePath
// end beta-only products
c.AccessContextManagerBasePath = AccessContextManagerDefaultBasePath
c.AppEngineBasePath = AppEngineDefaultBasePath
c.ComputeBasePath = ComputeDefaultBasePath
c.CloudBuildBasePath = CloudBuildDefaultBasePath
c.CloudSchedulerBasePath = CloudSchedulerDefaultBasePath
c.DnsBasePath = DnsDefaultBasePath
c.FilestoreBasePath = FilestoreDefaultBasePath
c.FirestoreBasePath = FirestoreDefaultBasePath
c.KmsBasePath = KmsDefaultBasePath
c.PubsubBasePath = PubsubDefaultBasePath
c.ResourceManagerBasePath = ResourceManagerDefaultBasePath
c.SourceRepoBasePath = SourceRepoDefaultBasePath
c.SpannerBasePath = SpannerDefaultBasePath
c.SqlBasePath = SqlDefaultBasePath
c.StorageBasePath = StorageDefaultBasePath

// Handwritten Products / Versioned / Atypical Entries
// start beta-only products
c.IAPBasePath = IAPDefaultBasePath
c.ServiceNetworkingBasePath = ServiceNetworkingDefaultBasePath
// end beta-only products
c.CloudBillingBasePath = CloudBillingDefaultBasePath
c.ComposerBasePath = ComposerDefaultBasePath
c.ComputeBetaBasePath = ComputeBetaDefaultBasePath
c.ContainerBasePath = ContainerDefaultBasePath
c.ContainerBetaBasePath = ContainerBetaDefaultBasePath
c.DataprocBasePath = DataprocDefaultBasePath
c.DataflowBasePath = DataflowDefaultBasePath
c.DnsBetaBasePath = DnsBetaDefaultBasePath
c.IamCredentialsBasePath = IamCredentialsDefaultBasePath
c.LoggingBasePath = LoggingDefaultBasePath
c.ResourceManagerV2Beta1BasePath = ResourceManagerV2Beta1DefaultBasePath
c.RuntimeconfigBasePath = RuntimeconfigDefaultBasePath
c.IAMBasePath = IAMDefaultBasePath
c.ServiceManagementBasePath = ServiceManagementDefaultBasePath
c.ServiceUsageBasePath = ServiceUsageDefaultBasePath
c.BigQueryBasePath = BigQueryDefaultBasePath
c.CloudFunctionsBasePath = CloudFunctionsDefaultBasePath
c.CloudIoTBasePath = CloudIoTDefaultBasePath
c.StorageTransferBasePath = StorageTransferDefaultBasePath
}

func validateCredentials(v interface{}, k string) (warnings []string, errors []error) {
if v == nil || v.(string) == "" {
return
Expand Down
13 changes: 13 additions & 0 deletions google-beta/provider_access_context_manager_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
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
13 changes: 13 additions & 0 deletions google-beta/provider_app_engine_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
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(),
}
13 changes: 13 additions & 0 deletions google-beta/provider_binary_authorization_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
var BinaryAuthorizationDefaultBasePath = "https://binaryauthorization.googleapis.com/v1beta1/"
var BinaryAuthorizationCustomEndpointEntryKey = "binary_authorization_custom_endpoint"
var BinaryAuthorizationCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_BINARY_AUTHORIZATION_CUSTOM_ENDPOINT",
}, BinaryAuthorizationDefaultBasePath),
}

var GeneratedBinaryAuthorizationResourcesMap = map[string]*schema.Resource{
"google_binary_authorization_attestor": resourceBinaryAuthorizationAttestor(),
"google_binary_authorization_policy": resourceBinaryAuthorizationPolicy(),
Expand Down
13 changes: 13 additions & 0 deletions google-beta/provider_cloud_build_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
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(),
}
13 changes: 13 additions & 0 deletions google-beta/provider_cloud_scheduler_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
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(),
}
13 changes: 13 additions & 0 deletions google-beta/provider_compute_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
var ComputeDefaultBasePath = "https://www.googleapis.com/compute/beta/"
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
13 changes: 13 additions & 0 deletions google-beta/provider_container_analysis_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
var ContainerAnalysisDefaultBasePath = "https://containeranalysis.googleapis.com/v1beta1/"
var ContainerAnalysisCustomEndpointEntryKey = "container_analysis_custom_endpoint"
var ContainerAnalysisCustomEndpointEntry = &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateCustomEndpoint,
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
"GOOGLE_CONTAINER_ANALYSIS_CUSTOM_ENDPOINT",
}, ContainerAnalysisDefaultBasePath),
}

var GeneratedContainerAnalysisResourcesMap = map[string]*schema.Resource{
"google_container_analysis_note": resourceContainerAnalysisNote(),
}
13 changes: 13 additions & 0 deletions google-beta/provider_dns_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
var DnsDefaultBasePath = "https://www.googleapis.com/dns/v1beta2/"
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(),
"google_dns_policy": resourceDnsPolicy(),
Expand Down
13 changes: 13 additions & 0 deletions google-beta/provider_filestore_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
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(),
}
13 changes: 13 additions & 0 deletions google-beta/provider_firestore_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ package google

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

// If the base path has changed as a result of your PR, make sure to update
// the provider_reference page!
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 c8e0416

Please sign in to comment.