divya bommerla
divya bommerla

Reputation: 1

Data Factory Set variable with KeyVault Value using Post method and body in ADF

In ADF pipeline using post method, In body i have

grant_type=client_credentials&client_id=xxxxx&client_secret=xxxxx&resource=xxxxx.net

I have to create a variable for secret and how to pass the variable for secret and how to debug the pipeline in ADF.

I have tried to add a variable for secret and passing the variable in body it is throwing a error like bad request

Upvotes: 0

Views: 219

Answers (1)

Rakesh Govindula
Rakesh Govindula

Reputation: 11514

To achieve your requirement, first you need to generate the Bearer token for it.

Create an app registration and secret. Assign Key vault administrator role to that app like below.

enter image description here

Then give the below configurations in a web activity in ADF pipeline.

URL : https://login.microsoftonline.com/<tenant-id>/oauth2/token

Body : grant_type=client_credentials&client_id=<your-app-client-id>&client_secret=<your-app-client-secret>&resource=https://vault.azure.net

Headers : Content-type application/x-www-form-urlencoded

enter image description here

This will generate required access_token. To update a secret value, first you need the latest secret version of the secret. For that Use another web activity with below configurations.

URL - https://<keyvault_name>.vault.azure.net/secrets/<secret_name>/?api-version=7.0

Headers : Bearer @{activity('Web3').output.access_token}

enter image description here

This will give keyvault URL in its id which contains current secret version and current secret value.

enter image description here

Now, use this id as URL in another web activity and here pass your variable to the body with a PUT request like below to update the secret value.

URL : @concat(activity('Web1').output.id,'?api-version=7.4')

Body : @json(concat('{"value": "',variables('new_secret'),'", "contentType": "","attributes":{"enabled": true},"tags": {}}'))

enter image description here

Debug the pipeline and after the pipeline run, the secret value will be updated from the set variable like mine.

enter image description here

Upvotes: 1

Related Questions