Every new Anypoint environment starts the same way: log into Anypoint Platform, navigate to Access Management, click “Environments,” fill out the form, wait for validation, then repeat for the next business group. Platform teams spend hours each week manually provisioning sandbox and production environments, copying configurations, and ensuring consistency across deployments. What if you could declare your entire Anypoint infrastructure as code and let Terraform handle the rest?
The MuleSoft Terraform Provider brings Infrastructure-as-Code (IaC) principles to Anypoint Platform. Currently in Customer Zero validation with MuleSoft engineering teams, the provider allows you to manage environments, flex gateways, API instances, and more through declarative Terraform configurations. This means version-controlled infrastructure, peer-reviewed changes, and automated provisioning workflows—all the benefits of GitOps applied to your integration platform.
In this tutorial, you’ll learn how to use the MuleSoft Terraform Provider to create sandbox and production environments in minutes instead of hours.
What is the MuleSoft Terraform Provider?
The MuleSoft Terraform Provider is a Terraform plugin that translates infrastructure declarations into Anypoint Platform API calls. Instead of clicking through the UI or writing custom scripts, you define your desired state in .tf files, and Terraform orchestrates the creation, updates, and deletion of resources.
Key capabilities
With the MuleSoft Terraform Provider, you can:
- Manage environments across multiple business groups with consistent naming and configuration
- Provision flex gateways with standardized policies and deployment targets
- Deploy API instances with policies pre-applied and SLA tiers configured
- Track infrastructure state in version control, enabling rollback and audit trails
- Automate provisioning through CI/CD pipelines, reducing manual toil
How it works
At its core, the provider acts as a bridge between Terraform’s declarative syntax and Anypoint Platform’s REST APIs. When you run terraform apply, the provider:
- Authenticates with Anypoint Platform using your credentials
- Translates resource declarations (e.g., anypoint_environment) into API requests
- Creates or updates resources via the Anypoint Platform API
- Stores resource metadata (IDs, names, attributes) in Terraform state
- Provides output values for use in other configurations or systems
This approach ensures that your Anypoint infrastructure is repeatable, versioned, and auditable—just like application code.
Architecture overview
The provider follows Terraform’s standard plugin architecture:

The provider handles authentication, API request construction, error handling, and state management. You focus on declaring what you want; Terraform and the provider figure out how to achieve it.
Tutorial: Provisioning Anypoint Environments With Terraform
In this hands-on tutorial, you’ll use the MuleSoft Terraform Provider to create two environments in an Anypoint business group: a sandbox environment for development and a production environment for live integrations.
Prerequisites
Before you begin, ensure you have:
- Terraform 1.0+ installed (installation guide)
- MuleSoft Terraform documentation
- Anypoint Platform account with Organization Administrator permissions
- Connected App credentials (client ID, client secret, username, password)
- Note: The provider currently requires password grant (App1) authentication; client credentials alone will return “username is required”
- Organization ID for your target business group
- Basic familiarity with Terraform workflows (init, plan, apply)
Tip: You can find your Organization ID in Anypoint Platform under Access Management > Organization > Business Groups.
Step 1: Create the provider configuration
First, create a new directory for your Terraform project:

Create a main.tf file with the provider configuration:

What this does:
- Declares the MuleSoft Terraform provider with version 0.1.0 (Customer Zero release)
- Configures authentication using variables (values defined in the next step)
- Sets the base_url to support both production and staging Anypoint environments
Step 2: Define variables for credentials
Create a variables.tf file to externalize configuration values:

Security note: Mark client_secret and password as sensitive = true to prevent Terraform from displaying these values in logs or console output in terminal.
Step 3: Create a terraform.tfvars file
Create a terraform.tfvars file with your actual credentials (this file should be .gitignore’d):

⚠️ Important: Never commit terraform.tfvars to version control. Add it to .gitignore:

Step 4: Define environment resources
Add environment resource declarations to main.tf:

What this does:
- Declares two anypoint_environment resources: one sandbox, one production
- Sets type to match the environment’s purpose (sandbox or production)
- Sets is_production to control production-level restrictions (e.g., deployment policies)
Note: The type field determines how the environment appears in Anypoint Platform, while is_production controls platform-level governance features.
Step 5: Define outputs
Add an outputs.tf file to expose environment IDs and names:

These outputs can be referenced by other Terraform configurations or CI/CD pipelines (e.g., to deploy Mule applications to the newly created environments).
Step 6: Initialize Terraform
Run terraform init to download the MuleSoft Terraform provider plugin:

Expected output:

Step 7: Preview the changes with terraform plan
Run terraform plan to see what Terraform will create:

Expected output:

This preview shows that Terraform will create two new environments. The id field will be populated after creation.
Step 8: Apply the configuration
Run terraform apply to create the environments:

Terraform will prompt for confirmation:

Type yes and press Enter.
Expected output:

In about 5 seconds, Terraform created both environments. What used to require multiple UI workflows now happens with a single command.
Step 9: Verify the environments in Anypoint Platform
Now, verify that the environments were created correctly:
Method 1: Anypoint Platform UI
- Log into Anypoint Platform
- Navigate to Access Management > Environments
- You should see both dev-sandbox and prod environments listed
Note: You may see additional default environments (Design, Sandbox) that exist in every organization. Focus on the two you just created: dev-sandbox and prod.
Method 2: Terraform state inspection
Run terraform show to inspect the current state:

This displays the full state of all managed resources, including their IDs, names, and attributes.
Method 3: Anypoint CLI (optional)
If you have the Anypoint CLI installed, you can verify via command line:

You should see both environments in the output.
Step 10: Test infrastructure immutability with terraform plan
Run terraform plan again (without making any changes):

Expected output:

This confirms that your Terraform state matches the actual state in Anypoint Platform. If someone manually changed an environment name in the UI, Terraform would detect the drift and offer to correct it.
Updating infrastructure: Renaming an environment
Let’s demonstrate in-place updates by renaming the sandbox environment.
Edit terraform.tfvars and change the sandbox_name:

Run terraform plan:

Expected output:

Notice the ~ symbol indicating an in-place update. The provider will send a PATCH request to rename the environment without destroying and recreating it.
Run terraform apply:

Expected output:

The environment was renamed in 2 seconds, and the resource ID remained unchanged. No downtime, no manual intervention.
Cleaning up: Destroying resources
When you’re done with the tutorial, clean up the resources:

Terraform will prompt for confirmation:

Type yes and press Enter.
Expected output:

Both environments are deleted from Anypoint Platform, and the Terraform state is cleared.
Infrastructure-as-Code for Anypoint Platform
By treating your Anypoint infrastructure as code, you unlock version control, peer review, and automated provisioning workflows. What used to take hours of manual clicking now happens in seconds with terraform apply. Your platform team can provision consistent environments across business groups, track changes in Git, and enforce standards through automated pipelines.
This tutorial covered the basics: creating, updating, and destroying environments. The MuleSoft Terraform Provider also supports Omni gateways, API / MCP / Agents instances, policies, and more—enabling end-to-end automation of your Anypoint Platform infrastructure.
Ready to get started?
- Learn the fundamentals: Terraform Introduction
- Try Anypoint Platform: 30-day free trial
- Explore the provider: MuleSoft Terraform Provider documentation
- MuleSoft Documentation reference: documentation




