api connection failed connect to Automation account using logicapp through bicep

221 views Asked by At

resource workflows_newlogic06_name_resource 'Microsoft.Logic/workflows@2016-06-01' = {
  name: workflows_newlogic06_name
  location:location
  properties: {
    state: 'Enabled'
    definition: {
      '$schema': 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'
      contentVersion: '1.0.0.0'
      parameters: {
        '$connections': {
          defaultValue: {}
          type: 'Object'
        }
      }
      triggers: {
        Recurrence: {
          recurrence: {
            frequency: 'Month'
            interval: 3
          }
          evaluatedRecurrence: {
            frequency: 'Month'
            interval: 3
          }
          type: 'Recurrence'
        }
      }
      actions: {
        Create_job: {
          runAfter: {}
          type: 'ApiConnection'
          inputs: {
            host: {
              connection: {
                name: '@parameters(\'$connections\')[\'azureautomation_1\'][\'connectionId\']'
              }
            }
            method: 'put'
            path: '/subscriptions/@{encodeURIComponent(\'${subscriptionid}\')}/resourceGroups/@{encodeURIComponent(\'nextone1\')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent(\'newauto01\')}/jobs'
            queries: {
              wait: true
              'x-ms-api-version': '2015-10-31'
            }
          }
        }
        Get_job_output: {
          runAfter: {
            Create_job: [
              'Succeeded'
            ]
          }
          type: 'ApiConnection'
          inputs: {
            host: {
              connection: {
                name: '@parameters(\'$connections\')[\'azureautomation_1\'][\'connectionId\']'
              }
            }
            method: 'get'
            path: '/subscriptions/@{encodeURIComponent(\'{subscriptionid}\')}/resourceGroups/@{encodeURIComponent(\'nextone1\')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent(\'newauto01\')}/jobs/@{encodeURIComponent(body(\'Create_job\')?[\'properties\']?[\'jobId\'])}/output'
            queries: {
              'x-ms-api-version': '2015-10-31'
            }
          }
        }
      }
      outputs: {}
    }
    parameters: {
      '$connections': {
        value: {
          azureautomation_1: {
            connectionId: connections_azureautomation_externalid
            connectionName: 'azureautomation'
            id: '/subscriptions/{subscriptionid}/providers/Microsoft.Web/locations/eastus/managedApis/azureautomation'
          }
        }
      }
    }
  }
}
resource connections_azureautomation_name_resource 'Microsoft.Web/connections@2016-06-01' = {
  name: connections_azureautomation_name
  location: location
  properties: {
    displayName: 'new-c0n-01'
    statuses: [
      {
        status: 'Ready'
      }
    ]
    customParameterValues: {}
    createdTime: '2023-09-26T11:35:24.8852931Z'
    changedTime: '2023-09-26T11:35:24.8852931Z'
    api: {
      name: connections_azureautomation_name
      displayName: 'Azure Automation'
      description: 'Azure Automation provides tools to manage your cloud and on-premises infrastructure seamlessly.'
      iconUri: 'https://connectoricons-prod.azureedge.net/u/shgogna/globalperconnector-train1/1.0.1639.3312/${connections_azureautomation_name}/icon.png'
      brandColor: '#56A0D7'
      id:subscriptionResourceId('Microsoft.web/locations/managedApis', location, 'azureautomation')
      type: 'Microsoft.Web/locations/managedApis'
      }
  }
}

What I Need? created azure automation account, runbook, logic app along with api connections using bicep. The deployment was successful but logicapp connections was not established trying from long got frustrated did some one help me finding out these. Thanks

tried with many ways of finding the solution set the parametervalueType='alternative' couldn't work out.

1

There are 1 answers

2
Jahnavi On

Api connection failed connect to Automation account using logic App through bicep: -

After analyzing your code, it looks good to me, but I made a few changes and attached the modified code below.

These kind of issues with connection can occur with older Api versions. As a result, always use the most recent Api version. 'Microsoft.Logic/workflows@2019-05-01.

param location string = resourceGroup().location
param subscriptionid string = 'xxxxx'
param connections_azureautomation_name string = 'jahconn'
resource workflows_newlogic06_name_resource 'Microsoft.Logic/workflows@2019-05-01' = {
  name: 'newwf'
  location:location
  properties: {
    state: 'Enabled'
    definition: {
      '$schema': 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'
      contentVersion: '1.0.0.0'
      parameters: {
        '$connections': {
          defaultValue: {}
          type: 'Object'
        }
      }
      triggers: {
        Recurrence: {
          recurrence: {
            frequency: 'Month'
            interval: 3
          }
          evaluatedRecurrence: {
            frequency: 'Month'
            interval: 3
          }
          type: 'Recurrence'
        }
      }
      actions: {
        Create_job: {
          runAfter: {}
          type: 'ApiConnection'
          inputs: {
            host: {
              connection: {
                name: '@parameters(\'$connections\')[\'azureautomation_1\'][\'connectionId\']'
              }
            }
            method: 'put'
            path: '/subscriptions/@{encodeURIComponent(\'${subscriptionid}\')}/resourceGroups/@{encodeURIComponent(\'nextone1\')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent(\'newauto01\')}/jobs'
            queries: {
              wait: true
              'x-ms-api-version': '2015-10-31'
            }
          }
        }
        Get_job_output: {
          runAfter: {
            Create_job: [
              'Succeeded'
            ]
          }
          type: 'ApiConnection'
          inputs: {
            host: {
              connection: {
                name: '@parameters(\'$connections\')[\'azureautomation_1\'][\'connectionId\']'
              }
            }
            method: 'get'
            path: '/subscriptions/@{encodeURIComponent(\'{subscriptionid}\')}/resourceGroups/@{encodeURIComponent(\'nextone1\')}/providers/Microsoft.Automation/automationAccounts/@{encodeURIComponent(\'newauto01\')}/jobs/@{encodeURIComponent(body(\'Create_job\')?[\'properties\']?[\'jobId\'])}/output'
            queries: {
              'x-ms-api-version': '2015-10-31'
            }
          }
        }
      }
      outputs: {}
    }
    parameters: {
      '$connections': {
        value: {
          azureautomation_1: {
            connectionName: 'azureautomation'
            connectionId: resourceId('Microsoft.Web/connections', connections_azureautomation_name)
            id: '/subscriptions/{subscriptionid}/providers/Microsoft.Web/locations/eastus/managedApis/azureautomation'
          }
        }
      }
    }
  }
}
resource connections_azureautomation_name_resource 'Microsoft.Web/connections@2016-06-01' = {
  name: connections_azureautomation_name
  location: location
  properties: {
    displayName: 'new-c0n-01'
    statuses: [
      {
        status: 'Ready'
      }
    ]
    customParameterValues: {}
    createdTime: '2023-09-26T11:35:24.8852931Z'
    changedTime: '2023-09-26T11:35:24.8852931Z'
    api: {
      name: connections_azureautomation_name
      displayName: 'Azure Automation'
      description: ''
      iconUri: 'https://connectoricons-prod.azureedge.net/u/shgogna/globalperconnector-train1/1.0.1639.3312/${connections_azureautomation_name}/icon.png'
      brandColor: '#56A0D7'
      id:subscriptionResourceId('Microsoft.web/locations/managedApis', location, 'azureautomation')
      type: 'Microsoft.Web/locations/managedApis'
      }
  }
}

Deployment succeeded:

enter image description here

enter image description here

enter image description here