- Okay, so revisiting collaboration a little bit.
The model that we talked about earlier
is a great model for collaborating
with your teammates using the common Git repo
and maybe using workspaces,
maybe, maybe not to store the state file
but if you need to collaborate with other teams
within your organization?
So a pretty common example
is that there'll be team responsible
for networking configuration or security configuration
and other teams responsible for delivering applications,
well, Terraform has a way to do that as well.
So if we see in this diagram,
let's say the user on the left is generating Terraform code
that creates an S3 bucket
that the user on the right being in a different team needs
to read some data from that S3 bucket
or write data to that S3 bucket
but the name is dynamically generated
and he doesn't have access to the GitHub repo,
how can we connect the dots there?
So let's take a quick look at terraform_remote data source.
So if you'll recall in the last exercise,
we configured a backend
to hold our state as you can see in this,
this is what we set up, okay?
So we're writing to an S3 backend
and we're creating an S3 bucket
and you can see that the name is dynamically generated
so we don't have the ability
to easily communicate
what the name of this bucket is
and maybe we're using multiple namespaces
on their multiple buckets
so the way that we're gonna communicate this
with another team
is to simply give them the connection information
and the name of the resource
and we're gonna place this in the output
just like we do in modules.
In remote state configuration,
the only access to the state is through the outputs, okay?
So we can go ahead and we can apply this.
So this tells us the bucket name
that was generated dynamically.
Now, if we go to our other team
and we can see that they've configured a backend
for their own state file here
but they've also configured this data source called
a terraform_remote_state, okay?
And what this is is a reference
to a backend for another Terraform project
so this is going to be taking information stored
in another Terraform state
and bringing it into this Terraform config, okay?
So we give it the key and the bucket name
and the workspace
from the other project, okay?
And now we can reference items
from the outputs of the other Terraform config here.
So here is the syntax for doing this.
It's data.terraform_remote_state.
This is just like any other data source
and then we're gonna look at the outputs.
Okay, so these are the outputs.
We could say outputs.
Okay so this will give us the output that we stored
in the other file.
So now you can see that we've fetched the name
of that dynamically generated bucket.
This is obviously a really trivial example
but you can extrapolate
from this very complex inner workings between teams.
Again, as I said,
a very common one of these
is things like networking components,
route tables, gateways, things like that
can be communicated this way.
Security credentials can be communicated this way,
so lots and lots of usage for this.
One other thing is namespacing
so oftentimes if we have namespaces that correspond
to Git branches or something like that,
then those can easily be coordinated
between different state files
using this method.