Oracle by Example brandingCreating a Template for Oracle Cloud Stack

section 0Before You Begin

This 20-minute tutorial shows you how to use the Oracle Cloud Stack console to create and test a custom stack template.

Background

To build and deploy their applications, businesses often require sophisticated environments that consist of multiple, integrated cloud services. Provisioning each of these services individually is time-consuming and error-prone. Oracle Cloud Stack uses templates to provision a group of cloud resources called a stack.

Templates also support input parameters. Users can enter values for these parameters when they create a stack from the template.

Cloud Stack provides several standard templates, but you can quickly create your own template using the web console. If you prefer to create a custom template by cloning one of the Oracle ones, see the tutorial Customizing a Template for Oracle Cloud Stack.

What Do You Need?

  • Valid credentials for an Oracle Cloud account
  • An active subscription to Oracle Database Cloud Service
  • An active subscription to Oracle Cloud Infrastructure Object Storage Classic
  • Your REST endpoint URL for Oracle Cloud Infrastructure Object Storage Classic (see About REST URLs)

section 1Configure Template Storage

If this is the first time for anyone in this Oracle Cloud account to work with templates in the Cloud Stack console, you must create a cloud storage container for your unpublished template files.

  1. Sign in to Oracle Cloud.
  2. From the Oracle Cloud Infrastructure Console, click the Navigation menu Dashboard Menu Icon at the top left corner of the page, expand Classic Infrastructure Services, and then select Storage Classic.

    Note: On some older Oracle Cloud accounts, you use the Oracle Cloud Infrastructure Classic Console. Click the Navigation menu Dashboard Menu Icon, and then select Storage Classic.

  3. From the Storage Classic console, click Create Container.
  4. For Name, enter StackTemplates. Then click Create.
  5. Click the Navigation menu Storage Menu Icon at the top left corner of the page, and then select Oracle Database Cloud Service.

    Tip: You can access Cloud Stack from any Oracle Platform service.

  6. From the Oracle Database Cloud Service console, click the Navigation menu Dashboard Menu Icon at the top left corner of the page, and then select Cloud Stack.
  7. From the Oracle Cloud Stack console, click Templates.
    Click Templates on oracle Cloud Stack console
    Description of the illustration click_templates.png
  8. Click the Unpublished tab. The Cloud Storage Credentials dialog displays.

    Note: You can also update the existing storage settings by clicking Configure cloud storage Gear Icon.

  9. For Cloud Storage Container, enter Your_Storage_REST_URL/StackTemplates. For example, https://foo.storage.oraclecloud.com/v1/MyService-bar/StackTemplates.
  10. For Username and Password, enter your Oracle Cloud credentials, or the credentials of another Oracle Cloud user who has write access to this storage container.
  11. Click Apply Changes.

section 2Create a Template

  1. From the Unpublished Templates page, click Add Template, and then select Create New Template. The Template Builder is displayed.
  2. Above the toolbar, click Right Arrow Icon.
    click expand arrow above toolbar
    Description of the illustration template_name.png
  3. In the first input field, set the template's name to MyStackTemplate.
  4. Set the templateDescription to Create an Oracle database.
  5. Click Save current template Save Icon.

section 3Add Template Parameters

  1. In the left panel of the Template Builder, to the right of Parameters, click Add parameter Plus Icon.
    click plus sign add parameter
    Description of the illustration add_parameter.png
  2. For the parameter's name, enter dbPassword.
  3. Configure the parameter:
    • description: The password for the DB system administrator
    • label: Database Password
    • mandatory: true
    • type: Password
    • maxLength: 30
    • minLength: 8
  4. Click Apply Changes.
  5. Click Add parameter Plus Icon again.
  6. For the parameter's name, enter publicKey.
  7. Configure the parameter:
    • description: Generate a new key pair, enter a key value, or upload a key file
    • label: SSH Public Key
    • mandatory: true
    • type: Ssh
  8. Click Apply Changes.
  9. Click Save current template Save Icon.

section 4Create a Resource

  1. In the left panel of the Template Builder, expand Resources and locate the Database resource type. You can use the Search field if you prefer.
    database in expanded resources
    Description of the illustration database_resource.png
  2. Either drag and drop the Database resource onto the canvas area (right side), or click Add resource Plus Icon.
  3. In the canvas area, right-click the resource, and then select Edit.
    select edit
    Description of the illustration edit_resource.png
  4. Replace the generated resource name with the value oracledb1.
  5. Update these required resource parameters:
    • shape: oc3
    • subscriptionType: HOURLY
    • level: PAAS
    • version: 12.2.0.1
    • edition: SE
  6. For serviceName, enter the text Fn to display a list of functions. Select the function Fn::GetParam.
    Select the function GetParam
    Description of the illustration select_getparam.png
  7. Replace the text paramName with serviceName.
    'Fn::GetParam': serviceName

    Note: You do not have to explicitly define the serviceName parameter in your templates.

  8. Update this value and use the Fn::Join function to add the text "DB" to the end of the stack's name. Pass the arguments to this function as a sequence:
    'Fn::Join':
      - ''
      - - 'Fn::GetParam': serviceName
        - DB
  9. For vmPublicKeyText, retrieve the value of your publicKey parameter:
    'Fn::GetParam': publicKey
  10. Expand parameters, and then expand 0.
    expand parameters then expand 0
    Description of the illustration database_params.png
    Scroll down if necessary.
  11. Update these required resource parameters:
    • type: db
    • usableStorage: 15
    • adminPassword: 'Fn::GetParam': dbPassword
    • sid: ORCL
    • backupDestination: NONE
  12. Click Apply Changes.
  13. Click Save current template Save Icon.

section 5Publish the Template

  1. Click Validate current template Validation Icon.

    If there are any validation errors, click Open YAML editor Command Prompt Icon to view the full template definition, and then correct the errors.

  2. Click Publish current template Publish Icon.
  3. Click the Published tab.
  4. Verify the presence of your new template, MyStackTemplate.

section 6Test the Template

  1. To the right of the template, click Create a stack with this template Create Stack Icon.
  2. Configure the stack's parameters:
    • Name: MyStack
    • Template: MyStackTemplate
    • Database Password: test
    • Confirm Database Password: test
  3. To the right of SSH Public Key, click Edit.
  4. Select the option Create a New Key, and then click Enter.
  5. Click Download, and then click Done.
  6. Click Next. An error message displays because of the Database Password constraints.
  7. Enter a password that contains at least one lowercase letter, one uppercase letter, one number, and one of these symbols: _, #, $. Then click Next.

    The password must begin with a letter.

    Tip: You can also configure an allowedPattern for a template parameter, such as ^(?=.*?[A-Z])(?=.*?[a-z])(?=.*[0-9])[a-zA-Z]([a-zA-Z0-9_#])+$.

  8. Click Confirm.

    Note: When you edit a published template, you will also need to change the templateVersion prior to publishing it again.


next stepNext Tutorial

Creating a Custom Action in an Oracle Cloud Stack Template


more informationWant to Learn More?