- Okay, so in the last example with S3,
we saw that we couldn't create a bucket
with a generic name like bucket one.
So,
one way to work around this is to just
not give it a name at all, in which case,
Terraform will automatically assign it
a random string that's guaranteed to be unique.
But if we do that, then how do we know
what our bucket is named?
So that's where outputs come in.
So,
outputs simply
store the value of a Terraform expression
in the state.
And at the end of an apply,
they list those out into the console
so you can review them.
They also store them so that you can
retrieve them at a later date.
And there's also some advanced use cases
that we'll get into later in the collaboration
and the module section.
Okay, so
in addition to values generated by our resources,
we can also output values from our,
fetched from a data source.
The syntax of
referencing a data source is a little bit different.
You have to prefix with the literal word data,
and then
the type, and then the,
you have to reference the label that you gave it.
Whereas with a resource, it's simply the type and the label.
Okay, so we can see here for AWS caller identity,
we called it current.
For availability zones, we called it available.
So we have to reference that as data.type.label.
So let's take a look at that.
Okay, so we'll do our plan.
And apply.
Okay, let's see what it gave us.
So first, it listed the availability zones.
So these are all the availability zones in the region,
with the state available, okay?
These are the names, these are the
IDs.
So we could use that, for example, to deploy
a cluster of EC2 instances across
multiple availability zones, for example.
And then the caller info
gives me a bunch of information about the
AWS account that I'm using to
interact with AWS.
So account ID is one that's commonly needed
for a bunch of different configurations.
And then it gives me the bucket info.
Now remember, I didn't give the bucket any
parameters to build itself.
So it has, Terraform has automatically created all of this.
And you can see that the name is this.
Okay, it's
terraform dash, and then a bunch of
random stuff, looks like it's based on the date and time.
So you can fetch these things out.
This is the entire data structure of the bucket.
If we wanted, if we just want the name,
we can do that
too, just by specifying
the individual
attribute.
Okay, now you can see that the bucket info
is just the name.
And then we can use,
if we wanna reference this in a shell script
or something like that,
we can use the Terraform output command,
and we'll just get the value of the object that we want.