<p>I feel like you are providing the answer yourself. Encode the entire cloud-init file as one-line base64 using a pre-processing script. Something like <code>cat cloud-init.txt | base64 -w0</code> would work for Linux based build agents, -w0 will encode everything in one line.</p>

CC BY-SA 4.0
2021-06-12T09:27:33.580Z
This is basically what I ended up doing, only I used PowerShell. I was hoping that there was some way to simply specify the file name and have the encoding part done for me. $encodedContent = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($cloudInitContent ))
Martin Brown
CC BY-SA 4.0
2021-06-11T06:30:18.663Z
2021-06-11T06:30:18.663Z
Michael
<p>I'm trying to set up a Ubuntu Server on Azure. None of the images do quite what I want, so I was planning on taking a vanilla Ubuntu image and using cloud-init to modify it. I'd like to be able to deploy this to multiple environments using Azure Pipelines and have an ARM Template that is deploying the vanilla instance quite nicely.</p>

<p>The issue I have is how to get the cloud-init script I have into the custom data parameter of the ARM Template. It seems that because ARM Templates have to be JSON the only way to do this is to have the cloud-init script on one very very long line. Either that or host the cloud-init file somewhere and do something hacky like this: <a href="https://www.wintellect.com/arm-templates-and-cloud-init/" rel="nofollow noreferrer">https://www.wintellect.com/arm-templates-and-cloud-init/</a>. The ARM Template task I'm using in Azure Pipelines does not seem to have a way to pass a file's contents as a parameter.</p>

<p>I'd like to have both the ARM Template and the cloud-init script as separate files in my private git repository. Currently I'm considering some kind of pre-processing build step to combine the two. Has anyone already done this and have a code example?</p>

<p>Maybe I'm "doing it wrong", what do other people do/what is the best way to do this?</p>

<azure-devops><azure><cloud-init>
How to combine cloud-init with Azure ARM Template
Martin Brown
# How to combine cloud-init with Azure ARM Template

(Asked by: username_0 on 2020-06-09)

I'm trying to set up a Ubuntu Server on Azure. None of the images do quite what I want, so I was planning on taking a vanilla Ubuntu image and using cloud-init to modify it. I'd like to be able to deploy this to multiple environments using Azure Pipelines and have an ARM Template that is deploying the vanilla instance quite nicely.

The issue I have is how to get the cloud-init script I have into the custom data parameter of the ARM Template. It seems that because ARM Templates have to be JSON the only way to do this is to have the cloud-init script on one very very long line. Either that or host the cloud-init file somewhere and do something hacky like this: <https://www.wintellect.com/arm-templates-and-cloud-init/>. The ARM Template task I'm using in Azure Pipelines does not seem to have a way to pass a file's contents as a parameter.

I'd like to have both the ARM Template and the cloud-init script as separate files in my private git repository. Currently I'm considering some kind of pre-processing build step to combine the two. Has anyone already done this and have a code example?

Maybe I'm "doing it wrong", what do other people do/what is the best way to do this?

**Tags:** azure-devops, azure, cloud-init


---

## 1 answers

### Answer by username_1 on 2021-06-11. Score: 1

I feel like you are providing the answer yourself. Encode the entire cloud-init file as one-line base64 using a pre-processing script. Something like `cat cloud-init.txt | base64 -w0` would work for Linux based build agents, -w0 will encode everything in one line.

> **Comments:**
> **username_0**: This is basically what I ended up doing, only I used PowerShell. I was hoping that there was some way to simply specify the file name and have the encoding part done for me. $encodedContent = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($cloudInitContent ))  

---

