Skip to content

Commit 0eeb7ac

Browse files
authored
remove CDKTF docs post deprecation (#351)
1 parent 70307eb commit 0eeb7ac

File tree

1 file changed

+0
-279
lines changed
  • src/content/docs/aws/integrations/infrastructure-as-code

1 file changed

+0
-279
lines changed

src/content/docs/aws/integrations/infrastructure-as-code/terraform.mdx

Lines changed: 0 additions & 279 deletions
Original file line numberDiff line numberDiff line change
@@ -239,285 +239,6 @@ It will detect whether the AWS account ID is `000000000000`, which is the defaul
239239
If you use a different account ID within LocalStack, you can customize the snippet accordingly.
240240
:::
241241

242-
## CDK for Terraform
243-
244-
Cloud Development Kit for Terraform (CDKTF) allows you to use general-purpose programming languages, such as TypeScript, Python, Java, and more, to create infrastructure declaratively.
245-
It allows you to create, update, and delete AWS infrastructure by leveraging a Terraform backend without manually configuring Terraform using HCL and [AWS Cloud Development Kit](https://aws.amazon.com/cdk/) to translate your code into infrastructure configuration files for Terraform.
246-
CDKTF supports every Terraform provider and module available on the [Terraform Registry](https://registry.terraform.io/).
247-
248-
### Configuration
249-
250-
To configure your existing CDKTF configuration to work with LocalStack, manually configure the local service endpoints and credentials.
251-
It includes:
252-
253-
- General configuration to specify mock credentials for the AWS provider (`region`, `access_key`, `secret_key`).
254-
- Request Management to avoid issues with routing and authentication, if needed.
255-
- Service configuration to point the individual services to LocalStack.
256-
257-
Here is a configuration example to use with Python & TypeScript CDKTF configurations:
258-
259-
<Tabs>
260-
<TabItem label="localstack_config.py">
261-
```python showshowLineNumbers
262-
AWS_CONFIG = {
263-
"region": "us-east-1",
264-
"endpoints": [
265-
{
266-
"apigateway": "http://localhost:4566",
267-
"apigatewayv2": "http://localhost:4566",
268-
"cloudformation": "http://localhost:4566",
269-
"cloudwatch": "http://localhost:4566",
270-
"dynamodb": "http://localhost:4566",
271-
"ec2": "http://localhost:4566",
272-
"es": "http://localhost:4566",
273-
"elasticache": "http://localhost:4566",
274-
"firehose": "http://localhost:4566",
275-
"iam": "http://localhost:4566",
276-
"kinesis": "http://localhost:4566",
277-
"lambda": "http://localhost:4566",
278-
"rds": "http://localhost:4566",
279-
"redshift": "http://localhost:4566",
280-
"route53": "http://localhost:4566",
281-
"s3": "http://s3.localhost.localstack.cloud:4566",
282-
"secretsmanager": "http://localhost:4566",
283-
"ses": "http://localhost:4566",
284-
"sns": "http://localhost:4566",
285-
"sqs": "http://localhost:4566",
286-
"ssm": "http://localhost:4566",
287-
"stepfunctions": "http://localhost:4566",
288-
"sts": "http://localhost:4566",
289-
}
290-
],
291-
}
292-
```
293-
</TabItem>
294-
<TabItem label="localstack_config.ts">
295-
```javascript showshowLineNumbers
296-
export const AWS_CONFIG = {
297-
region: "us-east-1",
298-
endpoints: [
299-
{
300-
apigateway: "http://localhost:4566",
301-
apigatewayv2: "http://localhost:4566",
302-
cloudformation: "http://localhost:4566",
303-
cloudwatch: "http://localhost:4566",
304-
dynamodb: "http://localhost:4566",
305-
ec2: "http://localhost:4566",
306-
es: "http://localhost:4566",
307-
elasticache: "http://localhost:4566",
308-
firehose: "http://localhost:4566",
309-
iam: "http://localhost:4566",
310-
kinesis: "http://localhost:4566",
311-
lambda: "http://localhost:4566",
312-
rds: "http://localhost:4566",
313-
redshift: "http://localhost:4566",
314-
route53: "http://localhost:4566",
315-
s3: "http://s3.localhost.localstack.cloud:4566",
316-
secretsmanager: "http://localhost:4566",
317-
ses: "http://localhost:4566",
318-
sns: "http://localhost:4566",
319-
sqs: "http://localhost:4566",
320-
ssm: "http://localhost:4566",
321-
stepfunctions: "http://localhost:4566",
322-
sts: "http://localhost:4566",
323-
},
324-
],
325-
};
326-
```
327-
</TabItem>
328-
</Tabs>
329-
330-
You can further import the above configuration in your project's code, and use it to configure the AWS provider:
331-
332-
<Tabs>
333-
<TabItem label="main.py">
334-
```python showshowLineNumbers
335-
...
336-
from localstack_config import AWS_CONFIG
337-
...
338-
AwsProvider(self, "Aws", **AWS_CONFIG)
339-
...
340-
```
341-
</TabItem>
342-
<TabItem label="main.ts">
343-
```javascript showshowLineNumbers
344-
...
345-
import { AWS_CONFIG } from "./localstack-config";
346-
...
347-
new AwsProvider(this, "aws", AWS_CONFIG);
348-
...
349-
```
350-
</TabItem>
351-
</Tabs>
352-
353-
### Getting started
354-
355-
To get started with CDKTF on LocalStack, we will set up a simple stack to create some AWS resources.
356-
We will then deploy the stack to LocalStack, and verify that the resources have been created successfully.
357-
Before we start, make sure you have the following prerequisites:
358-
359-
- LocalStack
360-
- [`cdktf`](https://www.npmjs.com/package/cdktf)
361-
362-
For Python:
363-
364-
- [`python`](https://www.python.org/downloads/)
365-
- [`pipenv`](https://pipenv.pypa.io/en/latest/installation.html#installing-pipenv)
366-
367-
For TypeScript:
368-
369-
- [`tsc`](https://www.npmjs.com/package/typescript)
370-
371-
Create a new directory named `cdktf-localstack` and initialize a new CDKTF project using the following command:
372-
373-
<Tabs>
374-
<TabItem label="Python">
375-
```python showshowLineNumbers
376-
cdktf init
377-
...
378-
? Do you want to continue with Terraform Cloud remote state management? No
379-
? What template do you want to use? python
380-
381-
Initializing a project using the python template.
382-
? Project Name sample-app
383-
? Project Description A simple getting started project for cdktf.
384-
? Do you want to start from an existing Terraform project? No
385-
? Do you want to send crash reports to the CDKTF team? Refer to https://developer.hashicorp.com/terraform/cdktf/create-and-deploy/configuration-file#enable-crash-reporting-for-the-cli for more information no
386-
Note: You can always add providers using 'cdktf provider add' later on
387-
? What providers do you want to use? aws
388-
...
389-
```
390-
</TabItem>
391-
<TabItem label="TypeScript">
392-
```javascript showshowLineNumbers
393-
cdktf init
394-
...
395-
? Do you want to continue with Terraform Cloud remote state management? No
396-
? What template do you want to use? typescript
397-
398-
Initializing a project using the typescript template.
399-
? Project Name sample-app
400-
? Project Description A simple getting started project for cdktf.
401-
? Do you want to start from an existing Terraform project? No
402-
? Do you want to send crash reports to the CDKTF team? Refer to https://developer.hashicorp.com/terraform/cdktf/create-and-deploy/configuration-file#enable-crash-reporting-for-the-cli for more information no
403-
Note: You can always add providers using 'cdktf provider add' later on
404-
? What providers do you want to use? aws
405-
...
406-
```
407-
</TabItem>
408-
</Tabs>
409-
410-
(Optional) If necessary, we can install the AWS provider separately for CDKTF, by running the following command:
411-
412-
<Tabs>
413-
<TabItem label="Python">
414-
```python
415-
pipenv install cdktf-cdktf-provider-aws
416-
```
417-
</TabItem>
418-
<TabItem label="TypeScript">
419-
```javascript
420-
npm install @cdktf/provider-aws
421-
```
422-
</TabItem>
423-
</Tabs>
424-
425-
Add the following code to import the AWS provider and create a new S3 bucket in the relevant file:
426-
427-
<Tabs>
428-
<TabItem label="main.py">
429-
```python showshowLineNumbers
430-
# !/usr/bin/env python
431-
432-
from constructs import Construct
433-
from cdktf import App, TerraformStack
434-
from cdktf_cdktf_provider_aws.provider import AwsProvider
435-
from cdktf_cdktf_provider_aws.s3_bucket import S3Bucket
436-
437-
class MyStack(TerraformStack):
438-
def **init**(self, scope: Construct, id: str):
439-
super().**init**(scope, id)
440-
441-
AwsProvider(self, "aws",
442-
region="us-east-1",
443-
s3_use_path_style=True,
444-
endpoints=[
445-
{
446-
"s3": "http://localhost:4566",
447-
"sts": "http://localhost:4566",
448-
}
449-
]
450-
)
451-
452-
S3Bucket(self, "bucket")
453-
454-
app = App()
455-
MyStack(app, "cdktf-example-python")
456-
457-
app.synth()
458-
```
459-
</TabItem>
460-
<TabItem label="main.ts">
461-
```javascript showshowLineNumbers
462-
import { Construct } from "constructs";
463-
import { App, TerraformStack } from "cdktf";
464-
import { AwsProvider } from "@cdktf/provider-aws/lib/provider";
465-
import {S3Bucket} from "@cdktf/provider-aws/lib/s3-bucket";
466-
467-
class MyStack extends TerraformStack {
468-
constructor(scope: Construct, id: string) {
469-
super(scope, id);
470-
471-
new AwsProvider(this, "aws",{
472-
region: "us-east-1",
473-
s3UsePathStyle: true,
474-
endpoints: [
475-
{
476-
s3: "http://localhost:4566",
477-
sts: "http://localhost:4566"
478-
},
479-
],
480-
});
481-
482-
new S3Bucket(this, "bucket", {});
483-
}
484-
}
485-
486-
const app = new App();
487-
new MyStack(app, "example");
488-
app.synth();
489-
```
490-
</TabItem>
491-
</Tabs>
492-
493-
Run the following command to compile and deploy the CDKTF stack to LocalStack:
494-
495-
```bash
496-
cdktf synth && cdktf deploy
497-
```
498-
499-
You should see the following output:
500-
501-
```sh showshowLineNumbers
502-
example Initializing the backend...
503-
example
504-
Successfully configured the backend "local"! Terraform will automatically
505-
use this backend unless the backend configuration changes.
506-
...
507-
example aws_s3_bucket.bucket (bucket): Creating...
508-
example aws_s3_bucket.bucket (bucket): Creation complete after 5s [id=terraform-20230418074657926600000001]
509-
example
510-
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
511-
```
512-
513-
Verify that the S3 bucket has been created successfully by running the following command:
514-
515-
```bash
516-
awslocal s3 ls
517-
```
518-
519-
Your CDKTF stack is now successfully deployed to LocalStack. You can now start using CDKTF to create and manage your AWS resources on LocalStack.
520-
521242
## OpenTofu
522243

523244
OpenTofu is an open-source fork of Terraform acting as a drop-in replacement for Terraform, as it's compatible with Terraform versions 1.5.x and most of 1.6.x. You can use OpenTofu with LocalStack to create and manage your AWS resources with your pre-existing Terraform configurations. You can use the `TF_CMD` environment variable with `tflocal` to specify the `tofu` binary to call, or setup a manual configuration to point the individual services to LocalStack.

0 commit comments

Comments
 (0)