Skip to content

Commit 8eeb945

Browse files
author
Rene Schönfelder
committed
added s3 config inside of the vm
1 parent f78d8bb commit 8eeb945

File tree

9 files changed

+101
-5
lines changed

9 files changed

+101
-5
lines changed

modules/cloud-init/simple-setup-init.tftpl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,29 @@ runcmd:
3939
- chmod a+w ${shared_filesystem_mount}
4040
- echo "filesystem-0 ${shared_filesystem_mount} virtiofs rw 0 0" >> /etc/fstab
4141
%{endif}
42+
43+
# install s3 access
44+
45+
- snap install aws-cli --classic
46+
47+
%{ for user in users}
48+
- mkdir -p /home/${user.user_name}/.aws
49+
- echo "[default]" > /home/${user.user_name}/.aws/credentials
50+
- echo "aws_access_key_id=${aws_access_key_id}" >> /home/${user.user_name}/.aws/credentials
51+
- echo "aws_secret_access_key=${aws_secret_access_key}" >> /home/${user.user_name}/.aws/credentials
52+
- echo "[default]" > /home/${user.user_name}/.aws/config
53+
- echo "endpoint_url = https://storage.eu-north1.nebius.cloud:443" >> /home/${user.user_name}/.aws/config
54+
- echo "region = eu-north1" >> /home/${user.user_name}/.aws/config
55+
- chown -R ${user.user_name}:${user.user_name} /home/${user.user_name}/.aws
56+
- chmod 600 /home/${user.user_name}/.aws/credentials
57+
%{ endfor }
58+
59+
- mkdir -p /root/.aws
60+
- echo "[default]" > /root/.aws/credentials
61+
- echo "aws_access_key_id=${aws_access_key_id}" >> /root/.aws/credentials
62+
- echo "aws_secret_access_key=${aws_secret_access_key}" >> /root/.aws/credentials
63+
- echo "[default]" > /root/.aws/config
64+
- echo "endpoint_url = https://storage.eu-north1.nebius.cloud:443" >> /root/.aws/config
65+
- echo "region = eu-north1" >> /root/.aws/config
66+
67+

modules/instance/locals.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ locals {
3939
extra_disk_id = local.extra_disk_id
4040
state = terraform.workspace
4141
users = local.users
42+
4243
})
4344
# current_region_defaults = local.regions_default[var.region]
4445
#

modules/instance/main.tf

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ resource "nebius_compute_v1_instance" "instance" {
6565
extra_path = local.extra_path,
6666
extra_disk_id = local.extra_disk_id,
6767
shared_filesystem_id = var.shared_filesystem_id,
68-
shared_filesystem_mount = var.shared_filesystem_mount
68+
shared_filesystem_mount = var.shared_filesystem_mount,
69+
aws_access_key_id = var.aws_access_key_id,
70+
aws_secret_access_key = var.aws_secret_access_key
6971
})
7072
}
7173

7274
resource "local_file" "cloud_init_variables_log" {
7375
content = local.cloud_init_log
7476
filename = "${path.module}/cloud-init-variables.log"
77+
78+
7579
}

modules/instance/variables.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,25 @@ variable "public_ip" {
9797
default = true
9898
description = "attach a public ip to the vm if true"
9999
}
100+
variable "mount_bucket" {
101+
type = string
102+
description = "name of a bucket that should be mounted into fs"
103+
default = ""
104+
}
105+
106+
variable "s3_mount_path" {
107+
type = string
108+
description = "mountpoint for s3 mount"
109+
default = "/mnt/s3"
110+
}
111+
variable "aws_access_key_id" {
112+
type = string
113+
description = "S3 access key"
114+
default = ""
115+
}
116+
117+
variable "aws_secret_access_key" {
118+
type = string
119+
description = "S3 access key"
120+
default = ""
121+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
NEBIUS_TENANT_ID=''
2-
NEBIUS_PROJECT_ID=''
1+
NEBIUS_TENANT_ID='tenant-e00f3wdfzwfjgbcyfv'
2+
NEBIUS_PROJECT_ID='project-e00z6b02t8ddk96c49'
33

44
if [ -z "${NEBIUS_TENANT_ID}" ]; then
55
echo "Error: NEBIUS_TENANT_ID is not set"

simple-solutions/vm-instance/.envrc.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ DATE_FORMAT='+%Y-%m-%dT%H:%M:%SZ'
225225

226226
if [[ "$(uname)" == "Darwin" ]]; then
227227
# macOS
228-
EXPIRATION_DATE=$(date -v +1d "${DATE_FORMAT}")
228+
EXPIRATION_DATE=$(date -v +14d "${DATE_FORMAT}")
229229
else
230230
# Linux (assumes GNU date)
231-
EXPIRATION_DATE=$(date -d '+1 day' "${DATE_FORMAT}")
231+
EXPIRATION_DATE=$(date -d '+14 day' "${DATE_FORMAT}")
232232
fi
233233

234234
echo 'Creating new access key for Object Storage'
@@ -280,6 +280,20 @@ else
280280
echo "Using existing bucket: ${NEBIUS_BUCKET_NAME}"
281281
fi
282282

283+
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
284+
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
285+
aws configure set region eu-north1
286+
aws configure set endpoint_url https://storage.eu-north1.nebius.cloud:443
287+
mkdir -p ./.aws
288+
echo "[default]" > ./.aws/credentials
289+
echo "aws_access_key_id = $AWS_ACCESS_KEY_ID" >> ./.aws/credentials
290+
echo "aws_secret_access_key = $AWS_SECRET_ACCESS_KEY" >> ./.aws/credentials
291+
echo "[default]" > ./.aws/config
292+
echo "region = eu-north1" >> ./.aws/config
293+
echo "endpoint_url = https://storage.eu-north1.nebius.cloud:443" >> ./.aws/config
294+
export TF_VAR_aws_access_key_id=$AWS_ACCESS_KEY_ID
295+
export TF_VAR_aws_secret_access_key=$AWS_SECRET_ACCESS_KEY
296+
283297
# endregion Bucket
284298

285299
# region Backend override

simple-solutions/vm-instance/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,8 @@ module "instance-module" {
1717
add_extra_storage = var.add_extra_storage
1818
extra_storage_size_gb = var.extra_storage_size_gb
1919
public_ip = var.public_ip
20+
mount_bucket = var.mount_bucket
21+
s3_mount_path = var.s3_mount_path
22+
aws_access_key_id = var.aws_access_key_id
23+
aws_secret_access_key = var.aws_secret_access_key
2024
}

simple-solutions/vm-instance/terraform.tfvars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ public_ip = true
2424
instance_count = 1
2525

2626
shared_filesystem_id = ""
27+
mount_bucket = "renes-bucket"

simple-solutions/vm-instance/variables.tf

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,27 @@ variable "public_ip" {
9090
default = true
9191
description = "attach a public ip to the vm if true"
9292
}
93+
94+
variable "mount_bucket" {
95+
type = string
96+
description = "name of a bucket that should be mounted into fs"
97+
default = ""
98+
}
99+
100+
variable "s3_mount_path" {
101+
type = string
102+
description = "mountpoint for s3 mount"
103+
default = "/mnt/s3"
104+
}
105+
106+
variable "aws_access_key_id" {
107+
type = string
108+
description = "S3 access key"
109+
default = ""
110+
}
111+
112+
variable "aws_secret_access_key" {
113+
type = string
114+
description = "S3 access key"
115+
default = ""
116+
}

0 commit comments

Comments
 (0)