Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Terraform setup #276

Merged
merged 9 commits into from
Sep 7, 2020
Merged

Fix Terraform setup #276

merged 9 commits into from
Sep 7, 2020

Conversation

gianarb
Copy link
Contributor

@gianarb gianarb commented Sep 2, 2020

This is part of the work I am doing with the Terraform Setup guide:

tinkerbell/tinkerbell.org#129

This is part of the work I am doing with the Terraform Setup guide:

tinkerbell/tinkerbell.org#129
Signed-off-by: Gianluca Arbezzano <[email protected]>
@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

Merging #276 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #276   +/-   ##
=======================================
  Coverage   20.61%   20.61%           
=======================================
  Files          15       15           
  Lines        1363     1363           
=======================================
  Hits          281      281           
  Misses       1068     1068           
  Partials       14       14           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c57d19b...da4ea2d. Read the comment docs.

Copy link
Member

@displague displague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for getting this working simpler, @gianarb

I have a few more changes that will benefit this setup and I'd rather see us get them in one shot. If we change resource names in a later commit people that started with this terraform example will have to transfer state to the renamed resources, for example.

I have my changes staged here: https://github.com/gianarb/tink/compare/fix/update-terraform-setup...displague:terraform-cleanup?expand=1

I'll push these changes into this branch once I have verified them.

@gianarb
Copy link
Contributor Author

gianarb commented Sep 2, 2020

Great thanks @displague !

type = "ssh"
user = var.ssh_user
host = packet_device.tink-provisioner.network[0].address
private_key = file(var.ssh_private_key)
Copy link
Member

@displague displague Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gianarb I removed the private_key because Terraform will use your ssh-agent by default.

The problem with defaulting to "~/.ssh/id_rsa" is that this file is usually encrypted, and Terraform can not use that.

My suggestion is that we ask the user to add the key they want to use to their SSH agent before running terraform apply. For most users, this should already be the case - nothing to do.

An alternative is to ask users to ssh-keygen create a new key in this directory, and tell Terraform to use that.

If we can make private_key optional (use the agent if ssh_private_key is empty) that would be even better. I can look into this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the ssh-agent note as part of the documentation. We can do the fallback work as follow up work 👍

hostname = "tink-provisioner"
plan = var.device_type
facilities = [var.facility]
operating_system = "ubuntu_18_04"
billing_cycle = "hourly"
project_id = var.project_id
user_data = file("install_package.sh")
}

resource "null_resource" "tink_directory" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gianarb by moving the provisioning to a null_resource, provisioning failures (like a missing ssh key) will not require the tink_provisioner host to be recreated. Changes to the tink/ directory can be reapplied (rsync'd) independently. terraform taint null_resource.tink_directory; terraform apply

type = "layer2-individual"
}

# Attach VLAN to provisioner
resource "packet_port_vlan_attachment" "provisioner" {
device_id = packet_device.tink-provisioner.id
device_id = packet_device.tink_provisioner.id
Copy link
Member

@displague displague Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into Error: POST https://api.packet.net/ports/bff62cf9-5f23-49fd-b500-686e3d8730b6/assign: 422 still bonded once while testing this. A follow-up terraform apply was successful.

It may make sense to add depends_on = packet_device_network_type.tink_provisioner_network_type here 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like a reasonable dependency to me, so let's be clear about that and write it down 👍

@@ -8,6 +8,11 @@ variable "project_id" {
type = string
}

variable "worker_count" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't checked tinkerbell/tinkerbell.org#129 to see if multiple workers will require any additional doc changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, they will just work! Nice!

@rugwirobaker
Copy link

I'm quite new to terraform, and for it to work for me I have had to terraform 0.13upgrade . And I'm currently testing with this PR.
I'm using the latest terraform version.

➜  ~ terraform version
Your version of Terraform is out of date! The latest version
is 0.13.2. You can update by downloading from https://www.terraform.io/downloads.html
Terraform v0.13.0

Also something that would make the process faster for the newbies is to include the file my_var.tfvars file mentioned in the docs(I did have to learn terraform so, I guess that's a positive 😆). I'm thinking of something like this:

deploy/
├── example.tfvars 
├── install_package.sh
├── my_var.tfvars // user created copy should be added to .gitignore 
├── main.tf
├── outputs.tf
└── variables.tf

Example: https://github.com/alexellis/sshdkit where the ssh.yml was ignored but we have an example for it in ssh.example.yml
Small thing but it would make the project a little bit more accessible for people like me.

@rugwirobaker
Copy link

A small hicup running ./setup.sh
Got this error on my first run of terraform apply so I redid it and it went away

Error: POST https://api.packet.net/ports/d6ddf121-3f74-4b43-9a6c-a25edfc40fa5/assign: 422 still bonded 

  on main.tf line 76, in resource "packet_port_vlan_attachment" "provisioner":
  76: resource "packet_port_vlan_attachment" "provisioner" {

Error: POST https://api.packet.net/ports/e16fe28f-e194-409f-9d06-c7c72d07f7b4/assign: 422 still bonded 

  on main.tf line 83, in resource "packet_port_vlan_attachment" "worker":
  83: resource "packet_port_vlan_attachment" "worker" {

But ounce insider the provisioner the setup.sh script failed:

INFO: verifying prerequisites for ubuntu (18.04)                                                                                   [51/719]
       Found prerequisite: docker                                                                                                          
       Found prerequisite: docker-compose                                                                                                  
       Found prerequisite: ip                                                                                                              
       Found prerequisite: jq                                                                                                              
       Found prerequisite: netplan                                                                                                         
INFO: waiting for the network configuration to be applied by systemd-networkd                                                              
.........

Step 7/7 : EXPOSE 443
 ---> Running in b68d63577cca
Removing intermediate container b68d63577cca
 ---> 9d1bdfff2b16
Successfully built 9d1bdfff2b16
Successfully tagged deploy_registry:latest
Recreating deploy_registry_1 ... 
Recreating deploy_registry_1 ... done
Error response from daemon: Get https://192.168.1.1/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded w
hile awaiting headers)  

I went on but docker-compose up -d could not bring up the nginx container with the following error:

ERROR: for deploy_nginx_1  Cannot start service nginx: driver failed programming external connectivity on endpoint deploy_nginx_1 (7ccfa729
954ae70036255926ac45970b2ddfc6797f7d3b2bf6924ea10b3c4f22): Error starting userland proxy: listen tcp 192.168.1.2:80: bind: cannot assign

@gianarb gianarb removed the request for review from DailyAlice September 7, 2020 06:53
@gianarb gianarb added the ready-to-merge Signal to Mergify to merge the PR. label Sep 7, 2020
@mergify mergify bot merged commit 1aef424 into tinkerbell:master Sep 7, 2020
@mmlb mmlb removed the ready-to-merge Signal to Mergify to merge the PR. label Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants