Catalog to create Ec2 instance and run Terraform scripts

Hi ,

I want to run a catalog which needs to create an Ec2 instance and run some terraform scripts
How can i put these two tasks in one catalog ?
Example : ec2 provision and provisioned ec2 instance gets attached to existing ebs volume by terraform scripts,

I need to get the ec2 instance id as output and pass the id in terraform scripts as input

Hello @Paul_B,

I think there could be a few ways to do this, even beyond what I mention below. Hopefully it might spur some ideas for your case.

  1. Use a workflow for both as tasks
    a. Already have/create an instance type that deploys as you expect, or use the built-in EC2 instance type
    b. Already have/create a Terraform App Blueprint that deploys as you expect
    c. Create a workflow that contains two tasks that call the Morpheus API. One task for calling the EC2 instance to be provisioned and another for the Terraform
    d. The output from the API creation of the instance, the externalId could be obtained from the server(s) created (another API call for the server(s). The external ID could be passed to the second task calling the Terraform App Blueprint
    e. Publish the workflow as a Catalog item

  2. Have a Terraform App Blueprint that contains an aws_instance resource, which Morpheus will natively see and create an Instance of. This is a link of our morpheus-automation-examples repo that contains an example of deploying an instance with the agent installed. There are other examples as well. You could use a local-exec provisioners to call the API after and get the instance id created in Morpheus under the App and then the servers to get the externalId. The Blueprint could be published to the end user as a Catalog Item.

    :exclamation: Note that if you use Morpheus variables for interpolation, you’ll need to use Terraform Spec templates. Otherwise, you can just use Terraform input variables.

  3. The final idea I can think of is to attach a workflow to an instance type or configured in the Catalog Item, which a task in it can call the Terraform App Blueprint. There are phases that can be configured when the tasks should run, such as the provision or post-provision phase, which would happen after the instance is created. You would have access to the Moprheus instance variables in this context and could get the server details and get the externalId from the server(s) via an API call. That externalId could be passed to the task that calls the Terraform App Blueprint and inputs the Terraform variables. The Instance could be published to the end user as a Catalog Item.

Checking your first suggestion “1.Use a workflow for both as tasks” , Tasks doesnot provide an option to use terraform blueprints or terraform based scripts , attached screenshot for reference

Sorry for the confusion @Paul_B. I was meaning that you can create tasks that calls the Create an App Morpheus API. That is, using one of the scripting languages there you can call the API with a JSON payload. Or you can use the HTTP task, which can be configured to call the API too. Tasks Documentation

Here is an example of what I would mean, using a Shell Script task running as local:

curl -k --url https://morpheusUrl/api/apps --request POST --header ‘accept: application/json’ --header ‘authorization: Bearer useYourToken’ --header ‘content-type: application/json’ --data ‘{“group”:{“id”:1},“defaultCloud”:{“id”:2},“blueprintId”:4,“name”:“MyTestApp1”,“templateParameter”:{“access_key”:“useYourKey”,“secret_key”:“useYourKey”,“name”:“testinstance1”,“region”:“us-east-2”,“type”:“t3.small”,“sec_group_name”:“test-sec-group1”,“vpc”:“useYourVPCId”}}’

In the above example, I was using the morpheus-automation-examples I mentioned previously. You can use a task to Create an Instance via the API and also retrieve details of the instance, which can be passed to the Terraform task mentioned above.

:information_source: On our API Docs page, you can build your queries and even try it: