Skip to content

Commit

Permalink
learn(tf): practising local-exec in dept
Browse files Browse the repository at this point in the history
  • Loading branch information
Trex-Hub committed Jun 19, 2024
1 parent 57012a4 commit 4a9ceb9
Show file tree
Hide file tree
Showing 5 changed files with 390 additions and 297 deletions.
65 changes: 65 additions & 0 deletions AWS Automation/env.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
GJS_DEBUG_TOPICS=JS ERROR;JS LOG
LESSOPEN=| /usr/bin/lesspipe %s
USER=dev
XDG_SESSION_TYPE=x11
GIT_ASKPASS=/usr/share/code/resources/app/extensions/git/dist/askpass.sh
host=localhost
SHLVL=1
HOME=/home/dev
CHROME_DESKTOP=code-url-handler.desktop
TERM_PROGRAM_VERSION=1.90.1
DESKTOP_SESSION=ubuntu
NVM_BIN=/home/dev/.nvm/versions/node/v20.9.0/bin
NVM_INC=/home/dev/.nvm/versions/node/v20.9.0/include/node
GIO_LAUNCHED_DESKTOP_FILE=/usr/share/applications/code.desktop
GNOME_SHELL_SESSION_MODE=ubuntu
GTK_MODULES=gail:atk-bridge
VSCODE_GIT_ASKPASS_MAIN=/usr/share/code/resources/app/extensions/git/dist/askpass-main.js
VSCODE_GIT_ASKPASS_NODE=/usr/share/code/code
MANAGERPID=2844
SYSTEMD_EXEC_PID=3212
GSM_SKIP_SSH_AGENT_WORKAROUND=true
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
COLORTERM=truecolor
GIO_LAUNCHED_DESKTOP_FILE_PID=6887
NVM_DIR=/home/dev/.nvm
DEBUGINFOD_URLS=https://debuginfod.ubuntu.com
LOGNAME=dev
JOURNAL_STREAM=8:25652
_=/usr/local/bin/terraform
MEMORY_PRESSURE_WATCH=/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/session.slice/org.gnome.Shell@x11.service/memory.pressure
XDG_SESSION_CLASS=user
USERNAME=dev
TERM=xterm-256color
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
WINDOWPATH=2
PATH=/home/dev/.nvm/versions/node/v20.9.0/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:/usr/bin:/usr/bin:/usr/bin:/usr/bin
SESSION_MANAGER=local/dev-B85M-D3H:@/tmp/.ICE-unix/3181,unix/dev-B85M-D3H:/tmp/.ICE-unix/3181
INVOCATION_ID=fb3e46bff8544e66ac1ab89ca0359f21
XDG_MENU_PREFIX=gnome-
XDG_RUNTIME_DIR=/run/user/1000
GDK_BACKEND=x11
DISPLAY=:1
LANG=en_US.UTF-8
XDG_CURRENT_DESKTOP=Unity
XMODIFIERS=@im=ibus
XDG_SESSION_DESKTOP=ubuntu
XAUTHORITY=/run/user/1000/gdm/Xauthority
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=00:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.avif=01;35:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:*~=00;90:*#=00;90:*.bak=00;90:*.crdownload=00;90:*.dpkg-dist=00;90:*.dpkg-new=00;90:*.dpkg-old=00;90:*.dpkg-tmp=00;90:*.old=00;90:*.orig=00;90:*.part=00;90:*.rej=00;90:*.rpmnew=00;90:*.rpmorig=00;90:*.rpmsave=00;90:*.swp=00;90:*.tmp=00;90:*.ucf-dist=00;90:*.ucf-new=00;90:*.ucf-old=00;90:
VSCODE_GIT_IPC_HANDLE=/run/user/1000/vscode-git-145185e0d2.sock
TERM_PROGRAM=vscode
SSH_AUTH_SOCK=/run/user/1000/keyring/ssh
ORIGINAL_XDG_CURRENT_DESKTOP=ubuntu:GNOME
SHELL=/bin/bash
QT_ACCESSIBILITY=1
GDMSESSION=ubuntu
LESSCLOSE=/usr/bin/lesspipe %s %s
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
GJS_DEBUG_OUTPUT=stderr
VSCODE_GIT_ASKPASS_EXTRA_ARGS=
QT_IM_MODULE=ibus
PWD=/home/dev/Desktop/Terraform Learning /AWS Automation
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
NVM_CD_FLAGS=
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
MEMORY_PRESSURE_WRITE=c29tZSAyMDAwMDAgMjAwMDAwMAA=
44 changes: 36 additions & 8 deletions AWS Automation/instance.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,63 @@ resource "aws_instance" "First-TF-Instance" {
tags = {
Name = "First-TF-Instance"
}
# This will run the script.sh file on the EC2 instance
user_data = file("${path.module}/script.sh")

connection {
# This will connect to the EC2 instance using SSH
# This will use the private key to connect to the EC2 instance
# This will use the ec2-user as the user
# This will use the public IP of the EC2 instance
type = "ssh"
user = "ec2-user"
private_key = file("${path.module}/id_rsa")
host = self.public_ip
}
provisioner "file" {
source = "Readme.MD"
destination = "/tmp/Readme.MD"
source = "Readme.MD" # This file should be in the same directory as the instance.tf file
destination = "/tmp/Readme.MD" # This is the destination path on the EC2 instance
}
provisioner "file" {
content = "This is test content"
content = "This is test content" # This is the content that will be written to the file
destination = "/tmp/Content.MD"
}
provisioner "file" {
source = "test-folder"
source = "test-folder" # This is the folder that will be copied to the EC2 instance
destination = "/tmp/test-folder/"
}

provisioner "local-exec" {
command = "echo ${self.public_ip} > ip_address.txt "
command = "echo ${self.public_ip} > ip_address.txt " # This will write the public IP of the EC2 instance to the file
}

provisioner "local-exec" {
interpreter = [
interpreter = [
"/usr/bin/python3", "-c"
]
command = "print('Hello World')"
]
command = "print('Hello World')" # This will run the python code on the local machine
}

provisioner "local-exec" {
# This will run only once when the resource is created
# This will create a file with the environment variables
command = "env > env.txt"
environment = {
host = "localhost"
}

}

provisioner "local-exec" {
when = destroy # This will only run when the resource is destroyed
command = "echo 'Destroying...'"
}

provisioner "local-exec" {
# This will run only once when the resource is created
command = "echo 'Creating Resources...'"
}

}


2 changes: 1 addition & 1 deletion AWS Automation/ip_address.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
13.235.23.207
3.110.212.213
Loading

0 comments on commit 4a9ceb9

Please sign in to comment.