Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add doc for adding new resources #123

Merged
merged 6 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 72 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,43 +15,89 @@ kubectl crossplane install provider crossplane/provider-tf-aws:v0.2.1

You can see the API reference [here](https://doc.crds.dev/github.com/crossplane-contrib/provider-tf-aws).

## Developing
## Contributing: Adding a New Resource

Run code-generation pipeline:
```console
make prepare.azurerm
go run cmd/generator/main.go
```
| Please note: the steps provided here is subject for changes since Terrajet is still alpha and does not guarantee a stabilized interface yet. |
| --- |

Run against a Kubernetes cluster:
Adding a new resource to [Terrajet](https://github.com/crossplane-contrib/terrajet)
based providers is a very straightforward process which is basically figuring
out and providing the required [custom configuration](/docs/custom-configuration.md)
for the resource.

```console
make run
```
### Steps to Follow

Build, push, and install:
1. **Include Resource:**

```console
make all
```
Add the Terraform resource name to the list of resources
(`includedResources`) in the [generator main.go](/cmd/generator/main.go).

Build image:
For example, to add [aws_iam_access_key](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_access_key)
we add [this line](https://github.com/crossplane-contrib/provider-tf-aws/blob/d2c0024f18b5760e4d2222c405ad0501c63ee0b2/cmd/generator/main.go#L108).

```console
make image
```

Push image:
2. **Create and Register Group Config File:** (if not exist)

```console
make push
```
1. Create the custom config file for the group:

Build binary:
```console
GROUP=<group-name>
RESOURCE=<terraform-resource-name>
mkdir config/$GROUP
cat << EOF > config/$GROUP/config.go
package $GROUP

```console
make build
```
import (
"github.com/crossplane-contrib/terrajet/pkg/config"
)

func init() {
config.Store.SetForResource("$RESOURCE", config.Resource{})
}
EOF
```

For `aws_iam_access_key` example:

```
GROUP=iam
RESOURCE=aws_iam_access_key
```

2. Register this custom configuration package in custom/register.go. See
[this](https://github.com/crossplane-contrib/provider-tf-aws/blob/main/config/register.go#L11)
for iam as an example.

3. **Add custom configuration** in `config/$GROUP/config.go`:

1. [Configure external name](/docs/custom-configuration.md#external-name).

2. [Cross resource referencing](/docs/custom-configuration.md#cross-resource-referencing).

3. [Configure Connection Secret Keys](/docs/custom-configuration.md#additional-sensitive-fields-and-custom-connection-details).

4. [Late initialization configuration](/docs/custom-configuration.md#late-initialization-behavior).

5. Run code-generation:

1. Run Terrajet code-generation pipeline:

```console
go run cmd/generator/main.go
```

1. Run code-generation for Controller Tools and Crossplane Tools:

```console
make generate
```

6. Run against a Kubernetes cluster:

```console
kubectl apply -f package/crds
make run
```

## Report a Bug

Expand Down
4 changes: 2 additions & 2 deletions cmd/generator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const (
"aws_kinesis_analytics_application": {},
}*/

var alphaIncludedResource = map[string]struct{}{
var includedResources = map[string]struct{}{

// VPC
"aws_vpc": {},
Expand Down Expand Up @@ -153,7 +153,7 @@ func main() { // nolint:gocyclo

groups := map[string]map[string]*schema.Resource{}
for name, resource := range aws.Provider().ResourcesMap {
if _, ok := alphaIncludedResource[name]; !ok {
if _, ok := includedResources[name]; !ok {
// Skip if not included
continue
}
Expand Down
Loading