Skip to content

Commit 4cd9fc2

Browse files
add assured workloads base implementation (#4936) (#3410)
Co-authored-by: Riley Karson <[email protected]> Signed-off-by: Modular Magician <[email protected]> Co-authored-by: Riley Karson <[email protected]>
1 parent 1d6219c commit 4cd9fc2

12 files changed

+976
-3
lines changed

.changelog/4936.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-resource
2+
`google_assured_workloads_workload`
3+
```

google-beta/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,9 @@ type Config struct {
175175

176176
// start DCLBasePaths
177177
// dataprocBasePath is implemented in mm
178-
EventarcBasePath string
179-
GkeHubBasePath string
178+
AssuredWorkloadsBasePath string
179+
EventarcBasePath string
180+
GkeHubBasePath string
180181
// CloudBuild WorkerPool uses a different endpoint (v1beta1) than any other CloudBuild resources
181182
CloudBuildWorkerPoolBasePath string
182183
}

google-beta/provider.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ func Provider() *schema.Provider {
750750
BigtableAdminCustomEndpointEntryKey: BigtableAdminCustomEndpointEntry,
751751

752752
// dcl
753+
AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
753754
EventarcEndpointEntryKey: EventarcEndpointEntry,
754755
GkeHubFeatureCustomEndpointEntryKey: GkeHubFeatureCustomEndpointEntry,
755756
CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
@@ -1227,6 +1228,7 @@ func ResourceMapWithErrors() (map[string]*schema.Resource, error) {
12271228
"google_workflows_workflow": resourceWorkflowsWorkflow(),
12281229
},
12291230
map[string]*schema.Resource{
1231+
"google_assured_workloads_workload": resourceAssuredWorkloadsWorkload(),
12301232
"google_app_engine_application": resourceAppEngineApplication(),
12311233
"google_bigquery_table": resourceBigQueryTable(),
12321234
"google_bigtable_gc_policy": resourceBigtableGCPolicy(),
@@ -1532,6 +1534,7 @@ func providerConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
15321534
config.BigtableAdminBasePath = d.Get(BigtableAdminCustomEndpointEntryKey).(string)
15331535

15341536
// dcl
1537+
config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
15351538
config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)
15361539
config.GkeHubBasePath = d.Get(GkeHubFeatureCustomEndpointEntryKey).(string)
15371540
config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)

google-beta/provider_dcl_client_creation.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,39 @@ package google
1717
import (
1818
dcl "github.com/GoogleCloudPlatform/declarative-resource-client-library/dcl"
1919

20+
assuredworkloads "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/assuredworkloads/beta"
2021
cloudbuild "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/cloudbuild/beta"
2122
dataproc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/dataproc/beta"
2223
eventarc "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/eventarc/beta"
2324
gke_hub "github.com/GoogleCloudPlatform/declarative-resource-client-library/services/google/gkehub/beta"
2425
)
2526

27+
func NewDCLAssuredWorkloadsClient(config *Config, userAgent, billingProject string) *assuredworkloads.Client {
28+
dclClientOptions := dcl.WithHTTPClient(config.client)
29+
dclUserAgentOptions := dcl.WithUserAgent(userAgent)
30+
dclLoggerOptions := dcl.WithLogger(dclLogger{})
31+
var dclConfig *dcl.Config
32+
if config.UserProjectOverride && billingProject != "" {
33+
dclBillingProjectHeader := dcl.WithHeader("X-Goog-User-Project", billingProject)
34+
dclConfig = dcl.NewConfig(
35+
dclClientOptions,
36+
dclUserAgentOptions,
37+
dclLoggerOptions,
38+
dcl.WithBasePath(config.AssuredWorkloadsBasePath),
39+
dclBillingProjectHeader,
40+
)
41+
} else {
42+
dclConfig = dcl.NewConfig(
43+
dclClientOptions,
44+
dclUserAgentOptions,
45+
dclLoggerOptions,
46+
dcl.WithBasePath(config.AssuredWorkloadsBasePath),
47+
)
48+
}
49+
50+
return assuredworkloads.NewClient(dclConfig)
51+
}
52+
2653
func NewDCLCloudbuildClient(config *Config, userAgent, billingProject string) *cloudbuild.Client {
2754
dclClientOptions := dcl.WithHTTPClient(config.client)
2855
dclUserAgentOptions := dcl.WithUserAgent(userAgent)

google-beta/provider_dcl_endpoints.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ import (
2121
// empty string is passed for dcl default since dcl
2222
// [hardcodes the values](https://github.com/GoogleCloudPlatform/declarative-resource-client-library/blob/main/services/google/eventarc/beta/trigger_internal.go#L96-L103)
2323

24+
var AssuredWorkloadsEndpointEntryKey = "assured_workloads_custom_endpoint"
25+
var AssuredWorkloadsEndpointEntry = &schema.Schema{
26+
Type: schema.TypeString,
27+
Optional: true,
28+
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
29+
"GOOGLE_ASSURED_WORKLOADS_CUSTOM_ENDPOINT",
30+
}, ""),
31+
}
32+
2433
var CloudBuildWorkerPoolEndpointEntryKey = "cloud_build_worker_pool_custom_endpoint"
2534
var CloudBuildWorkerPoolEndpointEntry = &schema.Schema{
2635
Type: schema.TypeString,
@@ -40,13 +49,16 @@ var EventarcEndpointEntry = &schema.Schema{
4049
}
4150

4251
//Add new values to config.go.erb config object declaration
52+
//AssuredWorkloadsBasePath string
4353
//CloudBuildWorkerPoolBasePath string
4454
//EventarcBasePath string
4555

4656
//Add new values to provider.go.erb schema initialization
57+
// AssuredWorkloadsEndpointEntryKey: AssuredWorkloadsEndpointEntry,
4758
// CloudBuildWorkerPoolEndpointEntryKey: CloudBuildWorkerPoolEndpointEntry,
4859
// EventarcEndpointEntryKey: EventarcEndpointEntry,
4960

5061
//Add new values to provider.go.erb - provider block read
62+
// config.AssuredWorkloadsBasePath = d.Get(AssuredWorkloadsEndpointEntryKey).(string)
5163
// config.CloudBuildWorkerPoolBasePath = d.Get(CloudBuildWorkerPoolEndpointEntryKey).(string)
5264
// config.EventarcBasePath = d.Get(EventarcEndpointEntryKey).(string)

0 commit comments

Comments
 (0)