- release_tracks: [ALPHA, BETA, GA]

  help_text:
    brief: |
      Create a new Memorystore for Redis Cluster instance.
    description: |
      Create a new Memorystore for Redis Cluster instance, and uses Private Service Connect service connectivity automation to automate connectivity for instances.

      This command can fail for the following reasons:
        * A cluster with the same name already exists.
        * The active account does not have permission to create clusters.
        * Some required APIs not enabled yet.
        * No connection policy defined yet on the network and in the region a cluster will be created.
        * Miss the steps for creating and configuring a service account (to grant permissions) in both host project and service project, if a shared VPC network is used.

      Refer to https://cloud.google.com/memorystore/docs/cluster/networking#prerequisites_required_before_creating_a_cluster for prerequisites.
    examples: |
      To create a cluster with name `my-redis-cluster` in region `us-central1`
      with 3 shards and with a discovery endpoint created on network "default", run:

        $ {command} my-redis-cluster --region=us-central1 --shard-count=3 \
            --network=projects/NETWORK_PROJECT_ID/global/networks/default

  arguments:
    resource:
      spec: !REF googlecloudsdk.command_lib.redis.resources:cluster
      help_text: |
        Arguments and flags that specify the cluster you want to create.
        Your cluster ID must be 1 to 63 characters and use only lowercase letters, numbers, or
        hyphens. It must start with a lowercase letter and end with a lowercase letter or number.
    params:
    - arg_name: node-type
      api_field: cluster.nodeType
      help_text: Node Type of the redis cluster Node.
      choices:
      - enum_value: REDIS_HIGHMEM_MEDIUM
        arg_value: redis-highmem-medium
      - enum_value: REDIS_HIGHMEM_XLARGE
        arg_value: redis-highmem-xlarge
      - enum_value: REDIS_HIGHMEM_2XLARGE
        arg_value: redis-highmem-2xlarge
        hidden: true
      - enum_value: REDIS_HIGHCPU_MEDIUM
        arg_value: redis-highcpu-medium
        hidden: true
      - enum_value: REDIS_STANDARD_SMALL
        arg_value: redis-standard-small
      - enum_value: REDIS_STANDARD_LARGE
        arg_value: redis-standard-large
        hidden: true
      - enum_value: REDIS_SHARED_CORE_NANO
        arg_value: redis-shared-core-nano
    - arg_name: network
      api_field: cluster.pscConfigs.network
      help_text: |
         The network used to create your instance. It must use the format:
         projects/NETWORK_PROJECT_ID/global/networks/NETWORK_ID.
         The network ID used here must match the network ID used by the service connection policy.
         Otherwise, the create operation fails
    - arg_name: auth-mode
      api_field: cluster.authorizationMode
      help_text: |
        Available authorization mode of a Redis cluster.
      choices:
      - enum_value: AUTH_MODE_DISABLED
        arg_value: disabled
        help_text: |
            Authorization is disabled for the cluster.
      - enum_value: AUTH_MODE_IAM_AUTH
        arg_value: iam-auth
        help_text: |
            IAM basic authorization is enabled for the cluster.
    - arg_name: replica-count
      api_field: cluster.replicaCount
      type: int
      help_text: |
        The replica count of each shard.
    - arg_name: shard-count
      api_field: cluster.shardCount
      type: int
      help_text: |
        The shard count of the cluster.
    - arg_name: transit-encryption-mode
      api_field: cluster.transitEncryptionMode
      help_text: |
        Transit encryption mode used for the Redis cluster.
        If not provided, encryption is disabled for the cluster.
      choices:
      - enum_value: TRANSIT_ENCRYPTION_MODE_DISABLED
        arg_value: disabled
        help_text: |
          In-transit encryption is disabled for the cluster.
      - enum_value: TRANSIT_ENCRYPTION_MODE_SERVER_AUTHENTICATION
        arg_value: server-authentication
        help_text: |
          The cluster uses server managed encryption for in-transit encryption.
    - arg_name: deletion-protection
      api_field: cluster.deletionProtectionEnabled
      type: bool
      # To distinguish b/w unset and default value. Otherwise, the request is always sent with
      # deletionProtectionEnabled=false.
      default: null
      help_text: |
        Enable deletion protection for the Redis Cluster. Use
        `--deletion-protection`/`--no-deletion-protection` to enable/disable it.
    - arg_name: redis-config
      api_field: cluster.redisConfigs.additionalProperties
      metavar: KEY=VALUE
      help_text: |
        A list of Redis config KEY=VALUE pairs to set on the Redis Cluster according to
        http://redis.io/topics/config. Currently the supported Redis configs are:

          maxmemory-clients, maxmemory, maxmemory-policy, notify-keyspace-events,
          slowlog-log-slower-than, maxclients.
      type:
        arg_dict:
          flatten: true
          spec:
          - api_field: key
          - api_field: value
    - arg_name: zone-distribution-mode
      api_field: cluster.zoneDistributionConfig.mode
      help_text: |
        Determines how the cluster nodes are distributed across zones.
      choices:
      - enum_value: MULTI_ZONE
        arg_value: multi-zone
        help_text: |
          Allocate cluster nodes across multiple zones.
      - enum_value: SINGLE_ZONE
        arg_value: single-zone
        help_text: |
          Allocate cluster nodes in a single zone.
    - arg_name: zone
      api_field: cluster.zoneDistributionConfig.zone
      help_text: |
        The zone used to allocate the cluster nodes. Applicable only if the zone-distribution-mode
        is set to single-zone.
    - arg_name: persistence-mode
      api_field: cluster.persistenceConfig.mode
      help_text: |
        Operation mode for persistence.
      choices:
      - enum_value: DISABLED
        arg_value: disabled
        help_text: Persistence mode is disabled
      - enum_value: RDB
        arg_value: RDB
        help_text: RDB-based persistence
      - enum_value: AOF
        arg_value: AOF
        help_text: AOF-based persistence
    - arg_name: rdb-snapshot-period
      api_field: cluster.persistenceConfig.rdbConfig.rdbSnapshotPeriod
      help_text: |
        Attempted period between RDB snapshots.
      choices:
      - enum_value: ONE_HOUR
        arg_value: 1h
        help_text: 1 hour
      - enum_value: SIX_HOURS
        arg_value: 6h
        help_text: 6 hours
      - enum_value: TWELVE_HOURS
        arg_value: 12h
        help_text: 12 hours
      - enum_value: TWENTY_FOUR_HOURS
        arg_value: 24h
        help_text: (default) 24 hours
    - arg_name: rdb-snapshot-start-time
      api_field: cluster.persistenceConfig.rdbConfig.rdbSnapshotStartTime
      help_text: |
        Date and time of the first snapshot in the ISO 1801 format, and alignment time for future snapshots. For example, 2024-01-01T01:00:00Z.
        If not specified, the current time will be used.
    - arg_name: aof-append-fsync
      api_field: cluster.persistenceConfig.aofConfig.appendFsync
      help_text: |
        Fsync configuration.
      choices:
      - enum_value: NO  # yamllint disable-line rule:truthy
        arg_value: no  # yamllint disable-line rule:truthy
        help_text: |
          Redis will not explicitly call fsync.
      - enum_value: EVERYSEC
        arg_value: everysec
        help_text: |
          (default) Redis explicitly calls fsync every second.
      - enum_value: ALWAYS
        arg_value: always
        help_text: |
          Redis explicitly calls fsync for every write command.
    - arg_name: maintenance-window-day
      api_field: cluster.maintenancePolicy.weeklyMaintenanceWindow.day
      choices:
      - arg_value: monday
        enum_value: MONDAY
      - arg_value: tuesday
        enum_value: TUESDAY
      - arg_value: wednesday
        enum_value: WEDNESDAY
      - arg_value: thursday
        enum_value: THURSDAY
      - arg_value: friday
        enum_value: FRIDAY
      - arg_value: saturday
        enum_value: SATURDAY
      - arg_value: sunday
        enum_value: SUNDAY
      help_text: |
          Day of week when the window starts, e.g. `sunday`.
    - arg_name: maintenance-window-hour
      api_field: cluster.maintenancePolicy.weeklyMaintenanceWindow.startTime.hours
      help_text: |
        Hour of day (`0` to `23`) for the start of maintenance window, in UTC time zone.
      processor: googlecloudsdk.command_lib.redis.clusters_update_util:CheckMaintenanceWindowStartTimeField
    - arg_name: cross-cluster-replication-role
      api_field: cluster.crossClusterReplicationConfig.clusterRole
      help_text: |
        The role of the cluster in cross cluster replication.
      choices:
      - enum_value: SECONDARY
        arg_value: secondary
        help_text: |
         Create a secondary cluster.
    - arg_name: primary-cluster
      api_field: cluster.crossClusterReplicationConfig.primaryCluster.cluster
      help_text: |
        The primary cluster that the secondary cluster will replicate from. It must use the format:
        projects/PROJECT_ID/locations/REGION/clusters/CLUSTER_ID. It must refer to an existing cluster. Otherwise, the create operation fails.
    - arg_name: automated-backup-mode
      api_field: cluster.automatedBackupConfig.automatedBackupMode
      help_text: |
        Automated backup mode
      choices:
      - enum_value: DISABLED
        arg_value: disabled
        help_text: |
          (default) Automated backup is disabled.
      - enum_value: ENABLED
        arg_value: enabled
        help_text: |
          Automated backup is enabled.
    - arg_name: automated-backup-start-time
      api_field: cluster.automatedBackupConfig.fixedFrequencySchedule.startTime
      help_text: |
        One-hour window when you want automated-backup operations to start. Specify the time in the format HH:00 on a 24-hour cycle in UTC time.
      ALPHA:
        processor: googlecloudsdk.command_lib.redis.cluster_util:ParseTimeOfDayAlpha
      BETA:
        processor: googlecloudsdk.command_lib.redis.cluster_util:ParseTimeOfDayBeta
      GA:
        processor: googlecloudsdk.command_lib.redis.cluster_util:ParseTimeOfDayGa
    - arg_name: automated-backup-ttl
      api_field: cluster.automatedBackupConfig.retention
      type: googlecloudsdk.core.util.times:ParseDuration
      processor: googlecloudsdk.core.util.times:FormatDurationForJson
      help_text: |
        Time to live for automated backups. A backup will be deleted automatically after the TTL
        is reached. It ranges from 1 day to 365 days. For example, "10d" for 10 days. If not specified, the default value is 35 days.
    - group:
        mutex: true
        params:
        - arg_name: import-gcs-object-uris
          type: 'googlecloudsdk.calliope.arg_parsers:ArgList:'
          api_field: cluster.gcsSource.uris
          help_text: |
            URIs of Google Cloud Storage objects to import from. For example, `gs://bucket/folder/file1.rdb,gs://bucket/folder/file2.rdb`.
        - arg_name: import-managed-backup
          api_field: cluster.managedBackupSource.backup
          help_text: |
            Managed backup to import from. For example, `projects/PROJECT_ID/locations/REGION/backupCollections/BACKUP_COLLECTION_ID/backups/BACKUP_ID`.
    - arg_name: kms-key
      api_field: cluster.kmsKey
      help_text: |
        The resource name of the customer-managed encryption key (CMEK) to use for the cluster.
        It must use this format:
        projects/PROJECT_ID/locations/LOCATION/keyRings/KEY_RING/cryptoKeys/CRYPTO_KEY.
        The key must be in the same region as the cluster. Otherwise, the create operation fails.
    - arg_name: server-ca-mode
      api_field: cluster.serverCaMode
      release_tracks: [ALPHA]
      hidden: true
      help_text: |
        Server CA mode for the cluster. This field is immutable.
      choices:
      - enum_value: SERVER_CA_MODE_UNSPECIFIED
        arg_value: unspecified
        help_text: |
          The Server CA mode isn't specified.
      - enum_value: SERVER_CA_MODE_GOOGLE_MANAGED_PER_INSTANCE_CA
        arg_value: google-managed-per-instance-ca
        help_text: |
          Each cluster has its unique Google-managed CA infrastructure.
      - enum_value: SERVER_CA_MODE_GOOGLE_MANAGED_SHARED_CA
        arg_value: google-managed-shared-ca
        help_text: |
          The cluster uses the Google-managed shared CA infrastructure for the region.
      - enum_value: SERVER_CA_MODE_CUSTOMER_MANAGED_CAS_CA
        arg_value: customer-managed-cas-ca
        help_text: |
          The cluster uses a customer-managed CA from Google Cloud Certificate Authority Service (CAS).
    - arg_name: server-ca-pool
      api_field: cluster.serverCaPool
      release_tracks: [ALPHA]
      hidden: true
      help_text: |
        The customer-managed Certificate Authority Service CA Pool resource name to use for issuing server certificates. Format: projects/{project}/locations/{region}/caPools/{ca_pool}. This is applicable only if --server-ca-mode is set to customer-managed-cas-ca. This field is immutable.
    labels:
      api_field: cluster.labels

  async:
    collection: redis.projects.locations.operations

  request:
    ALPHA:
      api_version: v1alpha1
    BETA:
      api_version: v1beta1
    GA:
      api_version: v1
    collection: redis.projects.locations.clusters

  output:
    format: yaml
