Skip to content

Commit

Permalink
Add Blockchain Engine API Resource Support (#9395) (#17096)
Browse files Browse the repository at this point in the history
* add blockchain yaml

* add blockchain product yaml

* add location parameter

* fix lint tests

* remove ApiReference from product yaml

* remove required from location parameters

* add location parameter into test

* add missing

* update tests to use proper blockchain values

* add missing query parameters and create_url in resource

* remove self_link

* Fix inconsistent apply

* Add async support

* lint fixes

* add gethdetails test

* fix node_id typo

* fix test config typos

* typo

* fix output only values

* use NestedObject

* add endline after block

* make additionalEndpoints output only

* WIP: import format

* add self_link of blockchain node

* update import_format

* update self_link

* blockchain_node_id in import_format

* name as import_format

* update directory + explicitly set import_path

* Update mmv1/products/blockchainnodeengine/BlockchainNodes.yaml



* use autogen_async, remove ignore_read,default_from_api

* requested changes to yaml fields

* Update mmv1/products/blockchainnodeengine/BlockchainNodes.yaml



* Update mmv1/products/blockchainnodeengine/BlockchainNodes.yaml



* add validator_config field in tests

* add mev_relay_urls test check

* type

---------


[upstream:c4dad9977780ff8ed3e98c30ea0f52a1daedfd52]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Jan 24, 2024
1 parent f6b90c2 commit afdec59
Show file tree
Hide file tree
Showing 14 changed files with 1,736 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/9395.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:new-resource
`google_blockchain_nodes`
```
5 changes: 5 additions & 0 deletions .teamcity/components/generated/services.kt
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ var services = mapOf(
"displayName" to "Binaryauthorization",
"path" to "./google/services/binaryauthorization"
),
"blockchainnodeengine" to mapOf(
"name" to "blockchainnodeengine",
"displayName" to "Blockchainnodeengine",
"path" to "./google/services/blockchainnodeengine"
),
"certificatemanager" to mapOf(
"name" to "certificatemanager",
"displayName" to "Certificatemanager",
Expand Down
1 change: 1 addition & 0 deletions google/fwmodels/provider_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ProviderModel struct {
BigtableCustomEndpoint types.String `tfsdk:"bigtable_custom_endpoint"`
BillingCustomEndpoint types.String `tfsdk:"billing_custom_endpoint"`
BinaryAuthorizationCustomEndpoint types.String `tfsdk:"binary_authorization_custom_endpoint"`
BlockchainNodeEngineCustomEndpoint types.String `tfsdk:"blockchain_node_engine_custom_endpoint"`
CertificateManagerCustomEndpoint types.String `tfsdk:"certificate_manager_custom_endpoint"`
CloudAssetCustomEndpoint types.String `tfsdk:"cloud_asset_custom_endpoint"`
CloudBuildCustomEndpoint types.String `tfsdk:"cloud_build_custom_endpoint"`
Expand Down
6 changes: 6 additions & 0 deletions google/fwprovider/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,12 @@ func (p *FrameworkProvider) Schema(_ context.Context, _ provider.SchemaRequest,
transport_tpg.CustomEndpointValidator(),
},
},
"blockchain_node_engine_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
transport_tpg.CustomEndpointValidator(),
},
},
"certificate_manager_custom_endpoint": &schema.StringAttribute{
Optional: true,
Validators: []validator.String{
Expand Down
10 changes: 10 additions & 0 deletions google/fwtransport/framework_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type FrameworkProviderConfig struct {
BigtableBasePath string
BillingBasePath string
BinaryAuthorizationBasePath string
BlockchainNodeEngineBasePath string
CertificateManagerBasePath string
CloudAssetBasePath string
CloudBuildBasePath string
Expand Down Expand Up @@ -218,6 +219,7 @@ func (p *FrameworkProviderConfig) LoadAndValidateFramework(ctx context.Context,
p.BigtableBasePath = data.BigtableCustomEndpoint.ValueString()
p.BillingBasePath = data.BillingCustomEndpoint.ValueString()
p.BinaryAuthorizationBasePath = data.BinaryAuthorizationCustomEndpoint.ValueString()
p.BlockchainNodeEngineBasePath = data.BlockchainNodeEngineCustomEndpoint.ValueString()
p.CertificateManagerBasePath = data.CertificateManagerCustomEndpoint.ValueString()
p.CloudAssetBasePath = data.CloudAssetCustomEndpoint.ValueString()
p.CloudBuildBasePath = data.CloudBuildCustomEndpoint.ValueString()
Expand Down Expand Up @@ -581,6 +583,14 @@ func (p *FrameworkProviderConfig) HandleDefaults(ctx context.Context, data *fwmo
data.BinaryAuthorizationCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.BlockchainNodeEngineCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_BLOCKCHAIN_NODE_ENGINE_CUSTOM_ENDPOINT",
}, transport_tpg.DefaultBasePaths[transport_tpg.BlockchainNodeEngineBasePathKey])
if customEndpoint != nil {
data.BlockchainNodeEngineCustomEndpoint = types.StringValue(customEndpoint.(string))
}
}
if data.CertificateManagerCustomEndpoint.IsNull() {
customEndpoint := transport_tpg.MultiEnvDefault([]string{
"GOOGLE_CERTIFICATE_MANAGER_CUSTOM_ENDPOINT",
Expand Down
6 changes: 6 additions & 0 deletions google/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ func Provider() *schema.Provider {
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"blockchain_node_engine_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: transport_tpg.ValidateCustomEndpoint,
},
"certificate_manager_custom_endpoint": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -903,6 +908,7 @@ func ProviderConfigure(ctx context.Context, d *schema.ResourceData, p *schema.Pr
config.BigtableBasePath = d.Get("bigtable_custom_endpoint").(string)
config.BillingBasePath = d.Get("billing_custom_endpoint").(string)
config.BinaryAuthorizationBasePath = d.Get("binary_authorization_custom_endpoint").(string)
config.BlockchainNodeEngineBasePath = d.Get("blockchain_node_engine_custom_endpoint").(string)
config.CertificateManagerBasePath = d.Get("certificate_manager_custom_endpoint").(string)
config.CloudAssetBasePath = d.Get("cloud_asset_custom_endpoint").(string)
config.CloudBuildBasePath = d.Get("cloud_build_custom_endpoint").(string)
Expand Down
6 changes: 4 additions & 2 deletions google/provider/provider_mmv1_resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/hashicorp/terraform-provider-google/google/services/bigtable"
"github.com/hashicorp/terraform-provider-google/google/services/billing"
"github.com/hashicorp/terraform-provider-google/google/services/binaryauthorization"
"github.com/hashicorp/terraform-provider-google/google/services/blockchainnodeengine"
"github.com/hashicorp/terraform-provider-google/google/services/certificatemanager"
"github.com/hashicorp/terraform-provider-google/google/services/cloudasset"
"github.com/hashicorp/terraform-provider-google/google/services/cloudbuild"
Expand Down Expand Up @@ -380,9 +381,9 @@ var handwrittenIAMDatasources = map[string]*schema.Resource{
}

// Resources
// Generated resources: 370
// Generated resources: 371
// Generated IAM resources: 222
// Total generated resources: 592
// Total generated resources: 593
var generatedResources = map[string]*schema.Resource{
"google_folder_access_approval_settings": accessapproval.ResourceAccessApprovalFolderSettings(),
"google_organization_access_approval_settings": accessapproval.ResourceAccessApprovalOrganizationSettings(),
Expand Down Expand Up @@ -477,6 +478,7 @@ var generatedResources = map[string]*schema.Resource{
"google_binary_authorization_attestor_iam_member": tpgiamresource.ResourceIamMember(binaryauthorization.BinaryAuthorizationAttestorIamSchema, binaryauthorization.BinaryAuthorizationAttestorIamUpdaterProducer, binaryauthorization.BinaryAuthorizationAttestorIdParseFunc),
"google_binary_authorization_attestor_iam_policy": tpgiamresource.ResourceIamPolicy(binaryauthorization.BinaryAuthorizationAttestorIamSchema, binaryauthorization.BinaryAuthorizationAttestorIamUpdaterProducer, binaryauthorization.BinaryAuthorizationAttestorIdParseFunc),
"google_binary_authorization_policy": binaryauthorization.ResourceBinaryAuthorizationPolicy(),
"google_blockchain_node_engine_blockchain_nodes": blockchainnodeengine.ResourceBlockchainNodeEngineBlockchainNodes(),
"google_certificate_manager_certificate": certificatemanager.ResourceCertificateManagerCertificate(),
"google_certificate_manager_certificate_issuance_config": certificatemanager.ResourceCertificateManagerCertificateIssuanceConfig(),
"google_certificate_manager_certificate_map": certificatemanager.ResourceCertificateManagerCertificateMap(),
Expand Down
Original file line number Diff line number Diff line change
@@ -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 blockchainnodeengine

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 BlockchainNodeEngineOperationWaiter struct {
Config *transport_tpg.Config
UserAgent string
Project string
tpgresource.CommonOperationWaiter
}

func (w *BlockchainNodeEngineOperationWaiter) 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.BlockchainNodeEngineBasePath, 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 createBlockchainNodeEngineWaiter(config *transport_tpg.Config, op map[string]interface{}, project, activity, userAgent string) (*BlockchainNodeEngineOperationWaiter, error) {
w := &BlockchainNodeEngineOperationWaiter{
Config: config,
UserAgent: userAgent,
Project: project,
}
if err := w.CommonOperationWaiter.SetOp(op); err != nil {
return nil, err
}
return w, nil
}

// nolint: deadcode,unused
func BlockchainNodeEngineOperationWaitTimeWithResponse(config *transport_tpg.Config, op map[string]interface{}, response *map[string]interface{}, project, activity, userAgent string, timeout time.Duration) error {
w, err := createBlockchainNodeEngineWaiter(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 BlockchainNodeEngineOperationWaitTime(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 := createBlockchainNodeEngineWaiter(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)
}
Loading

0 comments on commit afdec59

Please sign in to comment.