{"id":8085,"date":"2019-12-21T06:41:09","date_gmt":"2019-12-21T06:41:09","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=8085"},"modified":"2023-04-03T07:26:09","modified_gmt":"2023-04-03T07:26:09","slug":"terraform-variable-string-type-explained-2","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/terraform-variable-string-type-explained-2\/","title":{"rendered":"Terraform Tutorials: Variables &#8211; Data Type &#8211; String"},"content":{"rendered":"\n<p>In this example, the <code>instance_name<\/code> variable is defined with a type of <code>string<\/code>, and it is given a default value of <code>\"my-instance\"<\/code>. The AWS provider is then configured to use the <code>us-west-2<\/code> region.<\/p>\n\n\n\n<p>The <code>aws_instance<\/code> resource is used to launch Amazon EC2 instances. The <code>tags<\/code> argument is used to assign a name tag to the instance, and it is set to the value of the <code>instance_name<\/code> variable.<\/p>\n\n\n\n<p>You can change the value of <code>instance_name<\/code> by modifying the default value in the variable definition, or you can specify a different value when you run Terraform by using the <code>-var<\/code> flag. For example, if you want to launch an instance with the name <code>\"my-other-instance\"<\/code>, you can run the following command:<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/fd155eaf6761dee93e30b2de9bae7331.js\"><\/script>\n\n\n\n<p>$ terraform apply -var &#8216;instance_name=&#8221;my-other-instance&#8221;&#8216;<\/p>\n\n\n\n<script src=\"https:\/\/gist.github.com\/devops-school\/c4c2febe85fe80ac7d16a522d23e7dd1.js\"><\/script>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_17057\"><iframe loading=\"lazy\"  id=\"_ytid_38501\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_17057\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>In this example, the instance_name variable is defined with a type of string, and it is given a default value of &#8220;my-instance&#8221;. The AWS provider is then configured to use&#8230; <\/p>\n","protected":false},"author":1,"featured_media":8194,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5129],"tags":[],"class_list":["post-8085","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-terraform"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=8085"}],"version-history":[{"count":6,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8085\/revisions"}],"predecessor-version":[{"id":33197,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/8085\/revisions\/33197"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/8194"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=8085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=8085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=8085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}