本地的 Terraform 计划显示导入后没有更改,但在 github 操作上显示创建

问题描述 投票:0回答:1

我在 Azure 上部署了一些资源,当我在本地导入它们(CDN 配置文件和端点)以生成状态文件时,它显示“无更改”,您的基础架构匹配。 我有一个 git 生成计划工作流程,它只显示更改,而不显示应用,它显示这些资源的创建,即使我已将本地生成的 terraform 状态文件放置在从中选择更改的文件夹中。 terraform 脚本很简单 -

     data "azurerm_resource_group" "prresourcegroup" {
        name                                      = local.rgname
     }


    data "azurerm_storage_account" "frontendappstorage" {
        name                                      = "fastorage"
        resource_group_name                       = local.rgname
     }


    resource "azurerm_cdn_profile" "cdn-profile" {
      name                                              = "prcdnprofile"
      resource_group_name                               = data.azurerm_resource_group.prresourcegroup.name
      sku                                               = "Premium_Verizon"
      location                                          = "global"
      lifecycle {
        prevent_destroy = true
        ignore_changes = [
          tags
        ]
      }
    }

     resource "azurerm_cdn_endpoint" "frontend-endpoint" {
       name                                              = "eptpr"
       profile_name                                      = azurerm_cdn_profile.cdn-profile.name
       resource_group_name                               = data.azurerm_resource_group.prresourcegroup.name
       location                                          = "global"
       optimization_type                                 = "GeneralWebDelivery"
       querystring_caching_behaviour                     = "IgnoreQueryString" : "NotSet"
       origin {
         name      = data.azurerm_storage_account.frontendappstorage.primary_web_host
         host_name = data.azurerm_storage_account.frontendappstorage.primary_web_host
       }

       origin_host_header = data.azurerm_storage_account.frontendappstorage.primary_web_host

       lifecycle {
         ignore_changes = [
           tags,
           origin,
           optimization_type,
           is_compression_enabled,
           global_delivery_rule
         ]
       }
     }

Github actions.yaml -

     name: Plan terraform changes
     description: Produces a plan of the changes to be made by Terraform
     
     runs:
       using: composite

       steps:
         - uses: cschleiden/replace-tokens@v1 # Replace tokens in TF files with environment variable values
           with:
             files: '["**/*.tf*","**/*.yaml*"]'

         - uses: hashicorp/setup-terraform@v3

         - name: Terraform Init Frontend
               shell: bash
               working-directory: terraform/frontend
               run: terraform init

             - name: Terraform Validate Frontend
               shell: bash
               working-directory: terraform/frontend
               run: terraform validate

             - name: Terraform Plan Frontend
               shell: bash
               working-directory: terraform/frontend
               run: terraform plan --var-file=variables.tfvars -input=false -no-color >> ../../${{env.Environment-Name}}_plan.txt

             - name: Save plan
                   uses: actions/upload-artifact@v4
                   with:
                     name: ${{env.Environment-Name}}_plan.txt
                     path: ${{env.Environment-Name}}_plan.txt  

这仅适用于计划变更,并不实际适用。

github terraform github-actions terraform-provider-azure
1个回答
0
投票

Github 引用了错误的状态文件,导致本地和 git 工作流程出现差异。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.