Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. cd
  2. git clone https://github.com/wardviaene/terraform-course.git
  3. cd terraform/demo-2b
  4. ssh-keygen -f mykey
  5. git clone https://github.com/wardviaene/devops-box.git
  6. cd devops-box/scripts
  7. sed 's/mkdir/#mkdir/g' -i install.sh
  8. sed 's/ssh-/#ssh-/g' -i install.sh
  9. sed 's/chown/#chown/g' -i install.sh
  10. chmod +x install.sh
  11. ​sudo ./install.sh
  12. cd
  13. mkdir gopath
  14. export GOROOT=/usr/local/go
  15. export GOPATH=$HOME/gopath
  16. export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
  17. sudo -s
  18. export GOROOT=/usr/local/go
  19. export GOPATH=$HOME/gopath
  20. export PATH=$GOPATH/bin:$GOROOT/bin:$PATH
  21. go get github.com/tools/godep
  22. curl -O https://storage.googleapis.com/golang/go1.7.4.linux-amd64.tar.gz
  23. tar -zxvf go1.7.1.linux-amd64.tar.gz -C /usr/local/
  24. exit
  25. git clone https://github.com/masterzen/winrm-cli
  26. cd winrm-cli
  27. make
  28.  
  29. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
  30. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ ls -l
  31. total 36
  32. -rw------- 1 ubuntu ubuntu 1679 Dec 2 20:31 mykey
  33. -rw-r--r-- 1 ubuntu ubuntu 404 Dec 2 20:31 mykey.pub
  34. -rw-rw-r-- 1 ubuntu ubuntu 135 Dec 2 20:26 provider.tf
  35. -rw-rw-r-- 1 ubuntu ubuntu 3798 Dec 2 21:00 terraform.tfstate
  36. -rw-rw-r-- 1 ubuntu ubuntu 316 Dec 2 20:55 terraform.tfstate.backup
  37. -rw-rw-r-- 1 ubuntu ubuntu 125 Dec 2 20:35 terraform.tfvars
  38. -rw-rw-r-- 1 ubuntu ubuntu 43 Dec 2 20:24 test.txt
  39. -rw-rw-r-- 1 ubuntu ubuntu 462 Dec 2 20:29 vars.tf
  40. -rw-rw-r-- 1 ubuntu ubuntu 1246 Dec 2 20:40 windows-instance.tf
  41. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
  42. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
  43. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ cat windows-instance.tf
  44. resource "aws_key_pair" "mykey" {
  45. key_name = "mykey"
  46. public_key = "${file("${var.PATH_TO_PUBLIC_KEY}")}"
  47. }
  48.  
  49. resource "aws_instance" "win-example" {
  50. ami = "${lookup(var.WIN_AMIS, var.AWS_REGION)}"
  51. instance_type = "t2.micro"
  52. subnet_id = "subnet-7722xxxx"
  53. vpc_security_group_ids = ["sg-e838xxxx"]
  54. key_name = "${aws_key_pair.mykey.key_name}"
  55. user_data = <<EOF
  56. <powershell>
  57. net user ${var.INSTANCE_USERNAME} ${var.INSTANCE_PASSWORD} /add
  58. net localgroup administrators ${var.INSTANCE_USERNAME} /add
  59.  
  60. winrm quickconfig -q
  61. winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="300"}'
  62. winrm set winrm/config '@{MaxTimeoutms="1800000"}'
  63. winrm set winrm/config/service '@{AllowUnencrypted="true"}'
  64. winrm set winrm/config/service/auth '@{Basic="true"}'
  65.  
  66. netsh advfirewall firewall add rule name="WinRM 5985" protocol=TCP dir=in localport=5985 action=allow
  67. netsh advfirewall firewall add rule name="WinRM 5986" protocol=TCP dir=in localport=5986 action=allow
  68.  
  69. net stop winrm
  70. sc.exe config winrm start=auto
  71. net start winrm
  72. </powershell>
  73. EOF
  74.  
  75. provisioner "file" {
  76. source = "test.txt"
  77. destination = "C:/test.txt"
  78. }
  79. connection {
  80. type = "winrm"
  81. user = "${var.INSTANCE_USERNAME}"
  82. password = "${var.INSTANCE_PASSWORD}"
  83. }
  84. }
  85. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
  86. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
  87. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ cat vars.tf
  88. variable "AWS_ACCESS_KEY" {}
  89. variable "AWS_SECRET_KEY" {}
  90. variable "AWS_REGION" {
  91. default = "us-east-1"
  92. }
  93. variable "WIN_AMIS" {
  94. type = "map"
  95. default = {
  96. us-east-1 = "ami-fc97a7eb"
  97. us-west-2 = "ami-9f5efbff"
  98. eu-west-1 = "ami-7ac78809"
  99. }
  100. }
  101.  
  102. variable "PATH_TO_PRIVATE_KEY" {
  103. default = "mykey"
  104. }
  105. variable "PATH_TO_PUBLIC_KEY" {
  106. default = "mykey.pub"
  107. }
  108. variable "INSTANCE_USERNAME" {
  109. default = "Terraform"
  110. }
  111. variable "INSTANCE_PASSWORD" { }
  112. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
  113. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$
  114. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ export TF_LOG=TRACE
  115. ubuntu@ip-10-70-99-142:~/terraform-course/demo-2b$ terraform apply
  116. ...
  117. aws_instance.win-example: Still creating... (5m30s elapsed)
  118. 2016/12/02 21:00:49 [DEBUG] vertex provider.aws (close), waiting for: aws_instance.win-example
  119. 2016/12/02 21:00:50 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:50 connecting to remote shell using WinRM
  120. 2016/12/02 21:00:50 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:50 connection error: http error: 401 -
  121. 2016/12/02 21:00:50 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:50 Retryable error: http error: 401 -
  122. 2016/12/02 21:00:53 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:53 connecting to remote shell using WinRM
  123. 2016/12/02 21:00:53 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:53 connection error: http error: 401 -
  124. 2016/12/02 21:00:53 [DEBUG] plugin: terraform: file-provisioner (internal) 2016/12/02 21:00:53 Retryable error: http error: 401 -
  125. 2016/12/02 21:00:53 [DEBUG] vertex provisioner.file (close), waiting for: aws_instance.win-example
  126. 2016/12/02 21:00:53 [DEBUG] vertex root, waiting for: provisioner.file (close)
  127. 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalIf
  128. 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalWriteState
  129. 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalWriteDiff
  130. 2016/12/02 21:00:54 [DEBUG] root: eval: *terraform.EvalApplyPost
  131. 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalApplyPost, err: 1 error(s) occurred:
  132.  
  133. * http error: 401 -
  134. 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
  135.  
  136. * http error: 401 -
  137. 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalOpFilter, err: 1 error(s) occurred:
  138.  
  139. * http error: 401 -
  140. 2016/12/02 21:00:54 [ERROR] root: eval: *terraform.EvalSequence, err: 1 error(s) occurred:
  141.  
  142. * http error: 401 -
  143. 2016/12/02 21:00:54 [TRACE] [walkApply] Exiting eval tree: aws_instance.win-example
  144. 2016/12/02 21:00:54 [DEBUG] vertex provider.aws (close), got dep: aws_instance.win-example
  145. 2016/12/02 21:00:54 [DEBUG] vertex provisioner.file (close), got dep: aws_instance.win-example
  146. 2016/12/02 21:00:54 [DEBUG] vertex root, got dep: provisioner.file (close)
  147. 2016/12/02 21:00:54 [DEBUG] vertex root, got dep: provider.aws (close)
  148. 2016/12/02 21:00:54 [TRACE] Preserving existing state lineage "66fac295-aa48-4e59-a82f-bd22f3343407"
  149. 2016/12/02 21:00:54 [DEBUG] plugin: waiting for all plugin processes to complete...
  150. Error applying plan:
  151. 2016/12/02 21:00:54 [DEBUG] plugin: /usr/local/bin/terraform: plugin process exited
  152. 2016/12/02 21:00:54 [DEBUG] plugin: /usr/local/bin/terraform: plugin process exited
  153.  
  154. 1 error(s) occurred:
  155.  
  156. * http error: 401 -
  157.  
  158. Terraform does not automatically rollback in the face of errors.
  159. Instead, your Terraform state file has been partially updated with
  160. any resources that successfully completed. Please address the error
  161. above and apply again to incrementally change your infrastructure
  162.  
  163. 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