49
loading...
This website collects cookies to deliver better user experience
ssh-keygen
. This will create a private key: id_rsa
and a public key: id_rsa.pub
under the following path: %UserProfile%/.ssh
.ssh-keyscan -H -t rsa ssh.dev.azure.com > $env:userprofile/.ssh/known_hosts
. The content of the file will be used later on in the setup of the Install SSH Key devops task in our DevOps pipeline.id_rsa
into azure pipelines -> Library -> Secure files. The file can be renamed to make it more friendly to use later on in the Install SSH Key devops task. In my case I have renamed my private key to terraform_rsa
.id_rsa.pub
. In my case I have renamed my public key to terraform_rsa.pub
.terraform-git-ssh-pub
and add the content of file id_rsa.pub
. This can also be stored as a secret in Azure key vault instead and can be accessed as variables in our pipeline using the azure key vault devops task.git_ssh_known_hosts
and add the content of file known_hosts
created earlier with ssh-keyscan
. This can also be stored as a secret in Azure key vault instead and can be accessed as variables in our pipeline using the azure key vault devops task.git_ssh_pass
and add the secret value. This can also be stored as a secret in Azure key vault instead and can be accessed as variables in our pipeline using the azure key vault devops task.id_rsa
)steps:
### Link to key vault.
- task: AzureKeyVault@1
displayName: Keyvault
inputs:
azureSubscription: TerraformSP #ADO service connection (Service principal)
KeyVaultName: 'mykeyvault'
secretsFilter: '*'
runAsPreJob: true
### Install SSH key on ADO agent to access terraform modules git repo.
- task: InstallSSHKey@0
displayName: 'Install an SSH key'
inputs:
knownHostsEntry: '$(git_ssh_known_hosts)' #Variable pulled in from key vault via key vault task above.
sshPublicKey: '$(terraform-git-ssh-pub)' #Variable pulled in from key vault via key vault task above.
sshPassphrase: '$(git_ssh_pass)' #Variable pulled in from key vault via key vault task above.
sshKeySecureFile: 'terraform_rsa' #This was originally renamed from id_rsa and uploaded into secure files library on the project hosting our TF modules repo
module "mymodule" {
source = "git::[email protected]:v3/Org/Project/repo"
}