{"id":2353,"date":"2022-01-21T15:48:49","date_gmt":"2022-01-21T15:48:49","guid":{"rendered":"https:\/\/ionoslabs.com\/?p=2353"},"modified":"2022-01-28T18:26:29","modified_gmt":"2022-01-28T18:26:29","slug":"simple-terraform-linux-build","status":"publish","type":"post","link":"https:\/\/ionoslabs.com\/index.php\/simple-terraform-linux-build\/","title":{"rendered":"Simple Terraform Ubuntu Linux Build"},"content":{"rendered":"<div class=\"fusion-fullwidth fullwidth-box fusion-builder-row-1 fusion-flex-container nonhundred-percent-fullwidth non-hundred-percent-height-scrolling\" style=\"--awb-border-radius-top-left:0px;--awb-border-radius-top-right:0px;--awb-border-radius-bottom-right:0px;--awb-border-radius-bottom-left:0px;--awb-flex-wrap:wrap;\" ><div class=\"fusion-builder-row fusion-row fusion-flex-align-items-flex-start fusion-flex-content-wrap\" style=\"max-width:1289.6px;margin-left: calc(-4% \/ 2 );margin-right: calc(-4% \/ 2 );\"><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-0 fusion_builder_column_2_3 2_3 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-border-color:#000000;--awb-border-style:dashed;--awb-width-large:66.666666666667%;--awb-margin-top-large:0px;--awb-spacing-right-large:2.88%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:2.88%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-image-element \" style=\"--awb-caption-title-font-family:var(--h2_typography-font-family);--awb-caption-title-font-weight:var(--h2_typography-font-weight);--awb-caption-title-font-style:var(--h2_typography-font-style);--awb-caption-title-size:var(--h2_typography-font-size);--awb-caption-title-transform:var(--h2_typography-text-transform);--awb-caption-title-line-height:var(--h2_typography-line-height);--awb-caption-title-letter-spacing:var(--h2_typography-letter-spacing);\"><span class=\" fusion-imageframe imageframe-none imageframe-1 hover-type-none\"><img decoding=\"async\" width=\"185\" height=\"79\" title=\"terraform-ubuntu-logo\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%27http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%27%20width%3D%27185%27%20height%3D%2779%27%20viewBox%3D%270%200%20185%2079%27%3E%3Crect%20width%3D%27185%27%20height%3D%2779%27%20fill-opacity%3D%220%22%2F%3E%3C%2Fsvg%3E\" data-orig-src=\"https:\/\/ionoslabs.com\/wp-content\/uploads\/2022\/01\/terraform-ubuntu-logo.png\" alt class=\"lazyload img-responsive wp-image-2451\"\/><\/span><\/div><div class=\"fusion-content-boxes content-boxes columns row fusion-columns-1 fusion-columns-total-1 fusion-content-boxes-1 content-boxes-icon-with-title content-left\" style=\"--awb-hover-accent-color:#ff8d61;--awb-circle-hover-accent-color:#ff8d61;--awb-item-margin-bottom:40px;\" data-animationOffset=\"top-into-view\"><div style=\"--awb-backgroundcolor:rgba(255,255,255,0);\" class=\"fusion-column content-box-column content-box-column content-box-column-1 col-lg-12 col-md-12 col-sm-12 fusion-content-box-hover content-box-column-last content-box-column-last-in-row\"><div class=\"col content-box-wrapper content-wrapper link-area-box icon-hover-animation-fade\" data-animationOffset=\"top-into-view\"><div class=\"heading icon-left\"><h2 class=\"content-box-heading fusion-responsive-typography-calculated\" style=\"--h2_typography-font-size:23px;--fontSize:23;line-height:1.29;\">Provision a VDC and server instance using Terraform<\/h2><\/div><div class=\"fusion-clearfix\"><\/div><div class=\"content-container\">\n<p>The below Terraform files will create a new IONOS VDC and server instance, it will also copy a locally specified SSH key for the root key and finally copy a hello.txt file to \/tmp\/hello.txt.\u00a0 Once deployed you will be able to login to the instance with your SSH key.<\/p>\n<p>Prerequisites:<\/p>\n<ol>\n<li>You will need terraform installed <a href=\"https:\/\/learn.hashicorp.com\/tutorials\/terraform\/install-cli\">Hashicorp how to install Terraform<\/a><\/li>\n<li>You will need to set your IONOS username and password locally as environment variables (see export in deploy to the right)<\/li>\n<li>You will need to create a directory and have an SSH key that you would like to use<\/li>\n<li>You will need to create 3 files locally\n<ol>\n<li>terraform-simple-server.tf will contain the main script (below)<\/li>\n<li>variables.tf will contain the username and password settings to use in this deployment (below)<\/li>\n<li>hello.txt to copy up to the provisioned instance<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<\/div><\/div><\/div><div class=\"fusion-clearfix\"><\/div><\/div><div class=\"fusion-text fusion-text-1\" style=\"--awb-text-transform:none;\"><p><strong>terraform-simple-server.tf<\/strong><\/p>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-1 > .CodeMirror, .fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-1 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-1 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:10px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#eaeaea;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_1\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_1\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_1\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/yaml\"># Terraform IONOS simple server setup\n\nterraform {\n  required_providers {\n    ionoscloud = {\n      source  = \"ionos-cloud\/ionoscloud\"\n    }\n  }\n}\n\nprovider \"ionoscloud\" {\n  username = var.ionos_username\n  password = var.ionos_password\n}\n\nresource \"ionoscloud_datacenter\" \"terra-bash-script\" {\n  location    = \"us\/ewr\"\n  name        = \"terraform-wp1\"\n  description = \"terraform sandbox bash script\"\n}\n\nresource \"ionoscloud_lan\" \"terraform-lan-1\" {\n  datacenter_id = ionoscloud_datacenter.terra-bash-script.id\n  name          = \"terraform-lan-1\"\n  public        = true\n}\n\nresource \"ionoscloud_server\" \"terraform-wp1\" {\n  name              = \"terraform-wp1\"\n  datacenter_id     = ionoscloud_datacenter.terra-bash-script.id\n  cores             = 2\n  ram               = 4 * 1024\n  cpu_family        = \"AMD_OPTERON\"\n  availability_zone = \"AUTO\"\n  image_name        = \"ubuntu\"\n  # path below is the path to the public key already created you want to copy to the server instance, enter your local path\n  ssh_key_path = [\n    \"\/home\/user\/.ssh\/id_ed25519.pub\",\n  ]\n\n  connection {\n    type        = \"ssh\"\n    user        = \"root\"\n    private_key = file(\"~\/.ssh\/id_ed25519\")\n    host        = self.primary_ip\n  }\n\n  nic {\n    lan             = ionoscloud_lan.terraform-lan-1.id\n    dhcp            = true\n    firewall_active = false\n    name            = \"wan\"\n  }\n\n  volume {\n    name      = \"terraform-wp1-vol1\"\n    size      = 50\n    disk_type = \"HDD\"\n  }\n\n  provisioner \"file\" {\n    source      = \"hello.txt\"\n    destination = \"\/tmp\/hello.txt\"\n  }\n  \n  timeouts {\n    create = \"30m\"\n    update = \"30m\"\n    delete = \"30m\"\n  }\n}\n<\/textarea><\/div><div class=\"fusion-section-separator section-separator slant fusion-section-separator-1\" style=\"--awb-spacer-height:99px;--awb-svg-margin-left:2.88%;--awb-svg-margin-right:2.88%;--awb-svg-margin-left-medium:1.92%;--awb-svg-margin-right-medium:1.92%;--awb-svg-margin-left-small:1.92%;--awb-svg-margin-right-small:1.92%;--awb-divider-height:99px;--awb-spacer-padding-top:inherit;--awb-sep-padding:0;--awb-svg-padding:0;\"><div class=\"fusion-section-separator-svg\"><svg class=\"fusion-slant-candy\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" version=\"1.1\" width=\"100%\" height=\"100\" viewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" fill=\"rgba(11,42,99,1)\"><path d=\"M100 0 L100 100 L0 0 Z\"><\/path><\/svg><\/div><div class=\"fusion-section-separator-spacer\"><div class=\"fusion-section-separator-spacer-height\"><\/div><\/div><\/div><div class=\"fusion-text fusion-text-2\" style=\"--awb-text-transform:none;\"><p>variables.tf<\/p>\n<\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-2 > .CodeMirror, .fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-2 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-2 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#eaeaea;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_2\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_2\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_2\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-sh\">variable \"ionos_username\" {\n  description = \"Ionos Provider Username\"\n  type = string\n  sensitive = true\n}\n\nvariable \"ionos_password\" {\n  description = \"Ionos Provider Password\"\n  type = string\n  sensitive = true\n}<\/textarea><\/div><\/div><\/div><div class=\"fusion-layout-column fusion_builder_column fusion-builder-column-1 fusion_builder_column_1_3 1_3 fusion-flex-column\" style=\"--awb-bg-size:cover;--awb-width-large:33.333333333333%;--awb-margin-top-large:0px;--awb-spacing-right-large:5.76%;--awb-margin-bottom-large:20px;--awb-spacing-left-large:5.76%;--awb-width-medium:100%;--awb-order-medium:0;--awb-spacing-right-medium:1.92%;--awb-spacing-left-medium:1.92%;--awb-width-small:100%;--awb-order-small:0;--awb-spacing-right-small:1.92%;--awb-spacing-left-small:1.92%;\"><div class=\"fusion-column-wrapper fusion-column-has-shadow fusion-flex-justify-content-flex-start fusion-content-layout-column\"><div class=\"fusion-title title fusion-title-1 fusion-title-text fusion-title-size-one\"><div class=\"title-sep-container title-sep-container-left fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><span class=\"awb-title-spacer fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><\/span><h1 class=\"fusion-title-heading title-heading-left fusion-responsive-typography-calculated\" style=\"margin:0;--fontSize:24;line-height:1.2;\">Download<\/h1><span class=\"awb-title-spacer\"><\/span><div class=\"title-sep-container title-sep-container-right\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-3 > .CodeMirror, .fusion-syntax-highlighter-3 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-3 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-3 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-3 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#eaeaea;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_3\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_3\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_3\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-sh\">git clone https:\/\/github.com\/ionoslabs\/terraform-simple-server<\/textarea><\/div><div class=\"fusion-title title fusion-title-2 fusion-title-text fusion-title-size-one\"><div class=\"title-sep-container title-sep-container-left fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><span class=\"awb-title-spacer fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><\/span><h1 class=\"fusion-title-heading title-heading-left fusion-responsive-typography-calculated\" style=\"margin:0;--fontSize:24;line-height:1.2;\">Deploy<\/h1><span class=\"awb-title-spacer\"><\/span><div class=\"title-sep-container title-sep-container-right\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-4 > .CodeMirror, .fusion-syntax-highlighter-4 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-4 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-4 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-4 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#eaeaea;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_4\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_4\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_4\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-sh\">\/\/ set username and password below as your IONOS username and password\nexport TF_VAR_ionos_username=user@email.com\nexport TF_VAR_ionos_password=password  \n\nterraform init\nterraform plan\nterraform apply<\/textarea><\/div><div class=\"fusion-title title fusion-title-3 fusion-title-text fusion-title-size-one\"><div class=\"title-sep-container title-sep-container-left fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><span class=\"awb-title-spacer fusion-no-large-visibility fusion-no-medium-visibility fusion-no-small-visibility\"><\/span><h1 class=\"fusion-title-heading title-heading-left fusion-responsive-typography-calculated\" style=\"margin:0;--fontSize:24;line-height:1.2;\">Cleanup<\/h1><span class=\"awb-title-spacer\"><\/span><div class=\"title-sep-container title-sep-container-right\"><div class=\"title-sep sep- sep-solid\" style=\"border-color:#eaeaea;\"><\/div><\/div><\/div><style type=\"text\/css\" scopped=\"scopped\">.fusion-syntax-highlighter-5 > .CodeMirror, .fusion-syntax-highlighter-5 > .CodeMirror .CodeMirror-gutters {background-color:var(--awb-color1);}.fusion-syntax-highlighter-5 > .CodeMirror .CodeMirror-gutters { background-color: var(--awb-color2); }.fusion-syntax-highlighter-5 > .CodeMirror .CodeMirror-linenumber { color: var(--awb-color8); }<\/style><div class=\"fusion-syntax-highlighter-container fusion-syntax-highlighter-5 fusion-syntax-highlighter-theme-light\" style=\"opacity:0;margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0px;font-size:14px;border-width:1px;border-style:solid;border-color:#eaeaea;\"><div class=\"syntax-highlighter-copy-code\"><span class=\"syntax-highlighter-copy-code-title\" data-id=\"fusion_syntax_highlighter_5\" style=\"font-size:14px;\">Copy to Clipboard<\/span><\/div><label for=\"fusion_syntax_highlighter_5\" class=\"screen-reader-text\">Syntax Highlighter<\/label><textarea class=\"fusion-syntax-highlighter-textarea\" id=\"fusion_syntax_highlighter_5\" data-readOnly=\"nocursor\" data-lineNumbers=\"1\" data-lineWrapping=\"\" data-theme=\"default\" data-mode=\"text\/x-sh\">terraform destroy<\/textarea><\/div><\/div><\/div><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":2451,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[455,391],"tags":[],"class_list":["post-2353","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ci-cd","category-resources"],"_links":{"self":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts\/2353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/comments?post=2353"}],"version-history":[{"count":12,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts\/2353\/revisions"}],"predecessor-version":[{"id":2453,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/posts\/2353\/revisions\/2453"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/media\/2451"}],"wp:attachment":[{"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/media?parent=2353"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/categories?post=2353"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ionoslabs.com\/index.php\/wp-json\/wp\/v2\/tags?post=2353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}