Skip to content

Commit 3762731

Browse files
kunzesesce-taid
authored andcommitted
feat: allow the use of an existing GCS bucket
PiperOrigin-RevId: 781576884
1 parent 961f5aa commit 3762731

File tree

7 files changed

+40
-2
lines changed

7 files changed

+40
-2
lines changed

modules/server/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ For example usage, please check the following [example](../../examples/simple/ma
1717
| abfs\_bucket\_name | The name of the ABFS bucket. | `string` | `"abfs"` | no |
1818
| abfs\_docker\_image\_uri | Docker image URI for the ABFS server | `string` | n/a | yes |
1919
| abfs\_license | ABFS license (JSON) | `string` | n/a | yes |
20+
| abfs\_server\_allow\_stopping\_for\_update | Allow to stop the server to update properties | `bool` | `true` | no |
2021
| abfs\_server\_cos\_image\_ref | Reference to the COS boot image to use for the ABFS server | `string` | `"projects/cos-cloud/global/images/family/cos-109-lts"` | no |
2122
| abfs\_server\_machine\_type | Machine type for ABFS servers | `string` | `"n2-highmem-128"` | no |
2223
| abfs\_server\_name | Name for the ABFS server | `string` | `"abfs-server"` | no |
2324
| abfs\_spanner\_database\_name | A unique identifier for the ABFS database, which cannot be changed after the instance is created. | `string` | `"abfs"` | no |
2425
| abfs\_spanner\_instance\_config | The name of the instance's configuration (similar but not quite the same as a region) which defines the geographic placement and replication of your ABFS database in this instance. | `string` | n/a | yes |
2526
| abfs\_spanner\_instance\_display\_name | The descriptive name for the ABFS instance as it appears in UIs. | `string` | `"ABFS"` | no |
2627
| abfs\_spanner\_instance\_name | A unique identifier for the ABFS instance, which cannot be changed after the instance is created. | `string` | `"abfs"` | no |
28+
| existing\_bucket\_name | The name of the existing ABFS bucket to use. If not specified, a new bucket will be created. | `string` | `""` | no |
2729
| goog\_cm\_deployment\_name | The name of the deployment for Marketplace | `string` | `""` | no |
2830
| project\_id | Google Cloud project ID | `string` | n/a | yes |
2931
| service\_account\_email | Email of service account to attach to the servers | `string` | n/a | yes |

modules/server/gcs.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,30 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
moved {
16+
from = google_storage_bucket.abfs
17+
to = google_storage_bucket.abfs[0]
18+
}
19+
20+
moved {
21+
from = random_bytes.abfs_bucket_prefix
22+
to = random_bytes.abfs_bucket_prefix[0]
23+
}
24+
25+
data "google_storage_bucket" "abfs" {
26+
project = var.project_id
27+
name = var.existing_bucket_name == "" ? google_storage_bucket.abfs[0].name : var.existing_bucket_name
28+
}
29+
1530
resource "random_bytes" "abfs_bucket_prefix" {
31+
count = var.existing_bucket_name == "" ? 1 : 0
1632
length = 2
1733
}
1834

1935
resource "google_storage_bucket" "abfs" {
36+
count = var.existing_bucket_name == "" ? 1 : 0
2037
project = var.project_id
21-
name = "${var.abfs_bucket_name}-${random_bytes.abfs_bucket_prefix.hex}"
38+
name = "${var.abfs_bucket_name}-${random_bytes.abfs_bucket_prefix[0].hex}"
2239
location = var.abfs_bucket_location
2340
public_access_prevention = "enforced"
2441
uniform_bucket_level_access = true

modules/server/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ data "cloudinit_config" "abfs_server" {
136136
envs = {
137137
"ABFS_CMD" = <<-EOT
138138
--project ${google_spanner_instance.abfs.project} \
139-
--bucket ${google_storage_bucket.abfs.name} \
139+
--bucket ${data.google_storage_bucket.abfs.name} \
140140
--instance ${google_spanner_instance.abfs.name} \
141141
--db ${google_spanner_database.abfs.name}
142142
EOT

modules/server/metadata.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ spec:
4848
description: Email of service account to attach to the servers
4949
varType: string
5050
required: true
51+
- name: abfs_server_allow_stopping_for_update
52+
description: Allow to stop the server to update properties
53+
varType: bool
54+
defaultValue: true
5155
- name: abfs_server_machine_type
5256
description: Machine type for ABFS servers
5357
varType: string
@@ -76,6 +80,10 @@ spec:
7680
description: The PD regional disk type to use for the ABFS bootdisk
7781
varType: string
7882
defaultValue: pd-ssd
83+
- name: existing_bucket_name
84+
description: The name of the existing ABFS bucket to use. If not specified, a new bucket will be created.
85+
varType: string
86+
defaultValue: ""
7987
- name: abfs_bucket_name
8088
description: The name of the ABFS bucket.
8189
varType: string

modules/server/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ variable "abfs_bootdisk_type" {
8585
}
8686

8787
// Google Cloud Storage
88+
variable "existing_bucket_name" {
89+
type = string
90+
description = "The name of the existing ABFS bucket to use. If not specified, a new bucket will be created."
91+
default = ""
92+
}
93+
8894
variable "abfs_bucket_name" {
8995
type = string
9096
description = "The name of the ABFS bucket."

modules/uploaders/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ For example usage, please check the following [example](../../examples/simple/ma
1414
| abfs\_datadisk\_mountpoint | Location for mounting the ABFS datadisk on the host VM | `string` | `"/mnt/disks/abfs-data"` | no |
1515
| abfs\_docker\_image\_uri | Docker image URI for the ABFS uploader | `string` | n/a | yes |
1616
| abfs\_enable\_git\_lfs | Enable Git LFS support | `bool` | `false` | no |
17+
| abfs\_gerrit\_uploader\_allow\_stopping\_for\_update | Allow to stop uploaders to update properties | `bool` | `true` | no |
1718
| abfs\_gerrit\_uploader\_count | The number of gerrit uploader instances to create | `number` | `3` | no |
1819
| abfs\_gerrit\_uploader\_datadisk\_name\_prefix | A name prefix for the ABFS gerrit uploader datadisk(s) that will be attached to VM(s). Note, this does not affect the mounting of the disk - the device name is always set to "abfs-server-storage" | `string` | `"abfs-gerrit-uploader-datadisk"` | no |
1920
| abfs\_gerrit\_uploader\_datadisk\_size\_gb | Size in GB for the ABFS gerrit uploader datadisk(s) that will be attached to the VM(s) | `number` | `4096` | no |

modules/uploaders/metadata.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ spec:
4848
description: Email of service account to attach to the servers
4949
varType: string
5050
required: true
51+
- name: abfs_gerrit_uploader_allow_stopping_for_update
52+
description: Allow to stop uploaders to update properties
53+
varType: bool
54+
defaultValue: true
5155
- name: abfs_gerrit_uploader_count
5256
description: The number of gerrit uploader instances to create
5357
varType: number

0 commit comments

Comments
 (0)