简体   繁体   English

如何使用 azure devops 从一个组织中的一个项目消费或调用 terraform 模块到另一个组织的另一个项目

[英]How to consume or call terraform modules from one project in one organisation to another project from another organisation using azure devops

I would like to know the way to consume or call terraform modules from one project in one organisation to another project from another organisation using azure devops.我想知道如何使用 azure devops 从一个组织中的一个项目使用或调用 terraform 模块到另一个组织的另一个项目。 I tried to explore ways but found one solution using the below but my IT team is not letting to use this method as this is braking the subsequent pipelines.我尝试探索各种方法,但发现了一种使用以下方法的解决方案,但我的 IT 团队不允许使用这种方法,因为这会阻碍后续管道。 Any suggestions please?有什么建议吗?

Also, requirement is I just need to refer the modules of terraform which are in another organization but as per my POC its downloading/checkout the code from that organization/project and then I am able to refer those modules.此外,要求是我只需要引用另一个组织中的 terraform 模块,但根据我的 POC,它从该组织/项目下载/签出代码,然后我就可以引用这些模块。 I would like to only refer those modules instead checkout the code from another organization and utilising/referencing.我只想引用那些模块,而不是从另一个组织检查代码并使用/引用。

Below is the reply from pipeline team:以下是管道团队的回复:

Can you exclude this part as it is not ideal and you need to take a different approach?你能排除这部分吗,因为它不理想,你需要采取不同的方法?

          echo "Git config update start"

          MY_PAT=$(yourPAT)

          B64_PAT=$(printf "%s"":$MY_PAT" | base64)

          git config --global http.extraheader "Authorization: Basic ${B64_PAT}"

          echo "Git config update end"

          terraform init

          terraform plan

you are introducing your cred in.gitconfig that's breaking all subsequent pipelines in the agent.您正在引入您的 cred in.gitconfig,它会破坏代理中的所有后续管道。

POC: The below code is cloning the entire modules code from another organization and we are referecing those modules but I just need to refer those modules directly instead of downloading and calling/referencing modules. POC:下面的代码是从另一个组织克隆整个模块代码,我们正在引用这些模块,但我只需要直接引用这些模块,而不是下载和调用/引用模块。

resources:
  repositories:
  - repository: Modules
    type: git
    name: 'Compute Platforms/CES-Terraform-Automation-Service'
    endpoint: Repo-bp-digital # Azure DevOps service connection
    ref: Modules
  - repository: self
    type: git
    name: 'Cloud Onboarding/terraform-testing-by-vivek'

AFAIK, There's only one option to connect to the project of another Azure DevOps organization that is by creating a Service Connection in the organization from where you want to run the pipeline and by creating a PAT token in the target organization and referencing it in the service connection,据我所知,只有一个选项可以连接到另一个 Azure DevOps 组织的项目,即在您要运行管道的组织中创建服务连接,并在目标组织中创建 PAT 令牌并在服务中引用它联系,

I created 2 Organizations, 1) Organization alpha1 and 2) Organization beta2.我创建了 2 个组织,1) 组织 alpha1 和 2) 组织 beta2。 I created 2 projects in both organizations with one YAML script and a task.我使用一个 YAML 脚本和一个任务在两个组织中创建了 2 个项目。

在此处输入图像描述

在此处输入图像描述

Created a PAT Token in Organization beta2.在组织 beta2 中创建了一个 PAT 代币。

在此处输入图像描述

在此处输入图像描述

Created service connection in the Alpha organization from where I am running the pipeline to beta org by referencing PAT token from beta org like below:-通过引用来自 beta 组织的 PAT 令牌,在 Alpha 组织中创建了服务连接,从那里我运行管道到 beta 组织,如下所示:-

在此处输入图像描述

在此处输入图像描述

trigger:

- master

variables:

pythonVersion: '3.8'

vmImageName: 'ubuntu-latest'

resources:

repositories:

- repository: remoteRepo

type: git

name: remote-access/shared-common-install

endpoint: remoteaccesstemp # Service connection name

ref: refs/heads/main

stages:

- stage: remote_git_test

jobs:

- job: git_test

steps:

# Running the template from the same repsitory

- template: templates/hello-alpha.yaml

# Checkout the remote repository

- checkout: remoteRepo

persistCredentials: true

# Call the template that is located in another repository in another organization

- template: templates/hello-beta.yaml@remoteRepo

Alternatively, you can create a terraform task in Azure DevOps and call your terraform module from another organization with the below script:-或者,您可以在 Azure DevOps 中创建一个 terraform 任务,并使用以下脚本从另一个组织调用您的 terraform 模块:-

terraform init -backend-config="repository=organization-beta2/project-beta2/_git/beta-2" -backend-config="token=Pat-token"

and

provider "azuredevops"{
    org_service_url = var.org_service_url
    personal_access_token = var.personal_access_token
}

You can add this code in your terraform init script in your Organization repo from where you're running pipeline and reference the template in System.Artifacts.您可以在运行管道的组织存储库中的 terraform 初始化脚本中添加此代码,并在 System.Artifacts 中引用模板。

在此处输入图像描述

Even Azure DevOps Rest API does not support connecting to different Azure DevOps organizations.即使 Azure DevOps Rest API 也不支持连接到不同的 Azure DevOps 组织。

References:-参考:-

GitHub - Azure-Samples/azure-pipelines-remote-tasks GitHub - Azure 示例/azure 管道远程任务

Trying to setup an Azure DevOps organization using Terraform:: my tech ramblings — A blog for writing about my techie ramblings By Carlos Trying to setup an Azure DevOps organization using Terraform:: my tech ramblings — 一个写我的技术漫谈的博客作者:Carlos

Azure DevOps Git: Fork into another Repo using Azure DevOps REST API - Stack Overflow By Andi Li-MSFT Azure DevOps Git:使用 Azure DevOps 分叉到另一个 Repo REST API - Andi Li-MSFT 的堆栈溢出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何配置从一个 ADO 组织到另一个 ADO 组织的自承载代理 - How to configure a self hosted agent from one ADO organisation to another ADO organisation 我无法将项目从“无组织”迁移到新创建的项目。 它说我没有权限? - I cannot migrate project from "no organisation" to a newly created one. It says I do not have permissions? 从terraform代码中的Azure DevOps的现有项目中获取存储库id - To get the repository id from an existing project of Azure DevOps in terraform code 将 BigQuery 表从一个项目导出到另一个项目 - Exporting BigQuery table from one project to another 如何将 GCS 存储桶从一个项目迁移到不同帐户中的另一个项目 - How to migrate GCS bucket from one project to another in different account Terraform,如何将数据从一个子模块传递到另一个 - Terraform, how to pass data from one child module to another 地形:谷歌云。 为什么我不能在没有组织的情况下创建新项目? - Terraform: Google cloud. Why cannot I create a new project without having an organisation? 按位置限制对 GCP 组织和项目资源的访问 - Restrict access to GCP organisation and project resources by location Terraform:如何将 output 从一种资源传递到另一种资源? - Terraform: How to pass output from one resource to another? 需要将 Spanner 数据库从一个 GCP 项目迁移到另一个 - Need to migrate Spanner db from one GCP Project to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM