본문 바로가기
공부/AWS

[AWS/EC2] Proxy Setup user_data (Linux, Windows)

by haejang 2024. 7. 9.
728x90
728x90

 

 

# Linux

# linux.sh
#!/bin/bash
PROXY_URL="http://proxy.domain:3128"
NO_PROXY="169.254.169.254,localhost,127.0.0.1,.svc.cluster.local,.amazonaws.com,172.16.0.0/12,10.0.0.0/8,192.168.0.0/16,.internal"

echo "export http_proxy=$PROXY_URL" | tee -a /etc/profile.d/proxy.sh
echo "export https_proxy=$PROXY_URL" | tee -a /etc/profile.d/proxy.sh
echo "export no_proxy=$NO_PROXY" | tee -a /etc/profile.d/proxy.sh
source /etc/profile.d/proxy.sh

 

 

# Windows

# windows.ps1
<powershell>
$proxyUrl = "proxy.domain:3128"
$proxyOverride = "<local>;*.amazonaws.com;127.0.0.1;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*"

Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyEnable -Value 1
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyServer -Value $proxyUrl
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings" -Name ProxyOverride -Value $proxyOverride
</powershell>

 

 

# in Terraform

locals {
  ami_os           = # 알아서 linux인지 windows인지 구분하기
  user_data_file   = local.ami_os == "linux" ? "linux.sh" : "windows.ps1"
  user_data_script = file("${path.module}/${local.user_data_file}")
}

resource "aws_instance" "this" {
  # 매개변수 입력
  user_data = local.user_data_script
}

 

 

# 참조 (Powershell)

https://www.techcrafters.com/portal/en/kb/articles/powershell-comprehensive-guide-to-configuring-proxy-settings-on-windows#Starting_with_PowerShell

 

 

끝~

 

 

728x90
728x90

댓글