---
Title: Manage authentication
URL Source: https://company-skill.com/p/terraform/terraform-manage-authentication
Language: en
Description: You want Terraform to securely authenticate with Alibaba Cloud so it can manage your infrastructure—without exposing long-term credentials or violating compliance policies. Typical User Questions:…
---

# Manage authentication

Part of **Terraform**. Route queries via `POST https://company-skill.com/api/route`.

## What You Want to Do

You want Terraform to securely authenticate with Alibaba Cloud so it can manage your infrastructure—without exposing long-term credentials or violating compliance policies.

**Typical User Questions**:
- How do I authenticate Terraform with Alibaba Cloud?
- Can I use RAM roles instead of AccessKeys for Terraform?
- What’s the secure way to handle credentials in Terraform CI/CD?

## Decision Tree

Pick the best path for your situation:

- **If** you are running Terraform in a **CI/CD pipeline or production environment** and need scriptable, repeatable authentication → Use ** Provider API ** (go to *terraform/terraform-auth*)
- **If** you manage **10+ cloud accounts** using **Alibaba Cloud Resource Directory** and require centralized audit, least-privilege access, and automatic **credential rotation** → Use ** AccessKey ** (go to *terraform/terraform-identity*)
- **If** you are doing **local development or temporary testing** and prefer GUI-based workflows like **Terraform Explorer** or quick **Plan/Apply** via console → Use ** Terraform ** (go to *terraform/terraform-iac*)
- **Otherwise (default)** → Start with ** Provider API **, as it offers explicit control and works reliably in automation.

## Path Comparison

| Path | Best For | Complexity | Code Required | Automation | Key Fact | Detail Skill |
|------|----------|------------|---------------|------------|----------|-------------|
| Provider API | AccessKeySTS Token | low | Yes | Yes | Free to use with no cost for authentication operations. | `terraform/api/terraform-auth` |
| AccessKey | high | No | Yes | STS AssumeRole requests billed at 0.0001 per request; free tier includes 1000 requests. | `terraform/guide/terraform-identity` |
| Terraform | low | No | No | Terraform Cloud free tier includes 5 workspaces and 5 users. | `terraform/guide/terraform-iac` |

## Path Details

### Path 1: Provider API 

**Best For**: AccessKeySTS Token

**Brief Description**: Configure authentication directly in the Terraform provider block using parameters like `access_key`, `secret_key`, `security_token`, `ecs_role_name`, `oidc_provider_arn`, `assume_role`, or `assume_role_with_oidc`. Alternatively, supply credentials via environment variables such as `ALICLOUD_ACCESS_KEY`. The Alibaba Cloud Terraform Provider uses a **credential chain** to select the first valid method.

**Key technical facts**:
- Billing: Free to use with no cost for authentication operations.
- Regions available: cn-hangzhou, cn-shanghai, cn-beijing

**When to Use**:
- Need explicit, code-level control over authentication method (e.g., CI/CD pipeline using environment variables).
- Developing locally and want to quickly test with temporary STS tokens or static keys without complex role setup.

**When NOT to Use**:
- Managing credentials across multiple cloud accounts where centralized rotation and audit are required (use terraform-identity path instead).
- Operating in a secure production environment where long-term static credentials must be avoided (prefer OIDC or instance roles).

**Known Limitations**:
- Hardcoding static credentials (`access_key`/`secret_key`) in code is discouraged for production due to security risks.
- Only one authentication method is used per run—the provider selects the first valid method in its credential chain, so mixing methods can cause ambiguity.

### Path 2: AccessKey 

**Brief Description**: Use **RAM role** and **ECS instance role** to grant **STS temporary token** access via the metadata service. This approach leverages **Resource Directory** for **multi-account** governance, enforces **least privilege** through **trust policy**, and uses the **AliyunSTSAssumeRoleAccess** policy to enable cross-account role assumption—all without storing long-term **access_key** pairs in code.

**Key technical facts**:
- Billing: STS AssumeRole requests are billed at 0.0001 per request; free tier includes 1000 requests.
- Auth method: ECS instance RAM role granting temporary STS tokens via metadata service.
- Prerequisites: Alibaba Cloud account with Resource Directory enabled, permissions to create IAM roles and policies, access to both operations and management accounts, Terraform installed locally or in CI/CD

**When to Use**:
- Operating in a multi-account enterprise environment requiring centralized credential governance, audit, and least-privilege access.
- Need to eliminate long-term AccessKey storage in Terraform code or state files by leveraging temporary STS tokens from ECS instance roles.

**When NOT to Use**:
- Performing quick local development or testing where setting up RAM roles and ECS instances is excessive overhead (use terraform-auth or terraform-iac paths instead).
- Lacking permissions to create RAM roles or modify Resource Directory settings in the cloud account.

**Known Limitations**:
- Requires manual console steps to create RAM roles, configure trust policies, and launch ECS instances—cannot be fully automated via this guide alone.
- STS temporary credentials are rotated every 6 hours automatically, but initial setup depends on correct console configuration of instance roles and trust relationships.

### Path 3: Terraform 

**Brief Description**: Use **Terraform Explorer** in the Alibaba Cloud console under **Console > Projects** to **Initiate Debugging**, edit configurations, and run **Plan**, **Apply**, or **Destroy Resources** via UI. Supports **VCS Integration** and lets you toggle between editing modes. Choose **Workspace Type** during project creation—but note it cannot be changed later.

**Key technical facts**:
- Billing: Terraform open-source CLI is free; Terraform Cloud free tier includes 5 workspaces and 5 users.
- Prerequisites: Terraform CLI installed, API key configured, sufficient account permissions, Git repository initialized (for remote workspaces)

**When to Use**:
- Prefer GUI-based workflows for learning Terraform or debugging configurations without writing full HCL code locally.
- Want to quickly generate, plan, and apply infrastructure using pre-built templates in Terraform Explorer for Alibaba Cloud services.

**When NOT to Use**:
- Need fully automated, scriptable authentication and deployment in CI/CD pipelines (use terraform-auth path with environment variables instead).
- Operating in regulated environments where console-based point-and-click actions are not compliant with infrastructure-as-code policies.

**Known Limitations**:
- Workspace type (Private/Shared) cannot be changed after project creation—requires recreating the project.
- Terraform Cloud free tier limits to 5 workspaces and 5 users; exceeding these requires paid subscription.

## FAQ

Q: Which path should I start with?
A: If you're unsure, start with ** Provider API **—it works in most automation scenarios and supports modern methods like **assume_role_with_oidc** and **ecs_role_name** without requiring console setup.

Q: What if I’m managing 50 cloud accounts but used the terraform-iac path?
A: You’ll hit scalability and compliance issues: **Workspace Type** is fixed per project, **Terraform Cloud free tier** limits you to 5 workspaces, and you can’t enforce centralized **credential rotation** or audit across accounts.

Q: What if I hardcoded **access_key** and **secret_key** in production using the terraform-auth path?
A: You’ll expose long-term credentials in version control or state files, violating security best practices. Instead, use **ALICLOUD_ACCESS_KEY** via environment variables or switch to **assume_role** with **RAM role**.

Q: Can I use **OIDC** authentication with the terraform-identity path?
A: Not directly—the **terraform-identity** path focuses on **ECS instance role** and **STS temporary token** via metadata service. For **OIDC**, use **terraform-auth** with **oidc_provider_arn** and **assume_role_with_oidc**.

Q: What happens if I need CI/CD automation but chose the terraform-iac path?
A: You’ll be unable to script **Plan**/**Apply** reliably because **Terraform Explorer** and **Console > Projects** are GUI-only and lack API-driven authentication—breaking infrastructure-as-code principles.

Q: Does the terraform-auth path support **security_token** for STS?
A: Yes—it accepts **security_token** alongside **access_key** and **secret_key**, and also supports **credentials_url** and **shared_credentials_file** as part of the **credential chain**.

## Related queries

configure terraform auth, terraform alibaba cloud auth, authenticate terraform, terraform access key setup, how to set alibaba cloud credentials for terraform, terraform credential management, secure terraform credentials, terraform ci/cd auth, multi-account terraform auth, terraform ram role, terra

---
Part of [Terraform](https://company-skill.com/p/terraform.md) · https://company-skill.com/llms.txt
