Skip to content

Commit

Permalink
Merge branch 'main' into release-0.8
Browse files Browse the repository at this point in the history
  • Loading branch information
skorfmann committed Nov 30, 2021
2 parents 24b37c6 + 7e0697c commit 4f93c07
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@cdktf/provider-generator/lib/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ describe("parseConfig", () => {
"output": "cdktf.out",
"terraformModules": Array [
TerraformModuleConstraint {
"fqn": "app.terraform.io/example-corp/k8s-cluster/azurerm",
"fqn": "app-terraform-io/example-corp/k8s-cluster/azurerm",
"name": "k8s-cluster",
"namespace": "example-corp/azurerm",
"source": "app.terraform.io/example-corp/k8s-cluster/azurerm",
Expand Down
2 changes: 1 addition & 1 deletion packages/@cdktf/provider-generator/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export class TerraformModuleConstraint
source,
version,
namespace,
fqn: source.replace("//", "/"),
fqn: source.replace("//", "/").replace(/\./g, "-"),
};
}

Expand Down
26 changes: 26 additions & 0 deletions website/docs/cdktf/concepts/providers-and-resources.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,32 @@ You can instantiate the same resource multiple times throughout your infrastruct

Refer to the [constructs documentation](/docs/cdktf/concepts/constructs.html#scope) for more details and an example.

### References

You can reference resource properties throughout your configuration. For example, you may want to use the name of a parent resource when assigning names to related child resources. Refer to your provider's documentation for a full list of available properties for each resource type.

To create references, call `myResource.<propertyName>` on the resource instance. For example, you could use `myResource.name` to retrieve the `name` property from `myResource`. Terraform does not support passing an entire block (e.g. `exampleNamespace.metadata`) into a resource or data source, so you must create a reference for each individual property.

References are also useful when you need to track logical dependencies. For example, Kubernetes resources live in a namespace, so a namespace must exist before Terraform can provision the associated resources. The TypeScript example below uses a reference for the namespace property in the the deployment. This reference tells Terraform that it needs to create the namespace before creating the resources.

```ts

const exampleNamespace = new Namespace(this, "tf-cdk-example", {
metadata: {
name: "tf-cdk-example",
},
});

new Deployment(this, "nginx-deployment", {
metadata: {
name: "nginx",
namespace: exampleNamespace.metadata.name, // Reference the namespace name propery
labels: {
app,
},
});
```
### Escape Hatch
Terraform provides [meta-arguments](https://www.terraform.io/docs/language/resources/syntax.html#meta-arguments) to change resource behavior. For example, the `for_each` meta-argument creates multiple resource instances according to a map, or set of strings. The escape hatch allows you to use these meta-arguments to your CDKTF application and to override attributes that CDKTF cannot yet fully express.
Expand Down

0 comments on commit 4f93c07

Please sign in to comment.