# 操作失败：由于组织策略，访问被拒绝：constraint/compute.vmExternalIpAccess 违反了项目 <project-id>

- **ID:** `policy/gcp-org-policy-restrict-vm-external-ip`
- **领域:** policy
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

GCP 组织策略 'compute.vmExternalIpAccess' 阻止创建具有外部 IP 的 VM；该约束在组织、文件夹或项目级别强制执行。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Google Cloud SDK 450.0.0 | active | — | — |
| Compute Engine API v1 | active | — | — |
| Organization Policy Service | active | — | — |

## 解决方案

1. ```
   创建没有外部 IP 的 VM：gcloud compute instances create <instance-name> --no-address --zone=<zone>。然后使用 Cloud NAT 或堡垒主机进行出站连接。
   ```
2. ```
   向 GCP 管理员请求组织策略的例外：让他们通过组织策略控制台将你的项目添加到允许列表。
   ```
3. ```
   使用具有允许外部 IP 的代理子网的共享 VPC，然后在该子网中启动 VM，不直接分配外部 IP。
   ```

## 无效尝试

- **** — Setting VM to use an ephemeral external IP manually in gcloud still fails because the policy blocks all external IP assignment. (80% 失败率)
- **** — Removing the VM and recreating without specifying --no-address still triggers the policy if the default network has external IP. (70% 失败率)
- **** — Creating a VM in a different project without checking its policy may still fail if the organization policy applies across projects. (60% 失败率)
