Skip to content

Commit

Permalink
memorystore open api (GoogleCloudPlatform#11463)
Browse files Browse the repository at this point in the history
  • Loading branch information
himanikh authored and iyabchen committed Sep 14, 2024
1 parent 7bd654e commit 4a2eb84
Show file tree
Hide file tree
Showing 10 changed files with 930 additions and 0 deletions.
343 changes: 343 additions & 0 deletions mmv1/products/memorystore/Instance.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,343 @@
---
!ruby/object:Api::Resource
base_url: "projects/{{project}}/locations/{{location}}/instances"
create_url: "projects/{{project}}/locations/{{location}}/instances?instanceId={{instance_id}}"
self_link: "projects/{{project}}/locations/{{location}}/instances/{{instance_id}}"
id_format: "projects/{{project}}/locations/{{location}}/instances/{{instance_id}}"
import_format:
- "projects/{{project}}/locations/{{location}}/instances/{{instance_id}}"
name: Instance
description: A Google Cloud Memorystore instance.
update_verb: :PATCH
update_mask: true
autogen_async: true
min_version: beta
timeouts: !ruby/object:Api::Timeouts
insert_minutes: 60
update_minutes: 120
delete_minutes: 30
custom_code: !ruby/object:Provider::Terraform::CustomCode
encoder: templates/terraform/encoders/memorystore_instance.go.erb
decoder: templates/terraform/decoders/memorystore_instance.go.erb
examples:
- !ruby/object:Provider::Terraform::Examples
name: "memorystore_instance_basic"
primary_resource_id: "instance-basic"
min_version: beta
vars:
instance_name: "basic-instance"
policy_name: "my-policy"
subnet_name: "my-subnet"
network_name: "my-network"
prevent_destroy: "true"
test_vars_overrides:
prevent_destroy: "false"
oics_vars_overrides:
prevent_destroy: "false"
- !ruby/object:Provider::Terraform::Examples
name: "memorystore_instance_full"
primary_resource_id: "instance-full"
min_version: beta
vars:
instance_name: "full-instance"
policy_name: "my-policy"
subnet_name: "my-subnet"
network_name: "my-network"
prevent_destroy: "true"
test_vars_overrides:
prevent_destroy: "false"
oics_vars_overrides:
prevent_destroy: "false"
- !ruby/object:Provider::Terraform::Examples
name: "memorystore_instance_persistence_aof"
primary_resource_id: "instance-persistence-aof"
min_version: beta
vars:
instance_name: "aof-instance"
policy_name: "my-policy"
subnet_name: "my-subnet"
network_name: "my-network"
prevent_destroy: "true"
test_vars_overrides:
prevent_destroy: "false"
oics_vars_overrides:
prevent_destroy: "false"
properties:
- !ruby/object:Api::Type::String
name: name
description: "Identifier. Unique name of the instance.\nFormat: projects/{project}/locations/{location}/instances/{instance} "
output: true
- !ruby/object:Api::Type::String
name: createTime
description: "Output only. Creation timestamp of the instance. "
output: true
- !ruby/object:Api::Type::String
name: updateTime
description: "Output only. Latest update timestamp of the instance. "
output: true
- !ruby/object:Api::Type::KeyValueLabels
name: labels
description: "Optional. Labels to represent user-provided metadata. "
- !ruby/object:Api::Type::String
name: state
description:
"Output only. Current state of the instance. \n Possible values:\n
CREATING\nACTIVE\nUPDATING\nDELETING"
output: true
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::Integer
name: targetShardCount
description: "Output only. Target number of shards for the instance. "
output: true
- !ruby/object:Api::Type::Integer
name: targetReplicaCount
description:
"Output only. Target number of replica nodes per shard for the
instance. "
output: true
name: updateInfo
description: "Represents information about instance with state UPDATING. "
output: true
name: stateInfo
description: "Additional information about the state of the instance. "
output: true
- !ruby/object:Api::Type::String
name: uid
description: "Output only. System assigned, unique identifier for the instance. "
output: true
- !ruby/object:Api::Type::Integer
name: replicaCount
description:
"Optional. Number of replica nodes per shard. If omitted the default
is 0 replicas. "
default_from_api: true
- !ruby/object:Api::Type::String
name: authorizationMode
description:
"Optional. Immutable. Authorization mode of the instance. \n Possible
values:\n AUTH_DISABLED\nIAM_AUTH"
immutable: true
default_from_api: true
- !ruby/object:Api::Type::String
name: transitEncryptionMode
description:
"Optional. Immutable. In-transit encryption mode of the instance. \n
Possible values:\n TRANSIT_ENCRYPTION_DISABLED\nSERVER_AUTHENTICATION"
immutable: true
default_from_api: true
- !ruby/object:Api::Type::Integer
name: shardCount
description: "Required. Number of shards for the instance. "
required: true
- !ruby/object:Api::Type::Array
name: discoveryEndpoints
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: address
description:
"Output only. IP address of the exposed endpoint clients connect
to. "
output: true
- !ruby/object:Api::Type::Integer
name: port
description: "Output only. The port number of the exposed endpoint. "
output: true
- !ruby/object:Api::Type::String
name: network
description:
"Output only. The network where the IP address of the discovery
endpoint will be\nreserved, in the form of\nprojects/{network_project}/global/networks/{network_id}. "
output: true
description:
"Output only. Endpoints clients can connect to the instance through.
Currently only one\ndiscovery endpoint is supported. "
output: true
- !ruby/object:Api::Type::String
name: nodeType
description:
"Optional. Immutable. Machine type for individual nodes of the instance.
\n Possible values:\n SHARED_CORE_NANO\nHIGHMEM_MEDIUM\nHIGHMEM_XLARGE\nSTANDARD_SMALL"
immutable: true
default_from_api: true
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::Enum
name: mode
description: "Optional. Current persistence mode. \n Possible values:\nDISABLED\nRDB\nAOF"
values:
- :DISABLED
- :RDB
- :AOF
default_from_api: true
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: rdbSnapshotPeriod
default_from_api: true
description:
"Optional. Period between RDB snapshots. \n Possible values:\n
ONE_HOUR\nSIX_HOURS\nTWELVE_HOURS\nTWENTY_FOUR_HOURS"
- !ruby/object:Api::Type::String
name: rdbSnapshotStartTime
description:
"Optional. Time that the first snapshot was/will be attempted,
and to which future\nsnapshots will be aligned. If not provided, the current
time will be\nused. "
default_from_api: true
name: rdbConfig
description: "Configuration for RDB based persistence. "
default_from_api: true
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: appendFsync
description: "Optional. The fsync mode. \n Possible values:\n NEVER\nEVERY_SEC\nALWAYS"
default_from_api: true
name: aofConfig
description: "Configuration for AOF based persistence. "
default_from_api: true
name: persistenceConfig
default_from_api: true
description: "Represents persistence configuration for a instance. "
- !ruby/object:Api::Type::String
name: engineVersion
description: "Optional. Immutable. Engine version of the instance. "
immutable: true
default_from_api: true
- !ruby/object:Api::Type::KeyValuePairs
name: engineConfigs
description: "Optional. User-provided engine configurations for the instance. "
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::Double
name: sizeGb
description: "Output only. Memory size in GB of the node. "
output: true
name: nodeConfig
output: true
description: "Represents configuration for nodes of the instance. "
- !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: zone
description:
"Optional. Defines zone where all resources will be allocated with
SINGLE_ZONE mode.\nIgnored for MULTI_ZONE mode. "
immutable: true
- !ruby/object:Api::Type::Enum
name: mode
values:
- :MULTI_ZONE
- :SINGLE_ZONE
default_from_api: true
description:
"Optional. Current zone distribution mode. Defaults to MULTI_ZONE.
\n Possible values:\n MULTI_ZONE\nSINGLE_ZONE"
name: zoneDistributionConfig
immutable: true
default_from_api: true
description: "Zone distribution configuration for allocation of instance resources. "
- !ruby/object:Api::Type::Boolean
name: deletionProtectionEnabled
description: "Optional. If set to true deletion of the instance will fail. "
default_value: true
- !ruby/object:Api::Type::Array
name: pscAutoConnections
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: pscConnectionId
description:
"Output only. The PSC connection id of the forwarding rule connected
to the\nservice attachment. "
output: true
- !ruby/object:Api::Type::String
name: ipAddress
description:
"Output only. The IP allocated on the consumer network for the
PSC forwarding rule. "
output: true
- !ruby/object:Api::Type::String
name: forwardingRule
description: "Output only. The URI of the consumer side forwarding rule.\nFormat:\nprojects/{project}/regions/{region}/forwardingRules/{forwarding_rule} "
output: true
- !ruby/object:Api::Type::String
name: projectId
description:
"Output only. The consumer project_id where the forwarding rule is
created from. "
output: true
- !ruby/object:Api::Type::String
name: network
description:
"Output only. The consumer network where the IP address resides, in
the form of\nprojects/{project_id}/global/networks/{network_id}. "
output: true
description:
"Output only. User inputs and resource details of the auto-created
PSC connections. "
output: true
parameters:
- !ruby/object:Api::Type::String
name: location
description:
"Resource ID segment making up resource `name`. It identifies the resource
within its parent collection as described in https://google.aip.dev/122. See documentation
for resource type `memorystore.googleapis.com/CertificateAuthority`. "
url_param_only: true
required: true
immutable: true
- !ruby/object:Api::Type::String
name: instanceId
description:
"Required. The ID to use for the instance, which will become the final
component of\nthe instance's resource name.\n\nThis value is subject to the following
restrictions:\n\n* Must be 4-63 characters in length\n* Must begin with a letter
or digit\n* Must contain only lowercase letters, digits, and hyphens\n* Must not
end with a hyphen\n* Must be unique within a location "
url_param_only: true
required: true
immutable: true
virtual_fields:
- !ruby/object:Api::Type::Array
name: desired_psc_auto_connections
item_type: !ruby/object:Api::Type::NestedObject
properties:
- !ruby/object:Api::Type::String
name: project_id
description:
"Required. The consumer project_id where the forwarding rule is
created from. "
required: true
- !ruby/object:Api::Type::String
name: network
description:
"Required. The consumer network where the IP address resides, in
the form of\nprojects/{project_id}/global/networks/{network_id}. "
required: true
description: "Required. Immutable. User inputs for the auto-created
PSC connections. "
immutable: true
required: true
async: !ruby/object:Api::OpAsync
operation: !ruby/object:Api::OpAsync::Operation
path: name
base_url: "{{op_id}}"
wait_ms: 1000
timeouts:
result: !ruby/object:Api::OpAsync::Result
path: response
resource_inside_response: true
status: !ruby/object:Api::OpAsync::Status
path: done
complete: true
allowed:
- true
- false
error: !ruby/object:Api::OpAsync::Error
path: error
message: message
10 changes: 10 additions & 0 deletions mmv1/products/memorystore/product.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
!ruby/object:Api::Product
versions:
- !ruby/object:Api::Product::Version
base_url: https://memorystore.googleapis.com/v1beta/
name: beta
name: Memorystore
display_name: Memorystore
scopes:
- https://www.googleapis.com/auth/cloud-platform
42 changes: 42 additions & 0 deletions mmv1/templates/terraform/decoders/memorystore_instance.go.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Retrieve pscAutoConnections from API response
v, ok := res["pscAutoConnections"]
if !ok {
return nil, fmt.Errorf("pscAutoConnections field not found in API response")
}

connections, ok := v.([]interface{})
if !ok {
return nil, fmt.Errorf("pscAutoConnections is not an array")
}

transformed := make([]interface{}, 0, len(connections))
uniqueConnections := make(map[string]bool) // Track unique project+network combos

for _, raw := range connections {
connectionData, ok := raw.(map[string]interface{})
if !ok || len(connectionData) < 1 {
return nil, fmt.Errorf("Invalid or empty psc connection data: %v", raw)
}

projectID, ok := connectionData["projectId"].(string)
if !ok {
return nil, fmt.Errorf("invalid project ID in psc connection: %v", connectionData)
}

networkID, ok := connectionData["network"].(string)
if !ok {
return nil, fmt.Errorf("invalid network ID in psc connection: %v", connectionData)
}

uniqueKey := projectID + networkID
if !uniqueConnections[uniqueKey] { // Check for uniqueness
uniqueConnections[uniqueKey] = true
transformed = append(transformed, map[string]interface{}{
"project_id": projectID,
"network": networkID,
})
}
}

d.Set("desired_psc_auto_connections", transformed)
return res, nil
Loading

0 comments on commit 4a2eb84

Please sign in to comment.