harness / terraform-provider-harness

Terraform provider for provisioning Harness resources
Apache License 2.0
38 stars 44 forks source link

Upgrading from version 0.12.x -> 0.13.x breaks pipelines #401

Open annymsMthd opened 1 year ago

annymsMthd commented 1 year ago

Terraform Version

v1.2.9

Affected Resource(s)

Please list the resources as a list, for example:

Terraform Configuration Files

resource "harness_platform_pipeline" "example" {
  identifier = "testddd"
  org_id     = "sre"
  project_id = "pavedroads"
  name       = "testtt"

  yaml = <<-EOT
      pipeline:
          name: name
          identifier: identifier
          allowStageExecutions: false
          projectIdentifier: projectIdentifier
          orgIdentifier: orgIdentifier
          tags: {}
          stages:
              - stage:
                  name: dep
                  identifier: dep
                  description: ""
                  type: Deployment
                  spec:
                      serviceConfig:
                          serviceRef: service
                          serviceDefinition:
                              type: Kubernetes
                              spec:
                                  variables: []
                      infrastructure:
                          environmentRef: testenv
                          infrastructureDefinition:
                              type: KubernetesDirect
                              spec:
                                  connectorRef: testconf
                                  namespace: test
                                  releaseName: release-<+INFRA_KEY>
                          allowSimultaneousDeployments: false
                      execution:
                          steps:
                              - stepGroup:
                                      name: Canary Deployment
                                      identifier: canaryDepoyment
                                      steps:
                                          - step:
                                              name: Canary Deployment
                                              identifier: canaryDeployment
                                              type: K8sCanaryDeploy
                                              timeout: 10m
                                              spec:
                                                  instanceSelection:
                                                      type: Count
                                                      spec:
                                                          count: 1
                                                  skipDryRun: false
                                          - step:
                                              name: Canary Delete
                                              identifier: canaryDelete
                                              type: K8sCanaryDelete
                                              timeout: 10m
                                              spec: {}
                                      rollbackSteps:
                                          - step:
                                              name: Canary Delete
                                              identifier: rollbackCanaryDelete
                                              type: K8sCanaryDelete
                                              timeout: 10m
                                              spec: {}
                              - stepGroup:
                                      name: Primary Deployment
                                      identifier: primaryDepoyment
                                      steps:
                                          - step:
                                              name: Rolling Deployment
                                              identifier: rollingDeployment
                                              type: K8sRollingDeploy
                                              timeout: 10m
                                              spec:
                                                  skipDryRun: false
                                      rollbackSteps:
                                          - step:
                                              name: Rolling Rollback
                                              identifier: rollingRollback
                                              type: K8sRollingRollback
                                              timeout: 10m
                                              spec: {}
                          rollbackSteps: []
                  tags: {}
                  failureStrategies:
                      - onFailure:
                              errors:
                                  - AllErrors
                              action:
                                  type: StageRollback
  EOT
}

this is from the example in the documentation

Debug Output

---[ REQUEST ]---------------------------------------
POST /gateway/v1/orgs/sre/projects/pavedroads/pipelines HTTP/1.1
Host: app.harness.io
User-Agent: terraform-provider-harness-platform-0.13.2
Content-Length: 3979
Accept: application/json
Content-Type: application/json
Harness-Account: xxxx
X-Api-Key: ****
Accept-Encoding: gzip

{
 "pipeline_yaml": "pipeline:\n    name: name\n    identifier: identifier\n    allowStageExecutions: false\n    projectIdentifier: projectIdentifier\n    orgIdentifier: orgIdentifier\n    tags: {}\n    stages:\n        - stage:\n            name: dep\n            identifier: dep\n            description: \"\"\n            type: Deployment\n            spec:\n                serviceConfig:\n                    serviceRef: service\n                    serviceDefinition:\n                        type: Kubernetes\n                        spec:\n"
2023-01-20T11:46:46.065-0800 [WARN]  unexpected data: registry.terraform.io/harness/harness:stderr="variables: []\n                infrastructure:\n                    environmentRef: testenv\n                    infrastructureDefinition:\n                        type: KubernetesDirect\n                        spec:\n                            connectorRef: testconf\n                            namespace: test\n                            releaseName: release-\u003c+INFRA_KEY\u003e\n                    allowSimultaneousDeployments: false\n                execution:\n                    steps:\n                        - stepGroup:\n                                name: Canary Deployment\n                                identifier: canaryDepoyment\n                                steps:\n                                    - step:\n                                        name: Canary Deployment\n                                        identifier: canaryDeployment\n                                        type: K8sCanaryDeploy\n                                        timeout: 10m\n"
2023-01-20T11:46:46.065-0800 [WARN]  unexpected data: registry.terraform.io/harness/harness:stderr="spec:\n                                            instanceSelection:\n                                                type: Count\n                                                spec:\n                                                    count: 1\n                                            skipDryRun: false\n                                    - step:\n                                        name: Canary Delete\n                                        identifier: canaryDelete\n                                        type: K8sCanaryDelete\n                                        timeout: 10m\n                                        spec: {}\n                                rollbackSteps:\n                                    - step:\n                                        name: Canary Delete\n                                        identifier: rollbackCanaryDelete\n                                        type: K8sCanaryDelete\n                                        timeout: 10m\n"
2023-01-20T11:46:46.065-0800 [WARN]  unexpected data: registry.terraform.io/harness/harness:stderr="spec: {}\n                        - stepGroup:\n                                name: Primary Deployment\n                                identifier: primaryDepoyment\n                                steps:\n                                    - step:\n                                        name: Rolling Deployment\n                                        identifier: rollingDeployment\n                                        type: K8sRollingDeploy\n                                        timeout: 10m\n                                        spec:\n                                            skipDryRun: false\n                                rollbackSteps:\n                                    - step:\n                                        name: Rolling Rollback\n                                        identifier: rollingRollback\n                                        type: K8sRollingRollback\n                                        timeout: 10m\n"
2023-01-20T11:46:46.065-0800 [WARN]  unexpected data: registry.terraform.io/harness/harness:stderr="spec: {}\n                    rollbackSteps: []\n            tags: {}\n            failureStrategies:\n                - onFailure:\n                        errors:\n                            - AllErrors\n                        action:\n                            type: StageRollback\n",
 "identifier": "testddd",
 "name": "testtt"
}

-----------------------------------------------------"
2023-01-20T11:46:46.419-0800 [WARN]  unexpected data: registry.terraform.io/harness/harness:stderr="2023-01-20 11:46:46 [DEBUG] harness-openapi-go-client harness-go-sdk API Response Details:
---[ RESPONSE ]--------------------------------------
HTTP/2.0 400 Bad Request
Content-Length: 127
Cf-Cache-Status: DYNAMIC
Cf-Ray: 78ca516f4b2d2f14-LAX
Content-Type: application/json
Date: Fri, 20 Jan 2023 19:46:46 GMT
Server: cloudflare
Set-Cookie: _cfuvid=xxx; path=/; domain=.harness.io; HttpOnly; Secure; SameSite=None
Strict-Transport-Security: max-age=15724800; includeSubDomains
Via: 1.1 google
X-Harness-Trace-Id: 5906fa840719f0125b455bbc29658472

{
 "message": "Validation Error.",
 "code": null,
 "errors": [
  {
   "field_name": "slug",
   "message": "must not be null"
  }
 ],
 "error_metadata": null
}
-----------------------------------------------------"

Panic Output

harness_platform_pipeline.example: Creating...
╷
│ Error: Validation Error.
│ 
│   with harness_platform_pipeline.example,
│   on main.tf line 1, in resource "harness_platform_pipeline" "example":
│    1: resource "harness_platform_pipeline" "example" {
│ 

Expected Behavior

The pipeline to be created

Actual Behavior

The apply fails

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. terraform apply

Important Factoids

Moving from 0.12.x to 0.13.x also wants to recreate all pipelines like they weren't even in the state

annymsMthd commented 1 year ago

Update. The breaking change was introduced in 0.13.1. 0.13.0 works

annymsMthd commented 1 year ago

I believe it might be this https://github.com/harness/terraform-provider-harness/commit/7c4b57bfa43522768ee5b529d31c294d4b705686

annymsMthd commented 1 year ago

Also had to edit my terraform so the things matched in the yaml

          name: testtt
          identifier: testddd
          allowStageExecutions: false
          projectIdentifier: pavedroads
          orgIdentifier: sre
z3z1ma commented 1 year ago

I had to re-import all of my harness_platform_pipeline resources to get the tfstate to recognize that the pipelines exist already. After doing that, everything is working as usual.

The commit posted above is suspect to what my problem was too though. 🤔