metadata:
  name: cloudFoundryCreateService
  description: Creates one or multiple Services in Cloud Foundry
  longDescription: |
    Creates one or multiple Cloud Foundry Services in Cloud Foundry
    Mandatory:
    * Cloud Foundry API endpoint, Organization, Space and user are available

    Please provide either of the following options:
    * If you chose to create a single Service the Service Instance Name, Service Plan and Service Broker of the Service to be created have to be available. You can set the optional `cfCreateServiceConfig` flag to configure the Service creation with your respective JSON configuration. The JSON configuration can either be an in-line JSON string or the path a dedicated JSON configuration file containing the JSON configuration. If you chose a dedicated config file, you must store the file in the same folder as your `Jenkinsfile` that starts the Pipeline in order for the Pipeline to be able to find the file. Most favourable SCM is Git. If you want the service to be created from a particular broker you can set the optional `cfServiceBroker`flag. You can set user provided tags for the Service creation using a flat list as the value for the optional `cfServiceTags` flag. The optional `cfServiceBroker` flag can be used when the service name is ambiguous.
    * For creating one or multiple Cloud Foundry Services at once with the Cloud Foundry Create-Service-Push Plugin using the optional `serviceManifest` flag. If you chose to set this flag, the Create-Service-Push Plugin will be used for all Service creations in this step and you will need to provide a `serviceManifest.yml` file. In that case, above described flags and options will not be used for the Service creations, since you chose to use the Create-Service-Push Plugin. Please see below examples for more information on how to make use of the plugin with the appropriate step configuation. Additionally the Plugin provides the option to make use of variable substitution for the Service creations. You can find further information regarding the functionality of the Cloud Foundry Create-Service-Push Plugin in the respective documentation: [Cloud Foundry Create-Service-Push Plugin](https://github.com/dawu415/CF-CLI-Create-Service-Push-Plugin)
spec:
  inputs:
    secrets:
      - name: cfCredentialsId
        description: Jenkins 'Username with password' credentials ID containing user and password to authenticate to the Cloud Foundry API.
        type: jenkins
        aliases:
          - name: cloudFoundry/credentialsId
    resources:
      - name: deployDescriptor
        type: stash
    params:
      - name: cfApiEndpoint
        type: string
        description: Cloud Foundry API endpoint
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: true
        aliases:
          - name: cloudFoundry/apiEndpoint
        default: "https://api.cf.eu10.hana.ondemand.com"
      - name: username
        type: string
        description: User or E-Mail for CF
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
        secret: true
        resourceRef:
          - name: cfCredentialsId
            type: secret
            param: username
          - type: vaultSecret
            name: cloudfoundryVaultSecretName
            default: cloudfoundry-$(org)-$(space)
      - name: password
        type: string
        description: Password for Cloud Foundry User
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
        mandatory: true
        secret: true
        resourceRef:
          - name: cfCredentialsId
            type: secret
            param: password
          - type: vaultSecret
            default: cloudfoundry-$(org)-$(space)
            name: cloudfoundryVaultSecretName
      - name: cfOrg
        type: string
        description: Cloud Foundry org
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: true
        aliases:
          - name: cloudFoundry/org
      - name: cfSpace
        type: string
        description: Cloud Foundry Space
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: true
        aliases:
          - name: cloudFoundry/space
      - name: cfService
        type: string
        description: Parameter for Cloud Foundry Service to be used for creating Cloud Foundry Service
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/service
      - name: cfServicePlan
        type: string
        description: Parameter for Cloud Foundry Service Plan to be used when creating a Cloud Foundry Service
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/servicePlan
      - name: cfServiceInstanceName
        type: string
        description: Parameter for naming the Service Instance when creating a Cloud Foundry Service
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/serviceInstanceName
      - name: cfServiceBroker
        type: string
        description: Parameter for Service Broker to be used when creating a Cloud Foundry Service
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/serviceBroker
      - name: cfCreateServiceConfig
        type: string
        description: Path to JSON file or JSON in-line string for a Cloud Foundry Service creation
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/createServiceConfig
      - name: cfServiceTags
        type: string
        description: Flat list of Tags to be used when creating a Cloud Foundry Service in a single string
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/serviceTags
      - name: serviceManifest
        type: string
        description: Path to Cloud Foundry Service Manifest in YAML format for multiple service creations that are being passed to a Create-Service-Push Cloud Foundry cli plugin
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/serviceManifest
          - name: cfServiceManifest
        default: "service-manifest.yml"
      - name: manifestVariables
        type: "[]string"
        description: Defines a List of variables as key-value Map objects used for variable substitution within the file given by the Manifest. Defaults to an empty list, if not specified otherwise. This can be used to set variables like it is provided by `cf push --var key=value`. The order of the maps of variables given in the list is relevant in case there are conflicting variable names and values between maps contained within the list. In case of conflicts, the last specified map in the list will win. Though each map entry in the list can contain more than one key-value pair for variable substitution, it is recommended to stick to one entry per map, and rather declare more maps within the list. The reason is that if a map in the list contains more than one key-value entry, and the entries are conflicting, the conflict resolution behavior is undefined (since map entries have no sequence). Variables defined via `manifestVariables` always win over conflicting variables defined via any file given by `manifestVariablesFiles` - no matter what is declared before. This is the same behavior as can be observed when using `cf push --var` in combination with `cf push --vars-file`
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/manifestVariables
          - name: cfManifestVariables
      - name: manifestVariablesFiles
        type: "[]string"
        description: Defines the manifest variables Yaml files to be used to replace variable references in manifest. This parameter is optional and will default to `manifest-variables.yml`. This can be used to set variable files like it is provided by `cf push --vars-file <file>`. If the manifest is present and so are all variable files, a variable substitution will be triggered that uses the `cfManifestSubstituteVariables` step before deployment. The format of variable references follows the Cloud Foundry standard in `https://docs.cloudfoundry.org/devguide/deploy-apps/manifest-attributes.html#variable-substitution`
        scope:
          - PARAMETERS
          - STAGES
          - STEPS
          - GENERAL
        mandatory: false
        aliases:
          - name: cloudFoundry/manifestVariablesFiles
          - name: cfManifestVariablesFiles
  containers:
    - name: cf
      image: ppiper/cf-cli:latest
