1 00:00:06,680 --> 00:00:09,090 - Okay, so in the last example with S3, 2 00:00:09,090 --> 00:00:11,680 we saw that we couldn't create a bucket 3 00:00:11,680 --> 00:00:14,360 with a generic name like bucket one. 4 00:00:14,360 --> 00:00:15,960 So, 5 00:00:15,960 --> 00:00:17,570 one way to work around this is to just 6 00:00:17,570 --> 00:00:19,480 not give it a name at all, in which case, 7 00:00:19,480 --> 00:00:21,970 Terraform will automatically assign it 8 00:00:24,341 --> 00:00:26,970 a random string that's guaranteed to be unique. 9 00:00:26,970 --> 00:00:28,480 But if we do that, then how do we know 10 00:00:28,480 --> 00:00:30,300 what our bucket is named? 11 00:00:30,300 --> 00:00:32,660 So that's where outputs come in. 12 00:00:32,660 --> 00:00:33,493 So, 13 00:00:34,590 --> 00:00:36,730 outputs simply 14 00:00:36,730 --> 00:00:41,350 store the value of a Terraform expression 15 00:00:41,350 --> 00:00:42,620 in the state. 16 00:00:42,620 --> 00:00:45,533 And at the end of an apply, 17 00:00:47,100 --> 00:00:48,820 they list those out into the console 18 00:00:48,820 --> 00:00:50,620 so you can review them. 19 00:00:50,620 --> 00:00:52,010 They also store them so that you can 20 00:00:52,010 --> 00:00:53,600 retrieve them at a later date. 21 00:00:53,600 --> 00:00:55,370 And there's also some advanced use cases 22 00:00:55,370 --> 00:00:57,730 that we'll get into later in the collaboration 23 00:00:57,730 --> 00:00:59,130 and the module section. 24 00:00:59,130 --> 00:01:00,340 Okay, so 25 00:01:01,250 --> 00:01:05,060 in addition to values generated by our resources, 26 00:01:05,060 --> 00:01:07,700 we can also output values from our, 27 00:01:07,700 --> 00:01:10,370 fetched from a data source. 28 00:01:10,370 --> 00:01:12,280 The syntax of 29 00:01:13,260 --> 00:01:16,170 referencing a data source is a little bit different. 30 00:01:16,170 --> 00:01:20,630 You have to prefix with the literal word data, 31 00:01:20,630 --> 00:01:21,550 and then 32 00:01:23,070 --> 00:01:25,760 the type, and then the, 33 00:01:25,760 --> 00:01:29,120 you have to reference the label that you gave it. 34 00:01:29,120 --> 00:01:32,830 Whereas with a resource, it's simply the type and the label. 35 00:01:32,830 --> 00:01:36,830 Okay, so we can see here for AWS caller identity, 36 00:01:36,830 --> 00:01:37,710 we called it current. 37 00:01:37,710 --> 00:01:40,280 For availability zones, we called it available. 38 00:01:40,280 --> 00:01:44,013 So we have to reference that as data.type.label. 39 00:01:47,460 --> 00:01:48,910 So let's take a look at that. 40 00:01:52,860 --> 00:01:54,210 Okay, so we'll do our plan. 41 00:02:02,410 --> 00:02:03,253 And apply. 42 00:02:18,640 --> 00:02:20,240 Okay, let's see what it gave us. 43 00:02:25,370 --> 00:02:27,713 So first, it listed the availability zones. 44 00:02:29,280 --> 00:02:32,453 So these are all the availability zones in the region, 45 00:02:34,030 --> 00:02:36,550 with the state available, okay? 46 00:02:36,550 --> 00:02:38,290 These are the names, these are the 47 00:02:39,920 --> 00:02:40,753 IDs. 48 00:02:42,700 --> 00:02:46,830 So we could use that, for example, to deploy 49 00:02:48,160 --> 00:02:51,030 a cluster of EC2 instances across 50 00:02:51,030 --> 00:02:53,610 multiple availability zones, for example. 51 00:02:53,610 --> 00:02:55,480 And then the caller info 52 00:02:57,130 --> 00:03:00,540 gives me a bunch of information about the 53 00:03:01,450 --> 00:03:04,370 AWS account that I'm using to 54 00:03:06,200 --> 00:03:07,720 interact with AWS. 55 00:03:07,720 --> 00:03:11,900 So account ID is one that's commonly needed 56 00:03:11,900 --> 00:03:14,650 for a bunch of different configurations. 57 00:03:14,650 --> 00:03:16,110 And then it gives me the bucket info. 58 00:03:16,110 --> 00:03:18,210 Now remember, I didn't give the bucket any 59 00:03:20,250 --> 00:03:21,860 parameters to build itself. 60 00:03:21,860 --> 00:03:26,520 So it has, Terraform has automatically created all of this. 61 00:03:26,520 --> 00:03:29,193 And you can see that the name is this. 62 00:03:30,050 --> 00:03:31,830 Okay, it's 63 00:03:31,830 --> 00:03:35,730 terraform dash, and then a bunch of 64 00:03:35,730 --> 00:03:38,523 random stuff, looks like it's based on the date and time. 65 00:03:39,500 --> 00:03:42,430 So you can fetch these things out. 66 00:03:42,430 --> 00:03:45,480 This is the entire data structure of the bucket. 67 00:03:45,480 --> 00:03:49,060 If we wanted, if we just want the name, 68 00:03:49,060 --> 00:03:50,190 we can do that 69 00:03:51,400 --> 00:03:53,680 too, just by specifying 70 00:03:54,850 --> 00:03:55,820 the individual 71 00:03:59,142 --> 00:03:59,975 attribute. 72 00:04:17,180 --> 00:04:19,740 Okay, now you can see that the bucket info 73 00:04:19,740 --> 00:04:21,360 is just the name. 74 00:04:21,360 --> 00:04:22,843 And then we can use, 75 00:04:26,210 --> 00:04:28,400 if we wanna reference this in a shell script 76 00:04:28,400 --> 00:04:29,550 or something like that, 77 00:04:32,590 --> 00:04:35,410 we can use the Terraform output command, 78 00:04:35,410 --> 00:04:40,013 and we'll just get the value of the object that we want.