brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Oct 08. 2022

1. 테라폼-GCP-서버 1대 만들기

<1>  GCP 계정 정보 , 프로젝트 정보 확인 

<2> 테라폼으로 서버  만들어 보자.

<3> Console에서 확인

<4> 서버이름 변경해보기




<1>  GCP 계정 정보 , 프로젝트 정보 확인 


1

cloud shell  실행하기

화면 오른쪽 위  편지봉투 모양 아이콘 클릭


2

어카운트 정보 확인

gcloud auth list

승인


ACTIVE: *

ACCOUNT: topasvga0802@proton.me



3

프로젝트 정보 확인

gcloud config list project

[core]

project = seismic-catbird-358207




<2> 테라폼으로 서버  만들어 보자.


1


topasvga0802@cloudshell:~ (seismic-catbird-358207)$  terraform

Usage: terraform [global options] <subcommand> [args]


The available commands for execution are listed below.

The primary workflow commands are given first, followed by

less common or more advanced commands.


Main commands:

  init          Prepare your working directory for other commands

  validate      Check whether the configuration is valid

  plan          Show changes required by the current configuration

  apply         Create or update infrastructure

  destroy       Destroy previously-created infrastructure


All other commands:

  console       Try Terraform expressions at an interactive command prompt

  fmt           Reformat your configuration in the standard style

  force-unlock  Release a stuck lock on the current workspace

  get           Install or upgrade remote Terraform modules

  graph         Generate a Graphviz graph of the steps in an operation

  import        Associate existing infrastructure with a Terraform resource

  login         Obtain and save credentials for a remote host

  logout        Remove locally-stored credentials for a remote host

  output        Show output values from your root module

  providers     Show the providers required for this configuration

  refresh       Update the state to match remote systems

  show          Show the current state or a saved plan

  state         Advanced state management

  taint         Mark a resource instance as not fully functional

  test          Experimental support for module integration testing

  untaint       Remove the 'tainted' state from a resource instance

  version       Show the current Terraform version

  workspace     Workspace management




2

vi instance.tf


resource "google_compute_instance" "terraform" {

  project      = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  name         = "terraform"

  machine_type = "n1-standard-1"

  zone         = "us-west1-c"

  boot_disk {

    initialize_params {

      image = "debian-cloud/debian-11"

    }

  }

  network_interface {

    network = "default"

    access_config {

    }

  }

}



// 위에서 확인한 프로젝트 이름을  xxxxxxxx 대신 입력한다.






3

terraform init


4

terraform plan


5

terraform apply

Enter a value: yes



6

terraform show


topasvga0802@cloudshell:~ (seismic-catbird-358207)$ terraform show

# google_compute_instance.terraform:

resource "google_compute_instance" "terraform" {

    can_ip_forward       = false

    cpu_platform         = "Intel Broadwell"

    current_status       = "RUNNING"

    deletion_protection  = false

    enable_display       = false

    guest_accelerator    = []

    id                   = "projects/seismic-catbird-358207/zones/us-west1-c/instances/terraform"

    instance_id          = "1926731355898298248"

    label_fingerprint    = "42WmSpB8rSM="

    machine_type         = "n1-standard-1"

    metadata_fingerprint = "8iFUJEIEyQc="

    name                 = "terraform"

    project              = "seismic-catbird-358207"

    self_link            = "https://www.googleapis.com/compute/v1/projects/seismic-catbird-358207/zones/us-west1-c/instances/terraform"

    tags_fingerprint     = "42WmSpB8rSM="

    zone                 = "us-west1-c"


    boot_disk {

        auto_delete = true

        device_name = "persistent-disk-0"

        mode        = "READ_WRITE"

        source      = "https://www.googleapis.com/compute/v1/projects/seismic-catbird-358207/zones/us-west1-c/disks/terraform"


        initialize_params {

            image  = "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-11-bullseye-v20220920"

            labels = {}

            size   = 10

            type   = "pd-standard"

        }

    }


    network_interface {

        name               = "nic0"

        network            = "https://www.googleapis.com/compute/v1/projects/seismic-catbird-358207/global/networks/default"

        network_ip         = "10.138.0.2"

        queue_count        = 0

        stack_type         = "IPV4_ONLY"

        subnetwork         = "https://www.googleapis.com/compute/v1/projects/seismic-catbird-358207/regions/us-west1/subnetworks/default"

        subnetwork_project = "seismic-catbird-358207"


        access_config {

            nat_ip       = "35.233.234.118"

            network_tier = "PREMIUM"

        }

    }


    scheduling {

        automatic_restart   = true

        min_node_cpus       = 0

        on_host_maintenance = "MIGRATE"

        preemptible         = false

        provisioning_model  = "STANDARD"

    }


    shielded_instance_config {

        enable_integrity_monitoring = true

        enable_secure_boot          = false

        enable_vtpm                 = true

    }

}





<3> Console에서 확인



Compute > VM  인스턴스







<4> 서버이름 변경해보기



1

vi instance.tf



2

서버 이름 변경해 보자~


resource "google_compute_instance" "terraform" {

  project      = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  name         = "gcp-tts-kr-web01-dev"

  machine_type = "n1-standard-1"

  zone         = "us-west1-c"

  boot_disk {

    initialize_params {

      image = "debian-cloud/debian-11"

    }

  }

  network_interface {

    network = "default"

    access_config {

    }

  }

}



2

terraform apply

yes


3

콘솔에서 확인


기존 서버 이름이 변경됨



다음


https://brunch.co.kr/@topasvga/2740



https://brunch.co.kr/@topasvga/2419



감사합니다.




매거진의 이전글 193. 테라폼-GCP-VPC네트워크,VM인스턴스

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari