1 00:00:06,590 --> 00:00:11,400 - Okay, so revisiting collaboration a little bit. 2 00:00:11,400 --> 00:00:14,560 The model that we talked about earlier 3 00:00:14,560 --> 00:00:16,600 is a great model for collaborating 4 00:00:16,600 --> 00:00:21,417 with your teammates using the common Git repo 5 00:00:23,099 --> 00:00:25,470 and maybe using workspaces, 6 00:00:25,470 --> 00:00:28,220 maybe, maybe not to store the state file 7 00:00:28,220 --> 00:00:30,660 but if you need to collaborate with other teams 8 00:00:30,660 --> 00:00:32,210 within your organization? 9 00:00:32,210 --> 00:00:33,640 So a pretty common example 10 00:00:33,640 --> 00:00:35,684 is that there'll be team responsible 11 00:00:35,684 --> 00:00:40,020 for networking configuration or security configuration 12 00:00:40,020 --> 00:00:45,020 and other teams responsible for delivering applications, 13 00:00:45,490 --> 00:00:48,370 well, Terraform has a way to do that as well. 14 00:00:48,370 --> 00:00:50,780 So if we see in this diagram, 15 00:00:50,780 --> 00:00:55,580 let's say the user on the left is generating Terraform code 16 00:00:55,580 --> 00:00:57,660 that creates an S3 bucket 17 00:00:57,660 --> 00:01:02,100 that the user on the right being in a different team needs 18 00:01:02,100 --> 00:01:04,700 to read some data from that S3 bucket 19 00:01:04,700 --> 00:01:07,280 or write data to that S3 bucket 20 00:01:07,280 --> 00:01:09,350 but the name is dynamically generated 21 00:01:09,350 --> 00:01:12,940 and he doesn't have access to the GitHub repo, 22 00:01:12,940 --> 00:01:14,770 how can we connect the dots there? 23 00:01:14,770 --> 00:01:19,770 So let's take a quick look at terraform_remote data source. 24 00:01:20,170 --> 00:01:23,610 So if you'll recall in the last exercise, 25 00:01:23,610 --> 00:01:26,700 we configured a backend 26 00:01:26,700 --> 00:01:29,733 to hold our state as you can see in this, 27 00:01:30,830 --> 00:01:32,770 this is what we set up, okay? 28 00:01:32,770 --> 00:01:34,900 So we're writing to an S3 backend 29 00:01:34,900 --> 00:01:38,320 and we're creating an S3 bucket 30 00:01:38,320 --> 00:01:41,270 and you can see that the name is dynamically generated 31 00:01:41,270 --> 00:01:43,560 so we don't have the ability 32 00:01:43,560 --> 00:01:45,920 to easily communicate 33 00:01:45,920 --> 00:01:47,150 what the name of this bucket is 34 00:01:47,150 --> 00:01:49,950 and maybe we're using multiple namespaces 35 00:01:49,950 --> 00:01:51,420 on their multiple buckets 36 00:01:51,420 --> 00:01:54,410 so the way that we're gonna communicate this 37 00:01:54,410 --> 00:01:56,560 with another team 38 00:01:56,560 --> 00:02:00,650 is to simply give them the connection information 39 00:02:00,650 --> 00:02:03,080 and the name of the resource 40 00:02:04,830 --> 00:02:07,110 and we're gonna place this in the output 41 00:02:07,110 --> 00:02:08,870 just like we do in modules. 42 00:02:08,870 --> 00:02:11,610 In remote state configuration, 43 00:02:11,610 --> 00:02:15,920 the only access to the state is through the outputs, okay? 44 00:02:15,920 --> 00:02:19,113 So we can go ahead and we can apply this. 45 00:02:21,430 --> 00:02:23,060 So this tells us the bucket name 46 00:02:23,060 --> 00:02:25,130 that was generated dynamically. 47 00:02:25,130 --> 00:02:26,920 Now, if we go to our other team 48 00:02:26,920 --> 00:02:30,250 and we can see that they've configured a backend 49 00:02:30,250 --> 00:02:32,620 for their own state file here 50 00:02:32,620 --> 00:02:35,070 but they've also configured this data source called 51 00:02:35,070 --> 00:02:38,113 a terraform_remote_state, okay? 52 00:02:39,050 --> 00:02:41,750 And what this is is a reference 53 00:02:41,750 --> 00:02:45,110 to a backend for another Terraform project 54 00:02:45,110 --> 00:02:49,310 so this is going to be taking information stored 55 00:02:49,310 --> 00:02:51,120 in another Terraform state 56 00:02:51,120 --> 00:02:54,520 and bringing it into this Terraform config, okay? 57 00:02:54,520 --> 00:02:56,970 So we give it the key and the bucket name 58 00:02:56,970 --> 00:02:58,480 and the workspace 59 00:02:58,480 --> 00:03:00,930 from the other project, okay? 60 00:03:00,930 --> 00:03:04,880 And now we can reference items 61 00:03:05,790 --> 00:03:09,330 from the outputs of the other Terraform config here. 62 00:03:09,330 --> 00:03:11,680 So here is the syntax for doing this. 63 00:03:11,680 --> 00:03:14,003 It's data.terraform_remote_state. 64 00:03:14,003 --> 00:03:17,530 This is just like any other data source 65 00:03:17,530 --> 00:03:19,580 and then we're gonna look at the outputs. 66 00:03:24,340 --> 00:03:25,600 Okay, so these are the outputs. 67 00:03:25,600 --> 00:03:27,453 We could say outputs. 68 00:03:32,800 --> 00:03:36,076 Okay so this will give us the output that we stored 69 00:03:36,076 --> 00:03:37,953 in the other file. 70 00:03:39,520 --> 00:03:41,370 So now you can see that we've fetched the name 71 00:03:41,370 --> 00:03:44,900 of that dynamically generated bucket. 72 00:03:44,900 --> 00:03:47,400 This is obviously a really trivial example 73 00:03:47,400 --> 00:03:48,550 but you can extrapolate 74 00:03:48,550 --> 00:03:53,072 from this very complex inner workings between teams. 75 00:03:53,072 --> 00:03:54,260 Again, as I said, 76 00:03:54,260 --> 00:03:55,330 a very common one of these 77 00:03:55,330 --> 00:03:57,100 is things like networking components, 78 00:03:57,100 --> 00:03:59,290 route tables, gateways, things like that 79 00:03:59,290 --> 00:04:01,580 can be communicated this way. 80 00:04:01,580 --> 00:04:04,660 Security credentials can be communicated this way, 81 00:04:04,660 --> 00:04:07,920 so lots and lots of usage for this. 82 00:04:07,920 --> 00:04:11,250 One other thing is namespacing 83 00:04:11,250 --> 00:04:15,210 so oftentimes if we have namespaces that correspond 84 00:04:15,210 --> 00:04:16,770 to Git branches or something like that, 85 00:04:16,770 --> 00:04:18,450 then those can easily be coordinated 86 00:04:18,450 --> 00:04:20,330 between different state files 87 00:04:20,330 --> 00:04:21,483 using this method.