Skip to content

Commit 4bfae9a

Browse files
Removed template_file data to support ARM in GCP (#628)
Signed-off-by: HareshKumarkj <[email protected]>
1 parent 6aa23f1 commit 4bfae9a

File tree

3 files changed

+44
-43
lines changed

3 files changed

+44
-43
lines changed

resources/gcp/compute/vm_instance_0_disk/vm_instance_0_disk.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ data "google_compute_machine_types" "itself" {
4242
zone = var.zone
4343
}
4444

45-
data "template_file" "metadata_startup_script" {
46-
template = <<EOF
47-
#!/usr/bin/env bash
48-
echo "${var.private_key_content}" > ~/.ssh/id_rsa
49-
chmod 600 ~/.ssh/id_rsa
50-
echo "StrictHostKeyChecking no" >> ~/.ssh/config
51-
EOF
45+
locals {
46+
user_data = <<-EOT
47+
#!/usr/bin/env bash
48+
echo "${var.private_key_content}" > ~/.ssh/id_rsa
49+
chmod 600 ~/.ssh/id_rsa
50+
echo "StrictHostKeyChecking no" >> ~/.ssh/config
51+
EOT
5252
}
5353

5454
#tfsec:ignore:google-compute-enable-shielded-vm-im
@@ -90,7 +90,7 @@ resource "google_compute_instance" "itself" {
9090
vmdnssetting = var.is_multizone ? "GlobalDefault" : "ZonalOnly"
9191
}
9292

93-
metadata_startup_script = data.template_file.metadata_startup_script.rendered
93+
metadata_startup_script = local.user_data
9494

9595
service_account {
9696
email = var.service_email

resources/gcp/compute/vm_instance_ip_fwd/vm_instance_ip_fwd.tf

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,16 @@ data "google_kms_crypto_key" "itself" {
4343
key_ring = data.google_kms_key_ring.itself[0].id
4444
}
4545

46-
data "template_file" "metadata_startup_script" {
47-
template = <<EOF
48-
#!/usr/bin/env bash
49-
echo "${var.private_key_content}" > ~/.ssh/id_rsa
50-
chmod 600 ~/.ssh/id_rsa
51-
echo "StrictHostKeyChecking no" >> ~/.ssh/config
52-
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
53-
sysctl -p
54-
EOF
46+
47+
locals {
48+
user_data = <<-EOT
49+
#!/usr/bin/env bash
50+
echo "${var.private_key_content}" > ~/.ssh/id_rsa
51+
chmod 600 ~/.ssh/id_rsa
52+
echo "StrictHostKeyChecking no" >> ~/.ssh/config
53+
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
54+
sysctl -p
55+
EOT
5556
}
5657

5758
#tfsec:ignore:AVD-GCP-0067
@@ -95,7 +96,7 @@ resource "google_compute_instance" "itself" {
9596
vmdnssetting = var.is_multizone ? "GlobalDefault" : "ZonalOnly"
9697
}
9798

98-
metadata_startup_script = data.template_file.metadata_startup_script.rendered
99+
metadata_startup_script = local.user_data
99100

100101
service_account {
101102
email = var.service_email

resources/gcp/compute/vm_instance_multiple_disk/vm_instance_multiple_disk.tf

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,30 @@ data "google_kms_crypto_key" "itself" {
4141
key_ring = data.google_kms_key_ring.itself[0].id
4242
}
4343

44-
data "template_file" "metadata_startup_script" {
45-
template = <<EOF
46-
#!/usr/bin/env bash
47-
echo "${var.private_key_content}" > ~/.ssh/id_rsa
48-
chmod 600 ~/.ssh/id_rsa
49-
echo "StrictHostKeyChecking no" >> ~/.ssh/config
50-
if [ ! -d "/var/mmfs/etc" ]; then
51-
mkdir -p "/var/mmfs/etc"
52-
fi
53-
echo "#!/bin/ksh" > "/var/mmfs/etc/nsddevices"
54-
echo "# Generated by IBM Storage Scale deployment." >> "/var/mmfs/etc/nsddevices"
55-
%{if length(var.disk) > 0}
56-
%{for key, value in var.disk~}
57-
echo "echo \"disk/by-id/google-${key} generic\"" >> "/var/mmfs/etc/nsddevices"
58-
%{endfor~}
59-
%{else}
60-
%{for key in range(var.total_local_ssd_disks)~}
61-
echo "echo \"disk/by-id/google-local-nvme-ssd-${key} generic\"" >> "/var/mmfs/etc/nsddevices"
62-
%{endfor~}
63-
%{endif}
64-
echo "# Bypass the NSD device discovery" >> "/var/mmfs/etc/nsddevices"
65-
echo "return 0" >> "/var/mmfs/etc/nsddevices"
66-
chmod u+x "/var/mmfs/etc/nsddevices"
67-
EOF
44+
locals {
45+
user_data = <<-EOT
46+
#!/usr/bin/env bash
47+
echo "${var.private_key_content}" > ~/.ssh/id_rsa
48+
chmod 600 ~/.ssh/id_rsa
49+
echo "StrictHostKeyChecking no" >> ~/.ssh/config
50+
if [ ! -d "/var/mmfs/etc" ]; then
51+
mkdir -p "/var/mmfs/etc"
52+
fi
53+
echo "#!/bin/ksh" > "/var/mmfs/etc/nsddevices"
54+
echo "# Generated by IBM Storage Scale deployment." >> "/var/mmfs/etc/nsddevices"
55+
%{if length(var.disk) > 0}
56+
%{for key, value in var.disk~}
57+
echo "echo \"disk/by-id/google-${key} generic\"" >> "/var/mmfs/etc/nsddevices"
58+
%{endfor~}
59+
%{else}
60+
%{for key in range(var.total_local_ssd_disks)~}
61+
echo "echo \"disk/by-id/google-local-nvme-ssd-${key} generic\"" >> "/var/mmfs/etc/nsddevices"
62+
%{endfor~}
63+
%{endif}
64+
echo "# Bypass the NSD device discovery" >> "/var/mmfs/etc/nsddevices"
65+
echo "return 0" >> "/var/mmfs/etc/nsddevices"
66+
chmod u+x "/var/mmfs/etc/nsddevices"
67+
EOT
6868
}
6969

7070
#tfsec:ignore:google-compute-enable-shielded-vm-im
@@ -115,7 +115,7 @@ resource "google_compute_instance" "itself" {
115115
vmdnssetting = var.is_multizone ? "GlobalDefault" : "ZonalOnly"
116116
}
117117

118-
metadata_startup_script = data.template_file.metadata_startup_script.rendered
118+
metadata_startup_script = local.user_data
119119

120120
service_account {
121121
email = var.service_email

0 commit comments

Comments
 (0)