1 00:00:07,000 --> 00:00:08,840 - Okay, so now I wanna talk about 2 00:00:09,920 --> 00:00:11,900 making HCL a little bit more useful. 3 00:00:11,900 --> 00:00:12,823 Obviously, 4 00:00:14,950 --> 00:00:16,810 choosing random names for your resources 5 00:00:16,810 --> 00:00:18,960 like buckets and so forth 6 00:00:20,330 --> 00:00:22,660 isn't gonna be terribly useful in the real world. 7 00:00:22,660 --> 00:00:24,570 That's not generally what we want. 8 00:00:24,570 --> 00:00:25,403 So, 9 00:00:26,400 --> 00:00:29,980 and now, I'm using S3 buckets as an example 10 00:00:29,980 --> 00:00:31,170 for a couple of reasons. 11 00:00:31,170 --> 00:00:34,760 One, because they take no configuration 12 00:00:36,220 --> 00:00:39,430 to get started, there's no required attributes. 13 00:00:39,430 --> 00:00:41,780 And two, they're very simple and they're, 14 00:00:41,780 --> 00:00:43,803 they don't cost anything if, 15 00:00:44,920 --> 00:00:46,510 if you don't store any data in them, 16 00:00:46,510 --> 00:00:47,370 if you just create them. 17 00:00:47,370 --> 00:00:51,170 So they make a good example for configuring Terraform 18 00:00:51,170 --> 00:00:52,440 and doing demonstrations. 19 00:00:52,440 --> 00:00:54,900 But you should keep in mind that 20 00:00:54,900 --> 00:00:59,370 these techniques apply to any resource in Terraform, okay? 21 00:00:59,370 --> 00:01:03,440 So what I'm about to show you is called interpolation. 22 00:01:03,440 --> 00:01:04,630 This is simply 23 00:01:05,660 --> 00:01:09,310 evaluating string values and 24 00:01:09,310 --> 00:01:14,270 creating custom resource identifiers, 25 00:01:14,270 --> 00:01:16,800 and I'll show you the syntax for doing that. 26 00:01:16,800 --> 00:01:18,050 Okay. 27 00:01:18,050 --> 00:01:18,883 So, 28 00:01:21,160 --> 00:01:22,860 you remember our previous example 29 00:01:22,860 --> 00:01:24,760 where we didn't have any attributes, 30 00:01:24,760 --> 00:01:27,450 and then we put in bucket and we called it bucket one, 31 00:01:27,450 --> 00:01:29,380 and it wouldn't work because something was 32 00:01:29,380 --> 00:01:30,213 already named that. 33 00:01:30,213 --> 00:01:31,046 So, 34 00:01:32,210 --> 00:01:34,080 let's say we decide on a naming convention 35 00:01:34,080 --> 00:01:37,750 that we're gonna prefix our bucket names 36 00:01:37,750 --> 00:01:39,300 with the account ID that we saw 37 00:01:39,300 --> 00:01:41,023 in the caller identity before. 38 00:01:42,410 --> 00:01:44,700 This is how we would do that, okay? 39 00:01:44,700 --> 00:01:48,100 So, we're gonna call this one bucket two. 40 00:01:48,100 --> 00:01:50,950 And remember, this is just a label internal to Terraform. 41 00:01:53,230 --> 00:01:56,300 And then we're gonna create a quoted string, okay? 42 00:01:56,300 --> 00:01:58,330 And then within a quoted string, 43 00:01:58,330 --> 00:02:03,330 the syntax for this is dollar sign, curly brace, 44 00:02:03,860 --> 00:02:07,685 and then the attribute that you wanna place in that string 45 00:02:07,685 --> 00:02:10,040 and then the closing curly brace. 46 00:02:10,040 --> 00:02:13,650 Now, when Terraform runs, it's gonna interpolate that, 47 00:02:13,650 --> 00:02:17,050 and it's gonna substitute in the value 48 00:02:19,138 --> 00:02:20,690 into this part, okay? 49 00:02:20,690 --> 00:02:24,760 So this is gonna resolve to being the account ID string. 50 00:02:24,760 --> 00:02:28,790 And it's gonna create your bucket name 51 00:02:28,790 --> 00:02:29,910 that way. 52 00:02:29,910 --> 00:02:34,490 Prior to Terraform 12, interpolation was 53 00:02:34,490 --> 00:02:37,960 essentially the only way to reference between 54 00:02:37,960 --> 00:02:39,963 objects in Terraform. 55 00:02:41,520 --> 00:02:43,003 Since Terraform 12, 56 00:02:44,350 --> 00:02:46,780 this syntax, you see how this isn't quoted, 57 00:02:46,780 --> 00:02:49,190 it doesn't have the dollar sign, 58 00:02:49,190 --> 00:02:52,263 it doesn't have the curly braces, it's just a raw value. 59 00:02:53,100 --> 00:02:56,280 So this was introduced in Terraform 12. 60 00:02:56,280 --> 00:02:59,110 Prior to Terraform 12, to do this, 61 00:02:59,110 --> 00:02:59,960 you would have to 62 00:03:04,430 --> 00:03:05,970 quote it and 63 00:03:07,580 --> 00:03:09,550 put the brackets, even though there really is no 64 00:03:09,550 --> 00:03:13,320 interpolation here, it would just interpolate that value. 65 00:03:13,320 --> 00:03:14,153 Now, 66 00:03:16,830 --> 00:03:17,663 this 67 00:03:19,501 --> 00:03:22,340 is valid, and this is the recommended way 68 00:03:22,340 --> 00:03:24,483 to reference variables within HCL. 69 00:03:26,040 --> 00:03:27,773 But if you need to, 70 00:03:28,830 --> 00:03:31,061 if you need to concatenate it into a string, 71 00:03:31,061 --> 00:03:34,370 this is a good shortcut for doing that, 72 00:03:34,370 --> 00:03:36,480 because it doesn't require you to use 73 00:03:38,420 --> 00:03:39,473 a format, 74 00:03:40,800 --> 00:03:42,250 a function or anything like that. 75 00:03:42,250 --> 00:03:43,480 So it's a real simple way. 76 00:03:43,480 --> 00:03:46,170 It's a pretty self-explanatory code 77 00:03:47,730 --> 00:03:49,490 most of the time, so you can 78 00:03:56,570 --> 00:03:59,350 see what we get there, the plan should tell us 79 00:03:59,350 --> 00:04:02,230 what the name of the bucket is going to be 80 00:04:02,230 --> 00:04:03,433 before we apply it. 81 00:04:05,490 --> 00:04:06,570 So you can see 82 00:04:07,810 --> 00:04:10,640 that it's already done the interpolation within the plan, 83 00:04:10,640 --> 00:04:12,233 so that's already resolved. 84 00:04:13,120 --> 00:04:14,060 Okay. 85 00:04:14,060 --> 00:04:19,060 So we have our account ID, and then a suffix of bucket two, 86 00:04:20,020 --> 00:04:20,853 which 87 00:04:22,210 --> 00:04:23,913 you saw in the code. 88 00:04:28,490 --> 00:04:29,790 So we'll just create that.