Skip to content

Commit 721e10a

Browse files
authored
chore(examples): Add import examples for all resources (#939)
* chore(examples): Add import examples for all resources Signed-off-by: Alexander Dahmen <[email protected]> * Add guide: How to import resources Signed-off-by: Alexander Dahmen <[email protected]> --------- Signed-off-by: Alexander Dahmen <[email protected]>
1 parent e627296 commit 721e10a

File tree

118 files changed

+837
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

118 files changed

+837
-5
lines changed

docs/guides/import_resources.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
page_title: "How to import an existing resources"
3+
---
4+
# How to import an existing resources?
5+
6+
## 1. **Create a terraform config file and add an import block for your resource**
7+
8+
In order to import an existing resources in terraform you need to add an import block for the corresponding resource in a terraform config file.
9+
There is an example for every resource under the [examples](../../examples/) folder.
10+
11+
E.g. the import statement for a `stackit_volume` looks like the following:
12+
13+
```terraform
14+
import {
15+
to = stackit_volume.import-example
16+
id = "${var.project_id},${var.volume_id}"
17+
}
18+
```
19+
20+
## 2. **Generate the destination resource automatically**
21+
22+
Run `terraform plan -generate-config-out=generated.tf` to let terraform generate the configuration for you.
23+
In this step the `stackit_volume.import-example` resource is generated and filled with informations of your existing resource.
24+
25+
## 3. **Finish the import**
26+
27+
Run `terraform apply` to add your resource to the terraform state.

docs/resources/affinity_group.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ resource "stackit_affinity_group" "example" {
8787
name = "example-affinity-group-name"
8888
policy = "hard-anti-affinity"
8989
}
90+
91+
# Only use the import statement, if you want to import an existing affinity group
92+
import {
93+
to = stackit_affinity_group.import-example
94+
id = "${var.project_id},${var.affinity_group_id}"
95+
}
9096
```
9197

9298
<!-- schema generated by tfplugindocs -->

docs/resources/authorization_organization_role_assignment.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ resource "stackit_authorization_organization_role_assignment" "example" {
2121
role = "owner"
2222
subject = "[email protected]"
2323
}
24+
25+
# Only use the import statement, if you want to import an existing organization role assignment
26+
import {
27+
to = stackit_authorization_organization_role_assignment.import-example
28+
id = "${var.organization_id},${var.org_role_assignment_role},${var.org_role_assignment_subject}"
29+
}
2430
```
2531

2632
<!-- schema generated by tfplugindocs -->

docs/resources/authorization_project_role_assignment.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ resource "stackit_authorization_project_role_assignment" "example" {
2121
role = "owner"
2222
subject = "[email protected]"
2323
}
24+
25+
# Only use the import statement, if you want to import an existing project role assignment
26+
import {
27+
to = stackit_authorization_project_role_assignment.import-example
28+
id = "${var.project_id},${var.project_role_assignment_role},${var.project_role_assignment_subject}"
29+
}
2430
```
2531

2632
<!-- schema generated by tfplugindocs -->

docs/resources/cdn_custom_domain.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ resource "stackit_cdn_custom_domain" "example" {
2121
distribution_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
2222
name = "https://xxx.xxx"
2323
}
24+
25+
# Only use the import statement, if you want to import an existing cdn custom domain
26+
import {
27+
to = stackit_cdn_custom_domain.import-example
28+
id = "${var.project_id},${var.distribution_id},${var.custom_domain_name}"
29+
}
2430
```
2531

2632
<!-- schema generated by tfplugindocs -->

docs/resources/cdn_distribution.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "stackit_cdn_distribution" "example_distribution" {
2121
config = {
2222
backend = {
2323
type = "http"
24-
origin_url = "mybackend.onstackit.cloud"
24+
origin_url = "https://mybackend.onstackit.cloud"
2525
}
2626
regions = ["EU", "US", "ASIA", "AF", "SA"]
2727
blocked_countries = ["DE", "AT", "CH"]
@@ -31,6 +31,12 @@ resource "stackit_cdn_distribution" "example_distribution" {
3131
}
3232
}
3333
}
34+
35+
# Only use the import statement, if you want to import an existing cdn distribution
36+
import {
37+
to = stackit_cdn_distribution.import-example
38+
id = "${var.project_id},${var.distribution_id}"
39+
}
3440
```
3541

3642
<!-- schema generated by tfplugindocs -->

docs/resources/dns_record_set.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ resource "stackit_dns_record_set" "example" {
2121
comment = "Example comment"
2222
records = ["1.2.3.4"]
2323
}
24+
25+
# Only use the import statement, if you want to import an existing dns record set
26+
import {
27+
to = stackit_dns_record_set.import-example
28+
id = "${var.project_id},${var.zone_id},${var.record_set_id}"
29+
}
2430
```
2531

2632
<!-- schema generated by tfplugindocs -->

docs/resources/dns_zone.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ resource "stackit_dns_zone" "example" {
2323
description = "Example description"
2424
default_ttl = 1230
2525
}
26+
27+
# Only use the import statement, if you want to import an existing dns zone
28+
import {
29+
to = stackit_dns_zone.import-example
30+
id = "${var.project_id},${var.zone_id}"
31+
}
2632
```
2733

2834
<!-- schema generated by tfplugindocs -->

docs/resources/git.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ resource "stackit_git" "git" {
2929
]
3030
flavor = "git-100"
3131
}
32+
33+
# Only use the import statement, if you want to import an existing git resource
34+
import {
35+
to = stackit_git.import-example
36+
id = "${var.project_id},${var.git_instance_id}"
37+
}
3238
```
3339

3440
<!-- schema generated by tfplugindocs -->

docs/resources/image.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ resource "stackit_image" "example_image" {
2121
min_disk_size = 10
2222
min_ram = 5
2323
}
24+
25+
# Only use the import statement, if you want to import an existing image
26+
# Must set a configuration value for the local_file_path attribute as the provider has marked it as required.
27+
# Since this attribute is not fetched in general from the API call, after adding it this would replace your image resource after an terraform apply.
28+
# In order to prevent this you need to add:
29+
#lifecycle {
30+
# ignore_changes = [ local_file_path ]
31+
# }
32+
import {
33+
to = stackit_image.import-example
34+
id = "${var.project_id},${var.image_id}"
35+
}
2436
```
2537

2638
<!-- schema generated by tfplugindocs -->

0 commit comments

Comments
 (0)