Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cd
- git clone https://github.com/wardviaene/terraform-course.git
- cd terraform/demo-2b
- ssh-keygen -f mykey
- git clone https://github.com/wardviaene/devops-box.git
- cd devops-box/scripts
- sed 's/mkdir/#mkdir/g' -i install.sh
- sed 's/ssh-/#ssh-/g' -i install.sh
- sed 's/chown/#chown/g' -i install.sh
- chmod +x install.sh
- sudo ./install.sh
- cd
- mkdir gopath
- export GOROOT=/usr/local/go
- export GOPATH=$HOME/gopath
- export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
- sudo -s
- export GOROOT=/usr/local/go
- export GOPATH=$HOME/gopath
- export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
- go get github.com/tools/godep
- curl -O https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
- tar -zxvf go1.7.1.linux-amd64.tar.gz -C /usr/local/
- exit
- git clone https://github.com/masterzen/winrm-cli
- cd winrm-cli
- make
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ ls -l
- total 36
- -rw------- 1 ubuntu ubuntu 1679 Dec 2 20:31 mykey
- -rw-r--r-- 1 ubuntu ubuntu 404 Dec 2 20:31 mykey.pub
- -rw-rw-r-- 1 ubuntu ubuntu 135 Dec 2 20:26 provider.tf
- -rw-rw-r-- 1 ubuntu ubuntu 3798 Dec 2 21:00 terraform.tfstate
- -rw-rw-r-- 1 ubuntu ubuntu 316 Dec 2 20:55 terraform.tfstate.backup
- -rw-rw-r-- 1 ubuntu ubuntu 125 Dec 2 20:35 terraform.tfvars
- -rw-rw-r-- 1 ubuntu ubuntu 43 Dec 2 20:24 test.txt
- -rw-rw-r-- 1 ubuntu ubuntu 462 Dec 2 20:29 vars.tf
- -rw-rw-r-- 1 ubuntu ubuntu 1246 Dec 2 20:40 windows-instance.tf
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ cat windows-instance.tf
- resource "aws_key_pair" "mykey" {
- key_name = "mykey"
- public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
- }
- resource "aws_instance" "win-example" {
- ami = "${lookup(var.WIN_AMIS, var.AWS_REGION)}"
- instance_type = "t2.micro"
- subnet_id = "subnet-7722xxxx"
- vpc_security_group_ids = ["sg-e838xxxx"]
- key_name = "${aws_key_pair.mykey.key_name}"
- user_data = <<EOF
- <powershell>
- net user ${var.INSTANCE_USERNAME} ${var.INSTANCE_PASSWORD} /add
- net localgroup administrators ${var.INSTANCE_USERNAME} /add
- winrm quickconfig -q
- winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
- winrm set winrm/config '@{MaxTimeoutms="1800000"}'
- winrm set winrm/config/service '@{AllowUnencrypted="true"}'
- winrm set winrm/config/service/auth '@{Basic="true"}'
- netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
- netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
- net stop winrm
- sc.exe config winrm start=auto
- net start winrm
- </powershell>
- EOF
- provisioner "file" {
- source = "test.txt"
- destination = "C:/test.txt"
- }
- connection {
- type = "winrm"
- user = "${var.INSTANCE_USERNAME}"
- password = "${var.INSTANCE_PASSWORD}"
- }
- }
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ cat vars.tf
- variable "AWS_ACCESS_KEY" {}
- variable "AWS_SECRET_KEY" {}
- variable "AWS_REGION" {
- default = "us-east-1"
- }
- variable "WIN_AMIS" {
- type = "map"
- default = {
- us-east-1 = "ami-fc97a7eb"
- us-west-2 = "ami-9f5efbff"
- eu-west-1 = "ami-7ac78809"
- }
- }
- variable "PATH_TO_PRIVATE_KEY" {
- default = "mykey"
- }
- variable "PATH_TO_PUBLIC_KEY" {
- default = "mykey.pub"
- }
- variable "INSTANCE_USERNAME" {
- default = "Terraform"
- }
- variable "INSTANCE_PASSWORD" { }
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ export TF_LOG=TRACE
- ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ terraform apply
- ...
- aws_instance.win-example: Still creating... (5m30s elapsed)
- 2016/12/02 21:00:49 [DEBUG] vertex provider.aws (close), waiting for: aws_instance.win-example
- 2016/12/02 21:00:50 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:50 connecting to remote shell using WinRM
- 2016/12/02 21:00:50 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:50 connection error: http error: 401 -
- 2016/12/02 21:00:50 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:50 Retryable error: http error: 401 -
- 2016/12/02 21:00:53 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:53 connecting to remote shell using WinRM
- 2016/12/02 21:00:53 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:53 connection error: http error: 401 -
- 2016/12/02 21:00:53 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:53 Retryable error: http error: 401 -
- 2016/12/02 21:00:53 [DEBUG] vertex provisioner.file (close), waiting for: aws_instance.win-example
- 2016/12/02 21:00:53 [DEBUG] vertex root, waiting for: provisioner.file (close)
- 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalIf
- 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalWriteState
- 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalWriteDiff
- 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalApplyPost
- 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:
- * http error: 401 -
- 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
- * http error: 401 -
- 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalOpFilter, err: 1 error(s) occurred:
- * http error: 401 -
- 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
- * http error: 401 -
- 2016/12/02 21:00:54 [TRACE] [walkApply] Exiting eval tree: aws_instance.win-example
- 2016/12/02 21:00:54 [DEBUG] vertex provider.aws (close), got dep: aws_instance.win-example
- 2016/12/02 21:00:54 [DEBUG] vertex provisioner.file (close), got dep: aws_instance.win-example
- 2016/12/02 21:00:54 [DEBUG] vertex root, got dep: provisioner.file (close)
- 2016/12/02 21:00:54 [DEBUG] vertex root, got dep: provider.aws (close)
- 2016/12/02 21:00:54 [TRACE] Preserving existing state lineage "66fac295-aa48-4e59-a82f-bd22f3343407"
- 2016/12/02 21:00:54 [DEBUG] plugin: waiting for all plugin processes to complete...
- Error applying plan:
- 2016/12/02 21:00:54 [DEBUG] plugin: /usr/local/bin/terraform: plugin process exited
- 2016/12/02 21:00:54 [DEBUG] plugin: /usr/local/bin/terraform: plugin process exited
- 1 error(s) occurred:
- * http error: 401 -
- Terraform does not automatically rollback in the face of errors.
- Instead, your Terraform state file has been partially updated with
- any resources that successfully completed. Please address the error
- above and apply again to incrementally change your infrastructure
- while true; do date; ./winrm -hostname 10.x.x.x -username "Terraform" -password "secret" "ipconfig/all|findstr v4"; sleep 10; done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement