variable "resource_group_name_prefix" { default = "rg" description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." }
variable "resource_group_location" { default = "koreacentral" description = "Location of the resource group." }
# Create network interface resource "azurerm_network_interface" "myterraformnic" { name = "myNIC" => 자원을 만든 후 리스트 내에서 불리는 이름 location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name
# Connect the security group to the network interface resource "azurerm_network_interface_security_group_association" "example" { => NIC와 보안 그룹을 연결 network_interface_id = azurerm_network_interface.myterraformnic.id network_security_group_id = azurerm_network_security_group.myterraformnsg.id }
# Create (and display) an SSH key resource "tls_private_key" "example_ssh" { => tls(Transfet layer security) : 암호화 키를 만드는 tls프로토콜을 이용해 키 페어를 생성 algorithm = "RSA" rsa_bits = 4096 }
새 키 만들기JSON 유형의 키 만들기, 이후 윈도우 다운로드 폴더에서 키 파일 이름을 credentials.json으로 변경
/root/gcp-set에 credentials.json 업로드
gcp_terraform
# git clone https://github.com/hali-linux/gcp_set.git # vi provider.tf
provider "google" { credentials = file("credentials.json") => credentials 파일을 통해 자격증명 project = "gcp-gcp-skk0705" => 프로젝트의 ID를 가져옴 region = "asia-northeast3" zone = "asia-northeast3-a" }
# vi main.tf
resource "google_compute_network" "custom-test" { name = "new-vpc" auto_create_subnetworks = false => auto로 만들 것이 아니므로 false }
resource "google_compute_firewall" "http-server" { name = "default-allow-http-terraform" network = "new-vpc"
allow { protocol = "tcp" ports = ["80"] }
// Allow traffic from everywhere to instances with an http-server tag source_ranges = ["0.0.0.0/0"] target_tags = ["http-server"] }
resource "google_compute_firewall" "ssh-server" { name = "default-allow-ssh-terraform" network = "new-vpc"
access_config { // Include this section to give the VM an external ip address } }
metadata_startup_script = file("/root/gcp_set/script.txt") => 절대 경로로 쓰지 않으면 인식 하지 못함 // Apply the firewall rule to allow external IPs to access this instance tags = ["http-server"] }
# vi output.tf
output "ip" { value = "${google_compute_instance.default.network_interface.0.access_config.0.nat_ip}" } # terraform init # terraform plan # terraform apply # terraform output ip
Known host 애러
known host : 이 서버가 믿을 수 있는 서버인지 기록해 놓음known host를 지웠다가 다시 ssh 접근 하면 됨
Ansible
스페이스바 눌러야 체크됨ssh접속 후, sudo vi /etc/ssh/sshd_config루트 계정으로 우분투에 접속할 수 있도록 셋팅(ansible은 ssh 접근이 필요)
루트 계정으로 접속해서 비밀번호 설정 후 다시 일반 사용자로 가서 sudo systemctl restart sshd
루트 계정으로 로그인 완료
- 이후 poweroff 시켜주고 virtualBox 매니져에서 가상 시스템 내보내기 실행