When using the Anypoint Terraform Provider to import an API instance or when running `terraform plan` after generating configurations, you may encounter a plan failure. The error message indicates an issue with the `spec` attribute being `null`.
Example symptom during `terraform plan`:
```
Error: Invalid or unknown key: spec = null
```
This error typically occurs when the provider attempts to process or generate the API specification for an API instance, leading to an invalid configuration state.
CAUSE
This issue is caused by an internal bug within versions of the Anypoint Terraform Provider prior to 1.0.3. These earlier versions incorrectly handled the API specification (`spec`) during the import or configuration generation process. This led to the provider producing or interpreting a `spec = null` value, which Terraform's validation logic cannot process, resulting in a plan failure.
SOLUTION
To resolve this issue, upgrade your Anypoint Terraform Provider to version 1.0.3 or later.
1. **Upgrade Anypoint Terraform Provider:**
Ensure your Terraform configuration specifies version `1.0.3` or higher for the Anypoint Provider.
In your `versions.tf` file or within your provider block, update the required version constraint:
```terraform
terraform {
required_providers {
anypoint = {
source = "mulesoft/anypoint"
version = "~> 1.0.3" # Or specify a newer version like ">= 1.0.3"
}
}
}
```
After updating the version, run `terraform init` to download the new provider version. Then, you can proceed with `terraform plan` and `terraform apply` as usual.
2. **Workaround (if immediate upgrade is not possible):**
If you are unable to upgrade the provider immediately, you can manually import the API instances using the `terraform import` command. This method bypasses the configuration generation step that might be producing the `spec = null` error.
* For Mule APIs:
```bash
terraform import anypoint_api_instance.your_api_instance_resource_name your_organization_id/your_api_id/your_api_version_id/your_api_instance_id
```
* For Omni APIs:
```bash
terraform import anypoint_api_instance.your_omni_api_instance_resource_name your_organization_id/your_api_id/your_api_version_id/your_api_instance_id
```
Replace `your_api_instance_resource_name`, `your_organization_id`, `your_api_id`, `your_api_version_id`, and `your_api_instance_id` with the actual values corresponding to your Anypoint Platform environment.
APPLIES TO
* Anypoint Terraform Provider versions prior to 1.0.3
* Terraform CLI
005386566

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.