Skip to content

3152 create gitlab agents project from the module #11

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

Merged
merged 29 commits into from
Oct 22, 2024

Conversation

Stevesibilia
Copy link
Contributor

@Stevesibilia Stevesibilia commented Oct 21, 2024


PR Type

Enhancement


Description

  • Implemented the ability to create a GitLab project automatically if gitlab_project_name is set
  • Added new variables gitlab_project_name and gitlab_root_namespace for project creation and namespace specification
  • Updated main.tf to handle both existing and newly created projects
  • Modified outputs and resource references to use the new flexible project ID
  • Updated CHANGELOG.md and README.md to document the new feature and version 0.7.0
  • Improved error handling and conditions for project creation and referencing
  • Ensured backward compatibility with existing setups

Changes walkthrough 📝

Relevant files
Enhancement
main.tf
Implement GitLab project creation and flexible project referencing

main.tf

  • Added logic to create a new GitLab project if not existing
  • Introduced variables for project creation and root namespace
  • Modified resource and data source references to use the new project
  • Updated GitLab agent and token configurations to use the new project
    ID
  • +19/-5   
    outputs.tf
    Update project ID output for flexibility                                 

    outputs.tf

  • Updated the gitlab_agents_project_id output to use the new
    local.project_id
  • +1/-1     
    variables.tf
    Add new variables for project creation and root namespace

    variables.tf

  • Added new variables: gitlab_project_name and gitlab_root_namespace
  • Updated description for gitlab_project_path_with_namespace
  • +11/-0   
    Documentation
    CHANGELOG.md
    Update CHANGELOG for version 0.7.0                                             

    CHANGELOG.md

  • Added entry for version 0.7.0
  • Documented new feature to create GitLab agents project
  • +8/-0     
    README.md
    Update README with new project creation feature                   

    README.md

  • Added information about the new feature to create GitLab project
    automatically
  • Mentioned the requirement for proper permissions to create the project

  • +2/-0     

    💡 PR-Agent usage:
    Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    @sparkfabrik-ai-bot
    Copy link

    PR Reviewer Guide 🔍

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Key issues to review

    Potential Error
    The data.gitlab_group.root_namespace resource is missing a count parameter, which may cause issues when use_existing_project is 0.

    Code Duplication
    The project attribute is set multiple times using the same local.project_id value. Consider refactoring to reduce duplication.

    @sparkfabrik-ai-bot
    Copy link

    PR Code Suggestions ✨

    CategorySuggestion                                                                                                                                    Score
    Best practice
    Use boolean values instead of integers for conditional logic

    Consider using boolean values instead of 0 and 1 for better readability and to align
    with Terraform's idiomatic use of booleans for conditional logic.

    main.tf [12-13]

    -use_existing_project = var.gitlab_project_name == "" ? 1 : 0
    -project_id           = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id
    +create_new_project = var.gitlab_project_name != ""
    +project_id         = local.create_new_project ? gitlab_project.project[0].id : data.gitlab_project.this[0].id
     
    Suggestion importance[1-10]: 8

    Why: Using boolean values instead of integers aligns with Terraform best practices and improves code readability significantly.

    8
    Simplify resource creation logic by using the input variable directly in the count parameter

    Consider using the count parameter instead of the local.use_existing_project
    variable for the gitlab_project resource to improve readability and follow Terraform
    best practices.

    main.tf [32-36]

     resource "gitlab_project" "project" {
    -  count        = local.use_existing_project == 0 ? 1 : 0
    +  count        = var.gitlab_project_name != "" ? 1 : 0
       name         = var.gitlab_project_name
       namespace_id = data.gitlab_group.root_namespace.group_id
     }
     
    Suggestion importance[1-10]: 8

    Why: This suggestion simplifies the code and improves readability by directly using the input variable, adhering to Terraform best practices.

    8
    Enhancement
    Rename the variable to better reflect its purpose and simplify the conditional logic

    Consider using a more descriptive name for the use_existing_project variable. A name
    like create_new_project might be clearer, as it directly indicates the action being
    taken.

    main.tf [12-13]

    -use_existing_project = var.gitlab_project_name == "" ? 1 : 0
    -project_id           = local.use_existing_project == 1 ? data.gitlab_project.this[0].id : gitlab_project.project[0].id
    +create_new_project = var.gitlab_project_name != "" ? 1 : 0
    +project_id         = local.create_new_project == 1 ? gitlab_project.project[0].id : data.gitlab_project.this[0].id
     
    Suggestion importance[1-10]: 7

    Why: The suggestion improves code readability by using a more descriptive variable name, but the logic change might introduce subtle differences in behavior.

    7
    Maintainability
    Remove commented out code to improve maintainability

    The commented out line #group_id = data.gitlab_project.this.namespace_id in the data
    "gitlab_group" "root_namespace" block should be removed if it's no longer needed.

    main.tf [43-46]

     data "gitlab_group" "root_namespace" {
    -  #group_id = data.gitlab_project.this.namespace_id
       full_path = var.gitlab_root_namespace
     }
     
    Suggestion importance[1-10]: 6

    Why: Removing unused commented code improves maintainability, but it's a minor change that doesn't affect functionality.

    6

    @Stevesibilia Stevesibilia requested a review from Monska85 October 22, 2024 07:44
    Stevesibilia and others added 2 commits October 22, 2024 10:45
    Co-authored-by: Daniele Monti <[email protected]>
    Co-authored-by: Daniele Monti <[email protected]>
    Stevesibilia and others added 4 commits October 22, 2024 10:45
    Co-authored-by: Daniele Monti <[email protected]>
    Co-authored-by: Daniele Monti <[email protected]>
    Co-authored-by: Daniele Monti <[email protected]>
    @Stevesibilia Stevesibilia merged commit d4bc403 into main Oct 22, 2024
    1 check passed
    @Stevesibilia Stevesibilia deleted the 3152-create-gitlab-agents-project-from-the-module branch October 22, 2024 09:42
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants