Skip to content

Commit

Permalink
Terraform provider for Mreg, first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindhagberg committed Mar 13, 2021
1 parent bf96c23 commit 83023d4
Show file tree
Hide file tree
Showing 23 changed files with 702 additions and 245 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ website/node_modules

website/vendor

# Terraform files that may be left after running the example
terraform-provider-mreg
.terraform*
terraform.tfstate*
crash.log
terraform-provider-mreg-lockfile

# Test exclusions
!command/test-fixtures/**/*.tfstate
!command/test-fixtures/**/.terraform/
Expand Down
30 changes: 0 additions & 30 deletions docs/data-sources/data_source.md

This file was deleted.

22 changes: 12 additions & 10 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
---
page_title: "scaffolding Provider"
page_title: "Provider: Mreg"
subcategory: ""
description: |-
The Mreg provider provides resources to interact with [Mreg](https://github.com/unioslo/mreg/) through the API.
---

# scaffolding Provider
# Mreg Provider

The Mreg provider provides resources to interact with [Mreg](https://github.com/unioslo/mreg/) through the API.

## Example usage

## Example Usage
provider "mreg" {
serverurl = "https://mreg.example.com/"
token = "1234567890ABCDEF"
}

```terraform
provider "scaffolding" {
# example configuration here
}
```
### Required configuration options

## Schema
- **serverurl** (String)
- **token** (String, Sensitive)
30 changes: 30 additions & 0 deletions docs/resources/dns_srv.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
page_title: "mreg_dns_srv Resource - terraform-provider-mreg"
subcategory: ""
description: |-
---

# Resource `mreg_dns_srv`





## Schema

### Required

- **name** (String)
- **port** (Number)
- **priority** (Number)
- **proto** (String)
- **service** (String)
- **target_host** (String)
- **weight** (Number)

### Optional

- **id** (String) The ID of this resource.


44 changes: 44 additions & 0 deletions docs/resources/hosts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
page_title: "mreg_hosts Resource - terraform-provider-mreg"
subcategory: ""
description: |-
---

# Resource `mreg_hosts`





## Schema

### Required

- **contact** (String)
- **host** (Block List, Min: 1) (see [below for nested schema](#nestedblock--host))
- **network** (String)

### Optional

- **comment** (String)
- **id** (String) The ID of this resource.

<a id="nestedblock--host"></a>
### Nested Schema for `host`

Required:

- **name** (String)

Optional:

- **manual_ipaddress** (String)

Read-only:

- **comment** (String)
- **contact** (String)
- **ipaddress** (String)


27 changes: 0 additions & 27 deletions docs/resources/resource.md

This file was deleted.

3 changes: 0 additions & 3 deletions examples/data-sources/scaffolding_data_source/data-source.tf

This file was deleted.

71 changes: 71 additions & 0 deletions examples/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
terraform {
required_providers {
mreg = {
version = "0.1.0"
source = "uio.no/usit/mreg"
}
}
}

provider "mreg" {
serverurl = "https://mreg-test01.example.com/"
token = "1234567890ABCDEF" # replace with actual token
}

resource "mreg_hosts" "my_hosts" {
# You can supply more than one host in one resource
host {
name = "terraform-provider-test01.example.com"
}
host {
name = "terraform-provider-test02.example.com"
# You can also manually pick an ip address instead of getting assigned a free one
manual_ipaddress = "192.0.2.55"
}
host {
name = "terraform-provider-test03.example.com"
}
contact = "your.email.address@example.com"
comment = "Created by the Terraform provider for Mreg"
network = "192.0.2.0/24"
}

locals {
hostnames = toset(["test01.terraform-provider-test.example.com", "test02.terraform-provider-test.example.com"])
}

resource "mreg_hosts" "loop_hosts" {
# You can loop through a set of hostnames like this
for_each = local.hostnames
host {
name = each.key
}
contact = "your.email.address@example.com"
comment = "Created by the Terraform provider for Mreg"
network = "192.0.2.0/24"
}

# Here's how to create SRV records
resource "mreg_dns_srv" "srv" {
depends_on = [mreg_hosts.loop_hosts]
for_each = local.hostnames
target_host = each.key
service = "mysql"
proto = "tcp"
name = "terraform-provider-test.example.com"
priority = 0
weight = 5
port = 3306
}

output "foo" {
value = mreg_hosts.my_hosts
}

output "bar" {
value = mreg_hosts.loop_hosts
}

output "baz" {
value = mreg_dns_srv.srv
}
3 changes: 0 additions & 3 deletions examples/provider/provider.tf

This file was deleted.

3 changes: 0 additions & 3 deletions examples/resources/scaffolding_resource/resource.tf

This file was deleted.

18 changes: 18 additions & 0 deletions examples/run_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -e
cd `dirname $0`
pushd .. >/dev/null
rm -f terraform-provider-mreg
go get -v
go build
#TODO after the provider is added to the registry, there's no need to copy the file here
rm -rf ~/.terraform.d/plugins/uio.no/usit/mreg/
mkdir -p ~/.terraform.d/plugins/uio.no/usit/mreg/0.1.0/linux_amd64
cp terraform-provider-mreg ~/.terraform.d/plugins/uio.no/usit/mreg/0.1.0/linux_amd64/
popd >/dev/null
rm -rf .terraform .terraform.lock.hcl terraform.tfstate crash.log
terraform init
terraform apply -auto-approve -parallelism=10
terraform plan -detailed-exitcode # If there's a diff, the provider is not refreshing the state correctly
terraform destroy -auto-approve
echo Everything works!
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/hashicorp/terraform-provider-scaffolding
module github.com/unioslo/terraform-provider-mreg

go 1.15

require (
github.com/hashicorp/terraform-plugin-docs v0.3.0
github.com/hashicorp/terraform-plugin-sdk/v2 v2.4.0
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1 h1:6QPYqodiu3GuPL+7mfx+NwDdp2eTkp9IfEUpgAwUN0o=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b h1:FQ7+9fxhyp82ks9vAuyPzG0/vVbWwMwLJ+P6yJI5FN8=
github.com/juju/fslock v0.0.0-20160525022230-4d5c94c67b4b/go.mod h1:HMcgvsgd0Fjj4XXDkbjdmlbI505rUPBs6WBMYg2pXks=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd h1:Coekwdh0v2wtGp9Gmz1Ze3eVRAWJMLokvN3QjdzCHLY=
github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
github.com/keybase/go-crypto v0.0.0-20161004153544-93f5b35093ba/go.mod h1:ghbZscTyKdM07+Fw3KSi0hcJm+AlEUWj8QLlPtijN/M=
Expand Down
36 changes: 0 additions & 36 deletions internal/provider/data_source_scaffolding.go

This file was deleted.

32 changes: 0 additions & 32 deletions internal/provider/data_source_scaffolding_test.go

This file was deleted.

Loading

0 comments on commit 83023d4

Please sign in to comment.