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

Commit

Permalink
Link to configuring a resource doc
Browse files Browse the repository at this point in the history
Signed-off-by: Hasan Turken <turkenh@gmail.com>
  • Loading branch information
turkenh committed Nov 5, 2021
1 parent 57a9913 commit b8c4612
Showing 1 changed file with 35 additions and 19 deletions.
54 changes: 35 additions & 19 deletions docs/generating-a-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ be quite similar for any other Terraform provider.

1. Export `ProviderName`:

```console
```bash
export ProviderNameLower=github
export ProviderNameUpper=GitHub
```

2. Replace all occurrences of `template` with your provider name:

```console
```bash
git grep -l 'template' -- './*' ':!build/**' ':!go.sum' | xargs sed -i.bak "s/template/${ProviderNameLower}/g"
git grep -l 'Template' -- './*' ':!build/**' ':!go.sum' | xargs sed -i.bak "s/Template/${ProviderNameUpper}/g"
# Clean up the .bak files created by sed
Expand Down Expand Up @@ -65,7 +65,7 @@ be quite similar for any other Terraform provider.
```

Run:
```
```bash
go mod tidy
```

Expand All @@ -91,7 +91,7 @@ be quite similar for any other Terraform provider.
```

Run:
```
```bash
go mod tidy
```

Expand Down Expand Up @@ -150,37 +150,47 @@ be quite similar for any other Terraform provider.
7. Finally, we would need to add some custom configurations for these two
resources as follows:
```console
```bash
# Create custom configuration directory for whole repository group
mkdir config/repository
# Create custom configuration directory for whole branch group
mkdir config/branch
```
```console
```bash
cat <<EOF > config/repository/config.go
package repository
import "github.com/crossplane-contrib/terrajet/pkg/config"
func Customize(p *config.Provider) {
p.AddResourceConfigurator("github_repository", func(r *config.Resource) {
// we need to override the default group that terrajet generated for
// this resource, which would be "github"
r.Group = "repository"
})
}
EOF
```
```console
```bash
cat <<EOF > config/branch/config.go
package branch
import "github.com/crossplane-contrib/terrajet/pkg/config"
func Customize(p *config.Provider) {
p.AddResourceConfigurator("github_branch", func(r *config.Resource) {
// we need to override the default group that terrajet generated for
// this resource, which would be "github"
r.Group = "branch"
// Identifier for this resource is assigned by the provider. In other
// words it is not simply the name of the resource.
r.ExternalName = config.IdentifierFromProvider
// This resource need the repository in which branch would be created
// as an input. And by defining it as a reference to Repository
// object, we can build cross resource referencing. See
// repositoryRef in the example in Testing section below.
r.References["repository"] = config.Reference{
Type: "github.com/crossplane-contrib/provider-tf-github/apis/repository/v1alpha1.Repository",
}
Expand Down Expand Up @@ -213,12 +223,18 @@ be quite similar for any other Terraform provider.
}
```
_**To learn more about custom resource configurations (in step 7), please see
the [Configuring a Resource](/docs/configuring-a-resource.md) document._**
8. Now we can generate our Terrajet Provider:
```console
```bash
make generate
```
**_To add more resources, please follow the steps between 6-8 for each resource._**
## Test
Now let's test our generated resources.
Expand All @@ -227,7 +243,7 @@ Now let's test our generated resources.
Create example directories for repository and branch groups:
```console
```bash
mkdir examples/repository
mkdir examples/branch
Expand All @@ -237,7 +253,7 @@ Now let's test our generated resources.
Create a provider secret template:
```console
```bash
cat <<EOF > examples/providerconfig/secret.yaml.tmpl
apiVersion: v1
kind: Secret
Expand All @@ -257,7 +273,7 @@ Now let's test our generated resources.
`provider-tf-template` repo as template for the repository
to be created:
```console
```bash
cat <<EOF > examples/repository/repository.yaml
apiVersion: repository.github.tf.crossplane.io/v1alpha1
kind: Repository
Expand All @@ -278,7 +294,7 @@ Now let's test our generated resources.
Create `branch` resource which refers to the above repository
managed resource:
```console
```bash
cat <<EOF > examples/branch/branch.yaml
apiVersion: branch.github.tf.crossplane.io/v1alpha1
kind: Branch
Expand All @@ -300,27 +316,27 @@ Now let's test our generated resources.
3. Create `examples/providerconfig/secret.yaml` from
`examples/providerconfig/secret.yaml.tmpl` and set your token in the file:
```console
```bash
GITHUB_TOKEN=<your-token-here>
cat examples/providerconfig/secret.yaml.tmpl | sed -e "s/y0ur-t0k3n/${GITHUB_TOKEN}/g" > examples/providerconfig/secret.yaml
```
4. Apply CRDs:
```console
```bash
kubectl apply -f package/crds
```
5. Run the provider:
```console
```bash
make run
```
6. Apply ProviderConfig and example manifests (_In another terminal since
the previous command is blocking_):
```console
```bash
# Create "crossplane-system" namespace if not exists
kubectl create namespace crossplane-system --dry-run=client -o yaml | kubectl apply -f -
Expand All @@ -331,11 +347,11 @@ Now let's test our generated resources.
7. Observe managed resources and wait until they are ready:
```console
```bash
watch kubectl get managed
```
```console
```bash
NAME READY SYNCED EXTERNAL-NAME AGE
branch.branch.github.tf.crossplane.io/hello-terrajet True True hello-crossplane:hello-terrajet 89s
Expand All @@ -349,7 +365,7 @@ Now let's test our generated resources.
9. Cleanup
```console
```bash
kubectl delete -f examples/branch/branch.yaml
kubectl delete -f examples/repository/repository.yaml
```
Expand Down

0 comments on commit b8c4612

Please sign in to comment.