Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build_counter is constantly reset #94

Open
davidhiebert opened this issue Jul 15, 2020 · 6 comments
Open

build_counter is constantly reset #94

davidhiebert opened this issue Jul 15, 2020 · 6 comments
Assignees
Labels
investigate Needs analysis

Comments

@davidhiebert
Copy link

Expected behavior

Terraform is applied, creating build configs. Builds occur periodically in TeamCity, incrementing build_counter. Consecutive terraform apply executions should not reset the build counter.

Actual behavior

Consecutive terraform apply executions attempt to reset the resource.

Attempted workaround

Tried to add the following to the resource...

  lifecycle {
    ignore_changes = [
      settings.build_counter,
    ]
  }

however settings does not have any indexes, despite the output:

> teamcity_build_config.operator_station_rtc["api"].settings
[
  {
    "allow_personal_builds" = true
    "artifact_paths" = [
      "+:*.json => /config/*.json",
    ]
    "build_counter" = 0
    "build_number_format" = "%build.counter%"
    "concurrent_limit" = 10
    "configuration_type" = "REGULAR"
    "detect_hanging" = true
    "status_widget" = false
  },
]


> teamcity_build_config.operator_station_rtc["api"].settings[0]

>
Error: Invalid index

  on <console-input> line 1:
  (source code not available)

This value does not have any indices.


> teamcity_build_config.operator_station_rtc["api"].settings["build_counter"]

>  
Error: Invalid index

  on <console-input> line 1:
  (source code not available)

This value does not have any indices.
@cvbarros
Copy link
Owner

Hi @davidhiebert, what is the configuration you're using?

{
    "allow_personal_builds" = true
    "artifact_paths" = [
      "+:*.json => /config/*.json",
    ]
    "build_counter" = 0
    "build_number_format" = "%build.counter%"
    "concurrent_limit" = 10
    "configuration_type" = "REGULAR"
    "detect_hanging" = true
    "status_widget" = false
  }

Is this your configuration source?
If yes, would you mind omitting build_counter altogether to see if this flapping behaviour still persists?
There is some special treatment for that field.

@davidhiebert
Copy link
Author

davidhiebert commented Jul 15, 2020 via email

@cvbarros
Copy link
Owner

Would you mind sharing the source configuration, and if possible, inspecting the state on the affected resource?
I think terraform show teamcity_build_config.operator_station_rtc["api"] would do the trick.

My guess here is that the build_counter is somehow in the state and it's affecting its tracking

@davidhiebert
Copy link
Author

operator_station_rtc was an artifact from my initial resource definition, and has been changed to build_config, as I'm not using for_each on multiple resources. Reduced to just the one element for clarity.

variable "web_artifact_builds" {
  type = map
  default = {
    api = {
      core_name = "web_core"
    }
  }
}

variable "web_repos" {
  type = map
  default = {
    api = {
      url = "obfuscated"
      default_branch = "develop"
    }
  }
}


resource "teamcity_vcs_root_git" "vcsroot" {
  for_each       = var.web_repos
  name           = each.key
  project_id     = teamcity_project.projects["web_artifacts"].id
  fetch_url      = each.value["url"]
  default_branch = lookup(each.value, "default_branch", "develop")

  branches = [
    "+:refs/tags/*",
    "+:refs/heads/*",
  ]
  enable_branch_spec_tags = true
  username_style          = "userid"
  submodule_checkout    = "ignore"

  # Auth block configures the authentication to Git VCS
  auth {
    type     = "ssh"
    ssh_type = "uploadedKey"
    key_spec = lookup(each.value, "key_name", "Default Key")
  }

  # Configure agent settings
  agent {
    git_path           = "/usr/bin/git"
    clean_policy       = "branch_change"
    clean_files_policy = "untracked"
    use_mirrors        = true
  }
}


resource "teamcity_build_config" "build_config" {
  for_each    = var.web_artifact_builds
  name        = each.key
  description = "Configuration to showcase build configuration settings"
  project_id  = teamcity_project.projects["web_artifacts"].id

  settings {
    # Type of build configuration: "regular" (default), "composite" or "deployment"
    configuration_type = "REGULAR"

    build_number_format = "%build.counter%"
    # build_counter = 1
    allow_personal_builds = true
    artifact_paths = ["+:*.ecr"]
    detect_hanging = true
    status_widget = false
    concurrent_limit = 10
  }

  vcs_root {
    id = teamcity_vcs_root_git.vcsroot[each.key].id
  }

  env_params = {
    vcs_core_version = "develop"
    vcs_version = "develop"
  }

  step {
...
  }
}
$ terraform state show 'teamcity_build_config.build_config["api"]'
# teamcity_build_config.build_config["api"]:
resource "teamcity_build_config" "build_config" {
    description = "Configuration to showcase build configuration settings"
    env_params  = {
        "vcs_core_version" = "develop"
        "vcs_version"      = "develop"
    }
    id          = "WebArtifacts_Api"
    is_template = false
    name        = "api"
    project_id  = "WebArtifacts"
    settings    = [
        {
            allow_personal_builds = true
            artifact_paths        = [
                "+:*.ecr",
            ]
            build_counter         = 0
            build_number_format   = "%build.counter%"
            concurrent_limit      = 10
            configuration_type    = "REGULAR"
            detect_hanging        = true
            status_widget         = false
        },
    ]
    templates   = []

    step {
...
    }
    step {
...
    }
    step {
...
    }
    step {
...
    }
}

@davidhiebert
Copy link
Author

Another resource in the for_each loop after a single build produces this abbreviated output during a terraform apply (following a TeamCity build of that build_config):

  # teamcity_build_config.build_config["dash"] will be updated in-place
  ~ resource "teamcity_build_config" "build_config" {
        description = "Configuration to showcase build configuration settings"
        env_params  = {
            "vcs_core_version" = "develop"
            "vcs_version"      = "develop"
        }
        id          = "WebArtifacts_Dash"
        is_template = false
        name        = "dash"
        project_id  = "WebArtifacts"
      ~ settings    = [
          - {
              - allow_personal_builds = true
              - artifact_paths        = [
                  - "+:*.ecr",
                ]
              - build_counter         = 1
              - build_number_format   = "%build.counter%"
              - concurrent_limit      = 10
              - configuration_type    = "REGULAR"
              - detect_hanging        = true
              - status_widget         = false
            },
            {
                allow_personal_builds = true
                artifact_paths        = [
                    "+:*.ecr",
                ]
                build_counter         = (known after apply)
                build_number_format   = "%build.counter%"
                concurrent_limit      = 10
                configuration_type    = "REGULAR"
                detect_hanging        = true
                status_widget         = false
            },
        ]
        templates   = []

@cvbarros
Copy link
Owner

@davidhiebert I still wasn't able to reproduce the problem. Due to the special treatment for build_counter, indeed there may be a nasty bug there.
Would be great if you could put together some minimal configuration in isolated state that could hint me on how to reproduce it locally so I can start working on a test case to pin it down.

@cvbarros cvbarros self-assigned this Oct 14, 2020
@cvbarros cvbarros added the investigate Needs analysis label Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Needs analysis
Projects
None yet
Development

No branches or pull requests

2 participants