-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Terraform mock-api for unittesting tf config files #6629
Comments
I think it would be a very large undertaking to mock enough of the AWS API to make this useful. The AWS provider has 500+ resources and data sources, there may be some overlap in terms of API endpoints but some resources may also use multiple endpoints. Its just a lot of surface area. I think really what may be the best way to implement this is a couple different things:
Going to close this as I think this is more of an upstream testability concern than a provider specific implementation but please comment here if you feel I am missing some aspect of the solution you describe. |
You may also be able to implement this with https://localstack.cloud/ You could use a provider config like the following: provider "aws" {
access_key = "mock_access_key"
region = "us-east-1"
s3_force_path_style = true
secret_key = "mock_secret_key"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
version = "1.59.0"
endpoints {
apigateway = "http://localhost:4567"
cloudformation = "http://localhost:4581"
cloudwatch = "http://localhost:4582"
dynamodb = "http://localhost:4569"
es = "http://localhost:4578"
iam = "http://localhost:4593"
kinesis = "http://localhost:4568"
lambda = "http://localhost:4574"
r53 = "http://localhost:4580"
s3 = "http://localhost:4572"
sns = "http://localhost:4575"
sqs = "http://localhost:4576"
ssm = "http://localhost:4583"
sts = "http://localhost:4592"
# firehose = "http://localhost:4573"
# redshift = "http://localhost:4577"
# secretsmanager = "http://localhost:4584"
# ses = "http://localhost:4579"
# stepfunctions = "http://localhost:4585"
}
} |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Description
Hi,
Having used various AWS API mockers to mimic and stub aws api responses for code developed to run in AWS, it got me thinking we could do something similar with Terraform.
An option for a dry-run or a testing framework, would let us verify our terraform code and give us a smaller feedback cycle on the terraform code we write. It would also let us potentially identify dependancies between resources prior to running our first apply.
This is by no means trivial but would give us the ability to test our terraform config files and modules prior to deploy. Also, running deployment of resources to validate code is very expensive.
Ofc, post deploy we have inspec but by the we've gone thru the pain of
terraform plan
,terraform apply
, fix failure, write a make file,make plan
,make apply
, fix failure...New or Affected Resource(s)
dry-run option / testing framework
Potential Terraform Configuration
References
Mocking api and libraries:
The text was updated successfully, but these errors were encountered: