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

Fix terraform action >=1.11.0 #1418

Merged
merged 10 commits into from
Mar 12, 2025
Merged

Fix terraform action >=1.11.0 #1418

merged 10 commits into from
Mar 12, 2025

Conversation

bengtfredh
Copy link
Member

@bengtfredh bengtfredh commented Mar 11, 2025

Description

Adding subscription_id to backend config fixes issues with terraform >=1.11.0

Related Issue(s)

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

Summary by CodeRabbit

  • New Features

    • Improved backend configuration by explicitly setting the cloud subscription details during initialization.
  • Chores

    • Streamlined the deployment process by updating configuration expressions for consistency.

Copy link
Contributor

coderabbitai bot commented Mar 11, 2025

📝 Walkthrough

Walkthrough

This pull request modifies the backend configuration for the Terraform workflow in two action files. Specifically, it changes the source of the Azure subscription ID from an environment variable to an input parameter in both the apply and plan actions. This adjustment alters how the subscription ID is provided during the Terraform initialization process.

Changes

File(s) Change Summary
actions/terraform/apply/action.yaml Updated backend configuration syntax for subscription_id from ${{ env.ARM_SUBSCRIPTION_ID }} to ${{ inputs.tf_arm_subscription_id }}.
actions/terraform/plan/action.yaml Updated backend configuration syntax for subscription_id from ${{ env.ARM_SUBSCRIPTION_ID }} to ${{ inputs.tf_arm_subscription_id }}.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as GitHub Actions Runner
    participant Workflow as CI Workflow
    participant TF as Terraform CLI
    participant Azure as Azure Backend

    Runner->>Workflow: Trigger Terraform Workflow (Plan/Apply)
    Workflow->>TF: Run 'terraform init' with backend-config (subscription_id)
    TF->>Azure: Connect using provided backend configuration
Loading

Possibly related PRs

Suggested reviewers

  • monteiro-renato

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7e52c48 and ddfb122.

📒 Files selected for processing (12)
  • actions/terraform/apply/action.yaml (0 hunks)
  • actions/terraform/plan/action.yaml (0 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/apply/action.yaml (1 hunks)
  • actions/terraform/apply/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (12)
  • actions/terraform/plan/action.yaml
  • actions/terraform/plan/action.yaml
  • actions/terraform/apply/action.yaml
  • actions/terraform/plan/action.yaml
  • actions/terraform/plan/action.yaml
  • actions/terraform/plan/action.yaml
  • actions/terraform/apply/action.yaml
  • actions/terraform/apply/action.yaml
  • actions/terraform/plan/action.yaml
  • actions/terraform/plan/action.yaml
  • actions/terraform/plan/action.yaml
  • actions/terraform/plan/action.yaml
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
actions/terraform/apply/action.yaml (1)

90-96: Documentation Suggestion:
Consider adding an inline comment above these backend configuration lines explaining why these additional parameters are now required. This will aid future maintainers in understanding the context behind supporting Terraform versions >=1.11.0.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df6ff2b and 7e52c48.

📒 Files selected for processing (10)
  • actions/terraform/apply/action.yaml (0 hunks)
  • actions/terraform/plan/action.yaml (0 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/plan/action.yaml (1 hunks)
  • actions/terraform/apply/action.yaml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (3)
actions/terraform/apply/action.yaml (1)

90-96: Enhance backend configuration for Terraform Init.
The addition of the backend configuration options
-backend-config="subscription_id=${{ env.ARM_SUBSCRIPTION_ID }}" and
-backend-config="resource_group_name=${{ inputs.tf_arm_resource_group_name }}"
ensures that Terraform (v>=1.11.0) properly associates with the correct Azure subscription and resource group. This change improves compatibility with newer Terraform versions by explicitly passing the subscription ID and resource group name. Please verify that the environment variable ARM_SUBSCRIPTION_ID (sourced from inputs.tf_arm_subscription_id) is consistently set across all workflow steps.

actions/terraform/plan/action.yaml (2)

100-104: Standardize Terraform Init backend configuration.
The updated lines now reference the subscription ID using ${{ env.ARM_SUBSCRIPTION_ID }} and explicitly pass the resource group name via
-backend-config="resource_group_name=${{ inputs.tf_arm_resource_group_name }}". These changes mirror those in the apply workflow, ensuring consistency in how Terraform accesses the Azure backend. Please confirm that these variable references correctly resolve during workflow execution.


90-97: Verify Authentication Strategy Post-Azure Login Removal.
With the removal of the dedicated Azure login step and the use of ARM_USE_OIDC: "true", double-check that the OIDC-based authentication and the provided environment variables supply sufficient credentials for Terraform operations.

Copy link

github-actions bot commented Mar 11, 2025

Terraform environment test

Format and Style 🖌success

Initialization ⚙️success

Validation 🤖success

Validation Output

Success! The configuration is valid.


Plan 📖success

Show Plan

[Lines containing Refreshing state removed]
[Truncated to 120000 bytes! See logoutput for complete plan]
Acquiring state lock. This may take a few moments...
data.azurerm_container_registry.altinncr: Reading...
data.azurerm_container_registry.altinncr: Read complete after 0s [id=/subscriptions/a6e9ee7d-2b65-41e1-adfb-0c8c23515cf9/resourceGroups/acr/providers/Microsoft.ContainerRegistry/registries/altinncr]

Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place

Terraform will perform the following actions:

  # azurerm_kubernetes_cluster.aks will be updated in-place
  ~ resource "azurerm_kubernetes_cluster" "aks" {
        id                                  = "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/admin-test-rg/providers/Microsoft.ContainerService/managedClusters/admin-test-aks"
      ~ kubernetes_version                  = "1.30.9" -> "1.30"
        name                                = "admin-test-aks"
        tags                                = {}
        # (34 unchanged attributes hidden)

      ~ default_node_pool {
            name                          = "syspool"
          ~ orchestrator_version          = "1.30.9" -> "1.30"
            tags                          = {}
            # (29 unchanged attributes hidden)

            # (1 unchanged block hidden)
        }

        # (8 unchanged blocks hidden)
    }

  # azurerm_kubernetes_cluster_node_pool.workpool will be updated in-place
  ~ resource "azurerm_kubernetes_cluster_node_pool" "workpool" {
        id                            = "/subscriptions/1ce8e9af-c2d6-44e7-9c5e-099a308056fe/resourceGroups/admin-test-rg/providers/Microsoft.ContainerService/managedClusters/admin-test-aks/agentPools/workpool"
        name                          = "workpool"
      ~ orchestrator_version          = "1.30.9" -> "1.30"
        tags                          = {}
        # (30 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

Plan: 0 to add, 2 to change, 0 to destroy.

─────────────────────────────────────────────────────────────────────────────

Saved the plan to: tfplan.out

To perform exactly these actions, run the following command to apply:
    terraform apply "tfplan.out"
Releasing state lock. This may take a few moments...

Context Values
Pusher @bengtfredh
Action push
Working Directory ./infrastructure/adminservices-test/admin-test-aks-rg
State File github.com/altinn/altinn-platform/environments/test/admin-test-aks-rg.tfstate
Plan File github.com_altinn_altinn-platform_environments_test_admin-test-aks-rg.tfstate.tfplan

Copy link
Member

@tjololo tjololo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:godmode:

@bengtfredh bengtfredh merged commit 04e272e into main Mar 12, 2025
6 of 11 checks passed
@bengtfredh bengtfredh deleted the fix-terraform-action branch March 12, 2025 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terraform github actions fail with terraform >=1.11.0
2 participants