Skip to content

Commit

Permalink
Add new resource for Application for Apphub (#10079) (#17499)
Browse files Browse the repository at this point in the history
* Add new resource for Application for Apphub

* Add new resource for Application for Apphub

* Enable Apphub API in test cases

* Fix precheck error

* Fix precheck error

* Resolve comments

* Fix lint error

* Fix examples

* Remove apphub from teamcity config

This causes PR build failures, I'll add it later

---------



[upstream:55a1fa855d07e03b0ad43d070f3dc996fd6f2922]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 6, 2024
1 parent 1877603 commit bf69180
Show file tree
Hide file tree
Showing 16 changed files with 1,935 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/10079.txt
@@ -0,0 +1,3 @@
```release-note:new-resource
google_apphub_application
```
5 changes: 5 additions & 0 deletions .teamcity/components/inputs/services_beta.kt
Expand Up @@ -48,6 +48,11 @@ var ServicesListBeta = mapOf(
"displayName" to "Appengine",
"path" to "./google-beta/services/appengine"
),
"apphub" to mapOf(
"name" to "apphub",
"displayName" to "Apphub",
"path" to "./google-beta/services/apphub"
),
"artifactregistry" to mapOf(
"name" to "artifactregistry",
"displayName" to "Artifactregistry",
Expand Down
5 changes: 5 additions & 0 deletions .teamcity/components/inputs/services_ga.kt
Expand Up @@ -48,6 +48,11 @@ var ServicesListGa = mapOf(
"displayName" to "Appengine",
"path" to "./google/services/appengine"
),
"apphub" to mapOf(
"name" to "apphub",
"displayName" to "Apphub",
"path" to "./google/services/apphub"
),
"artifactregistry" to mapOf(
"name" to "artifactregistry",
"displayName" to "Artifactregistry",
Expand Down
1 change: 1 addition & 0 deletions google/fwmodels/provider_model.go
Expand Up @@ -34,6 +34,7 @@ type ProviderModel struct {
AlloydbCustomEndpoint types.String `tfsdk:"alloydb_custom_endpoint"`
ApigeeCustomEndpoint types.String `tfsdk:"apigee_custom_endpoint"`
AppEngineCustomEndpoint types.String `tfsdk:"app_engine_custom_endpoint"`
ApphubCustomEndpoint types.String `tfsdk:"apphub_custom_endpoint"`
ArtifactRegistryCustomEndpoint types.String `tfsdk:"artifact_registry_custom_endpoint"`
BeyondcorpCustomEndpoint types.String `tfsdk:"beyondcorp_custom_endpoint"`
BiglakeCustomEndpoint types.String `tfsdk:"biglake_custom_endpoint"`
Expand Down
6 changes: 6 additions & 0 deletions google/fwprovider/framework_provider.go
Expand Up @@ -178,6 +178,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
transport_tpg.CustomEndpointValidator(),
},
},
"apphub_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
transport_tpg.CustomEndpointValidator(),
},
},
"artifact_registry_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand Down
10 changes: 10 additions & 0 deletions google/fwtransport/framework_config.go
Expand Up @@ -57,6 +57,7 @@ type FrameworkProviderConfig struct {
AlloydbBasePath string
ApigeeBasePath string
AppEngineBasePath string
ApphubBasePath string
ArtifactRegistryBasePath string
BeyondcorpBasePath string
BiglakeBasePath string
Expand Down Expand Up @@ -208,6 +209,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
p.AlloydbBasePath = data.AlloydbCustomEndpoint.ValueString()
p.ApigeeBasePath = data.ApigeeCustomEndpoint.ValueString()
p.AppEngineBasePath = data.AppEngineCustomEndpoint.ValueString()
p.ApphubBasePath = data.ApphubCustomEndpoint.ValueString()
p.ArtifactRegistryBasePath = data.ArtifactRegistryCustomEndpoint.ValueString()
p.BeyondcorpBasePath = data.BeyondcorpCustomEndpoint.ValueString()
p.BiglakeBasePath = data.BiglakeCustomEndpoint.ValueString()
Expand Down Expand Up @@ -489,6 +491,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
data.AppEngineCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.ApphubCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_APPHUB_CUSTOM_ENDPOINT",
}, transport_tpg.DefaultBasePaths[transport_tpg.ApphubBasePathKey])
if customEndpoint != nil {
data.ApphubCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.ArtifactRegistryCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_ARTIFACT_REGISTRY_CUSTOM_ENDPOINT",
Expand Down
6 changes: 6 additions & 0 deletions google/provider/provider.go
Expand Up @@ -175,6 +175,11 @@ func Provider() *schema.Provider {
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"apphub_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"artifact_registry_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -925,6 +930,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.AlloydbBasePath = d.Get("alloydb_custom_endpoint").(string)
config.ApigeeBasePath = d.Get("apigee_custom_endpoint").(string)
config.AppEngineBasePath = d.Get("app_engine_custom_endpoint").(string)
config.ApphubBasePath = d.Get("apphub_custom_endpoint").(string)
config.ArtifactRegistryBasePath = d.Get("artifact_registry_custom_endpoint").(string)
config.BeyondcorpBasePath = d.Get("beyondcorp_custom_endpoint").(string)
config.BiglakeBasePath = d.Get("biglake_custom_endpoint").(string)
Expand Down
6 changes: 4 additions & 2 deletions google/provider/provider_mmv1_resources.go
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform-provider-google/google/services/alloydb"
"github.com/hashicorp/terraform-provider-google/google/services/apigee"
"github.com/hashicorp/terraform-provider-google/google/services/appengine"
"github.com/hashicorp/terraform-provider-google/google/services/apphub"
"github.com/hashicorp/terraform-provider-google/google/services/artifactregistry"
"github.com/hashicorp/terraform-provider-google/google/services/beyondcorp"
"github.com/hashicorp/terraform-provider-google/google/services/biglake"
Expand Down Expand Up @@ -388,9 +389,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 387
// Generated resources: 388
// Generated IAM resources: 231
// Total generated resources: 618
// Total generated resources: 619
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -441,6 +442,7 @@ var generatedResources = map[string]*schema.Resource{
"google_app_engine_service_network_settings": appengine.ResourceAppEngineServiceNetworkSettings(),
"google_app_engine_service_split_traffic": appengine.ResourceAppEngineServiceSplitTraffic(),
"google_app_engine_standard_app_version": appengine.ResourceAppEngineStandardAppVersion(),
"google_apphub_application": apphub.ResourceApphubApplication(),
"google_artifact_registry_repository": artifactregistry.ResourceArtifactRegistryRepository(),
"google_artifact_registry_repository_iam_binding": tpgiamresource.ResourceIamBinding(artifactregistry.ArtifactRegistryRepositoryIamSchema, artifactregistry.ArtifactRegistryRepositoryIamUpdaterProducer, artifactregistry.ArtifactRegistryRepositoryIdParseFunc),
"google_artifact_registry_repository_iam_member": tpgiamresource.ResourceIamMember(artifactregistry.ArtifactRegistryRepositoryIamSchema, artifactregistry.ArtifactRegistryRepositoryIamUpdaterProducer, artifactregistry.ArtifactRegistryRepositoryIdParseFunc),
Expand Down
92 changes: 92 additions & 0 deletions google/services/apphub/apphub_operation.go
@@ -0,0 +1,92 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------

package apphub

import (
"encoding/json"
"errors"
"fmt"
"time"

"github.com/hashicorp/terraform-provider-google/google/tpgresource"
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
)

type ApphubOperationWaiter struct {
Config *transport_tpg.Config
UserAgent string
Project string
tpgresource.CommonOperationWaiter
}

func (w *ApphubOperationWaiter) QueryOp() (interface{}, error) {
if w == nil {
return nil, fmt.Errorf("Cannot query operation, it's unset or nil.")
}
// Returns the proper get.
url := fmt.Sprintf("%s%s", w.Config.ApphubBasePath, w.CommonOperationWaiter.Op.Name)

return transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
Config: w.Config,
Method: "GET",
Project: w.Project,
RawURL: url,
UserAgent: w.UserAgent,
})
}

func createApphubWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*ApphubOperationWaiter, error) {
w := &ApphubOperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func ApphubOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createApphubWaiter(config, op, project, activity, userAgent)
if err != nil {
return err
}
if err := tpgresource.OperationWait(w, activity, timeout, config.PollInterval); err != nil {
return err
}
rawResponse := []byte(w.CommonOperationWaiter.Op.Response)
if len(rawResponse) == 0 {
return errors.New("`resource` not set in operation response")
}
return json.Unmarshal(rawResponse, response)
}

func ApphubOperationWaitTime(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
if val, ok := op["name"]; !ok || val == "" {
// This was a synchronous call - there is no operation to wait for.
return nil
}
w, err := createApphubWaiter(config, op, project, activity, userAgent)
if err != nil {
// If w is nil, the op was synchronous.
return err
}
return tpgresource.OperationWait(w, activity, timeout, config.PollInterval)
}

0 comments on commit bf69180

Please sign in to comment.