Files
floci/docs/getting-started/terraform.md
T
kotov228andPriamo 8765cde6dd test(terraform): expand Floci IaC compatibility coverage (#1834)
* test(terraform): expand Floci IaC compatibility coverage

* fix(terraform): use current S3 backend path style option

* fix(terraform): route ElastiCache provider calls to Floci

* fix(compat): resolve Firehose name collision, drop resources with live Floci gaps

- aws_kinesis_firehose_delivery_stream.compat collided with main's
  .events stream (both named floci-compat-firehose); renamed to
  floci-compat-firehose-basic.
- Removed aws_codebuild_project, aws_cloudtrail, and aws_opensearch_domain
  from both suites: running the suite end-to-end surfaced real Floci gaps
  behind them (BatchGetProjects ARN lookup, CloudTrail ListTags, OpenSearch
  CognitoOptions nil deref crashing the provider) that only show once
  Terraform gets past apply into the post-create refresh. Tracked as
  #2799, #2800, #2801.
- Updated test counts in README to match (70/44/2,582).

* fix(compat): force_destroy the compat bucket, drop resources with live teardown gaps

- aws_s3_bucket.app now sets force_destroy = true: the CUR report now
  actually emits into this bucket (format=Parquet finally lets the
  report definition get created), so terraform destroy needs to be
  able to clear a non-empty bucket.
- Removed aws_transfer_server: Floci's DeleteServer wrongly requires
  OFFLINE state, which isn't real AWS behavior (confirmed against the
  API reference and terraform-provider-aws's own delete logic, which
  never calls StopServer first). Tracked as #2802.
- Removed aws_batch_compute_environment: UpdateComputeEnvironment
  (called by terraform destroy to disable it first) isn't implemented
  at all, so the request falls through to an HTML error page instead
  of a modeled error. Tracked as #2803.
- Updated test counts in README to match (68/42/2,578).

* fix(compat): drop aws_api_gateway_rest_api pending Floci apiStatus fix

CI (native / compat-terraform) showed terraform apply deterministically
timing out on aws_api_gateway_rest_api: terraform-provider-aws waits for
the REST API's apiStatus field to reach AVAILABLE, and Floci never sets
it (confirmed apiStatus is a real, current field in the apigateway wire
model). Removed from both suites; tracked as #2804.

Updated test counts in README to match (67/41/2,576).

* fix(compat): drop redundant ECS containerInsights setting causing drift

CreateCluster silently drops the settings field on Floci (confirmed:
handleCreateCluster never parses req.path("settings"), unlike the
update handlers), so a subsequent plan always proposes re-adding it -
permanent drift on the suite's "re-planning reports no changes" check.
containerInsights=disabled is AWS's actual default, so the block was
functionally redundant; dropped it rather than block on a Java fix.
Tracked as #2806.

---------

Co-authored-by: Priamo <pgermosen@gmail.com>
2026-08-30 22:44:33 -04:00

145 lines
3.5 KiB
Markdown

# Terraform with Floci
Terraform can use Floci as a local AWS-compatible endpoint. Terraform sends requests through the standard `hashicorp/aws` provider, while Floci stores and emulates the resources locally. No real AWS account or cloud resources are used.
## Start Floci
```yaml title="docker-compose.yml"
services:
floci:
image: floci/floci:latest
ports:
- "4566:4566"
volumes:
- ./data:/app/data
```
```bash
docker compose up -d
```
## Configure the AWS provider
Create `provider.tf`:
```hcl
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 6.0"
}
}
}
provider "aws" {
region = "us-east-1"
access_key = "test"
secret_key = "test"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
s3_use_path_style = true
endpoints {
dynamodb = "http://localhost:4566"
secretsmanager = "http://localhost:4566"
s3 = "http://localhost:4566"
sns = "http://localhost:4566"
sqs = "http://localhost:4566"
ssm = "http://localhost:4566"
}
}
```
The endpoint must be configured for every AWS service used by the Terraform configuration. See the [services overview](../services/index.md) for the services implemented by Floci.
## Create local AWS resources
Create `main.tf`:
```hcl
resource "aws_s3_bucket" "app" {
bucket = "floci-terraform-example"
}
resource "aws_sqs_queue" "jobs" {
name = "floci-terraform-jobs"
}
resource "aws_dynamodb_table" "items" {
name = "floci-terraform-items"
billing_mode = "PAY_PER_REQUEST"
hash_key = "id"
attribute {
name = "id"
type = "S"
}
}
resource "aws_ssm_parameter" "environment" {
name = "/floci/environment"
type = "String"
value = "local"
}
```
Initialize and apply the configuration:
```bash
terraform init
terraform validate
terraform plan
terraform apply
```
Verify a resource through the AWS CLI:
```bash
aws --endpoint-url http://localhost:4566 \
s3api head-bucket --bucket floci-terraform-example
```
Remove the local resources when finished:
```bash
terraform destroy
```
## Terraform state in Floci
Terraform can keep state locally by using its default local backend. For a fully emulated AWS workflow, Floci also supports the S3 backend and DynamoDB locking used by the compatibility suite:
```hcl
terraform {
backend "s3" {
bucket = "tfstate"
key = "terraform.tfstate"
region = "us-east-1"
endpoint = "http://localhost:4566"
dynamodb_endpoint = "http://localhost:4566"
dynamodb_table = "tflock"
access_key = "test"
secret_key = "test"
skip_credentials_validation = true
skip_region_validation = true
use_path_style = true
}
}
```
Create the backend resources before running `terraform init`:
```bash
aws --endpoint-url http://localhost:4566 s3api create-bucket --bucket tfstate
aws --endpoint-url http://localhost:4566 dynamodb create-table \
--table-name tflock \
--attribute-definitions AttributeName=LockID,AttributeType=S \
--key-schema AttributeName=LockID,KeyType=HASH \
--billing-mode PAY_PER_REQUEST
```
For a complete automated example covering more services and the full lifecycle, see [`compatibility-tests/compat-terraform`](https://github.com/floci-io/floci/tree/main/compatibility-tests/compat-terraform).