- [Instructor] In this video,
you'll see how to provision
AWS service catalog products using Terraform.
With this capability,
you can use Terraform
to create a service catalog product and portfolio,
associate the product with the portfolio,
and share the portfolio with another AWS account.
We'll begin by creating
the service catalog portfolio and product.
For the purposes of this example,
we have already created the necessary Terraform file
in the root of the project and called it main.tf.
Let's review its contents.
Line one defines the AWS provider.
This is what Terraform will use to communicate with AWS.
Next, we define a Terraform resource
for AWS service catalog portfolio,
providing a name and description.
The provider name represents the person or organization
that owns the portfolio.
After defining the empty portfolio,
we define a resource for an AWS service catalog product.
In this case,
we're defining an AWS simple storage service
or Amazon S3 bucket.
We then pass the cloud formation template URL
used to define the product inside
the provisioning artifact parameters configuration block.
For this example,
we'll use a cloud formation template
in the GitHub repository
for AWS service catalog reference architecture.
Let's view the template in GitHub.
As you can see,
this cloud formation template provisions an S3 bucket.
Let's go back to the Terraform code.
Now that we've defined the product, we'll use
the Terraform principle portfolio association resource
to associate the S3 product
with the empty service catalog portfolio we created.
This is the same as adding a product to a portfolio
from within service catalog.
Next, we'll use AWS
service catalog principal portfolio association
to associate an IAM user or role with the portfolio.
This means that only this IAM user or role
will be able to see and launch the products
in that portfolio.
Next, we'll share the portfolio
with another AWS account or organization node.
The type parameter defines
who we want to share the portfolio with.
In this case,
we want to share this portfolio
with a specific account in the organization.
Next, let's look at the Terraform code
to provision the product itself.
First, we need to get the path to the specified product.
We find this path by using the data source
called AWS service catalog launch paths
and passing the product ID as the parameter.
Now that we've determined the path to this product,
we'll provision it
using the Terraform resource
called AWS service catalog provisioned product.
We'll pass the product details
from the AWS service catalog product and path ID resources.
Let's take a quick look at them both.
Here's the service catalog product we defined earlier.
Here's the path ID
that we obtained from this data source.
Here, we'll pass both IDs as parameters
and provision the product.
To run this code, let's initialize Terraform.
Next, let's run Terraform plan
to see what resources will be created in the AWS account.
As you can see, six resources will be created.
Next, we'll run Terraform apply to create these resources.
The Terraform apply is complete.
Let's check the AWS service catalog management console
and verify that the resources were created.
Here is the portfolio we defined in Terraform,
let's drill down.
The S3 bucket product we defined has also been created
and associated with this portfolio.
Let's check the sharing.
This portfolio is shared
with the organization member account we specified
in our Terraform code.
Let's check for associated roles.
The portfolio is associated
with the role in our Terraform code,
which allows a user with this ARN
to provision a product from service catalog.
Let's verify that the product has been provisioned.
As expected, the simple S3 bucket has been provisioned.
Let's confirm its presence in the S3 management console.
Here's the bucket we created.
You've just seen how to provision
AWS service catalog products using Terraform.
You can learn more about this topic in the description
and links for this video.
Thanks for watching, now it's your turn to try.