Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webservice
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
masi9606
webservice
Commits
6a0995a6
Commit
6a0995a6
authored
8 months ago
by
schnarkus
Browse files
Options
Downloads
Patches
Plain Diff
allocate a virtual machine in google cloud
parent
32731da5
No related branches found
Branches containing commit
No related tags found
2 merge requests
!4
build new image with ubuntu
,
!3
allocate a virtual machine in google cloud
Pipeline
#64333
passed
8 months ago
Stage: test
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+3
-0
3 additions, 0 deletions
.gitignore
gcp-vm-setup/main.tf
+64
-0
64 additions, 0 deletions
gcp-vm-setup/main.tf
gcp-vm-setup/terminal.log
+10
-0
10 additions, 0 deletions
gcp-vm-setup/terminal.log
gcp-vm-setup/variables.tf
+23
-0
23 additions, 0 deletions
gcp-vm-setup/variables.tf
with
100 additions
and
0 deletions
.gitignore
+
3
−
0
View file @
6a0995a6
.local
artifact.bin
.terraform
*terraform.*
.ssh
This diff is collapsed.
Click to expand it.
gcp-vm-setup/main.tf
0 → 100644
+
64
−
0
View file @
6a0995a6
terraform
{
required_version
=
">= 1.0"
}
provider
"google"
{
project
=
var
.
projectID
zone
=
var
.
zone
credentials
=
file
(
var
.
gcpCredentialsFilePath
)
}
locals
{
sshUserName
=
"schnarkus"
}
resource
"google_compute_network"
"the_network"
{
name
=
"the-network"
}
resource
"google_compute_firewall"
"gate_guardian"
{
name
=
"gate-guardian"
network
=
google_compute_network
.
the_network
.
name
allow
{
protocol
=
"icmp"
}
allow
{
protocol
=
"tcp"
ports
=
[
"22"
,
"8080"
]
# ssh localhost
}
source_ranges
=
[
"0.0.0.0/0"
]
}
resource
"google_compute_instance"
"schminstance"
{
name
=
"schminstance"
machine_type
=
"e2-micro"
boot_disk
{
initialize_params
{
image
=
data
.
google_compute_image
.
image
.
self_link
}
}
network_interface
{
network
=
google_compute_network
.
the_network
.
name
access_config
{}
}
metadata
=
{
ssh-keys
=
"
${
local
.
sshUserName
}
:
${
file
(
var
.
sshPublicKeyPath
)}
"
}
}
data
"google_compute_image"
"image"
{
family
=
"ubuntu-2004-lts"
project
=
"ubuntu-os-cloud"
}
# get ip and publish
output
"instanceIPv4"
{
description
=
"Public IP address of the Google Compute Engine instance"
value
=
google_compute_instance
.
schminstance
.
network_interface
[
0
].
access_config
[
0
].
nat_ip
}
This diff is collapsed.
Click to expand it.
gcp-vm-setup/terminal.log
0 → 100644
+
10
−
0
View file @
6a0995a6
1272 tofu init
1273 tofu apply
1274 tofu output instanceIPv4
1275 ssh -i ../.ssh/operator -l schnarkus $(tofu output -raw 'instanceIPv4')
1276 scp -i ../.ssh/operator ../artifact.bin schnarkus@$(tofu output -raw 'instanceIPv4'):~/webservice
1277 curl -s http://$(tofu output -raw 'instanceIPv4'):8080
1278 tofu destroy
HOST=0.0.0.0 PORT=8080 ./webservice
\ No newline at end of file
This diff is collapsed.
Click to expand it.
gcp-vm-setup/variables.tf
0 → 100644
+
23
−
0
View file @
6a0995a6
variable
"sshPublicKeyPath"
{
type
=
string
description
=
"Path to the public part of the SSH key pair"
default
=
"../.ssh/operator.pub"
}
variable
"gcpCredentialsFilePath"
{
type
=
string
description
=
"Path to a GCP credentials file (e.g., service account key)"
default
=
"~/.gcp/keyfile.json"
}
variable
"projectID"
{
type
=
string
description
=
"ID of a project within GCP"
default
=
"bht-devops24-ss"
}
variable
"zone"
{
type
=
string
description
=
"GCP zone to deploy resources in"
default
=
"europe-west3-b"
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment