Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for infrastructure stacks #32

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
0b81d26
start adding model
maciaszczykm Apr 19, 2024
7dfb6d4
complete model struct
maciaszczykm Apr 19, 2024
029c2b5
start mapping from create
maciaszczykm Apr 19, 2024
9cec9fc
start adding attributes
maciaszczykm Apr 19, 2024
e02339b
refactor bidings
maciaszczykm Apr 19, 2024
b40ffe8
start adding resource
maciaszczykm Apr 19, 2024
c29636d
update schema
maciaszczykm Apr 19, 2024
d01e0f5
update schema
maciaszczykm Apr 22, 2024
b3f8556
update client
maciaszczykm Apr 22, 2024
f130903
finish schema
maciaszczykm Apr 22, 2024
ffb948c
add example
maciaszczykm Apr 22, 2024
6f00507
adjust types
maciaszczykm Apr 22, 2024
1b006ac
fix types
maciaszczykm Apr 22, 2024
9cec940
generate docs
maciaszczykm Apr 22, 2024
d5b3242
update attributes
maciaszczykm Apr 22, 2024
babc90d
update attributes
maciaszczykm Apr 22, 2024
e7b4725
do not run checks twice in pull requests
maciaszczykm Apr 22, 2024
b40fd9d
update attributes
maciaszczykm Apr 22, 2024
760595a
update attributes
maciaszczykm Apr 22, 2024
5140648
update attributes
maciaszczykm Apr 22, 2024
1f6f8d2
update from
maciaszczykm Apr 22, 2024
5c9c4e0
update from
maciaszczykm Apr 22, 2024
4de3c52
update attributes
maciaszczykm Apr 22, 2024
ba5aa5c
update attributes
maciaszczykm Apr 22, 2024
6ff4a34
update attributes
maciaszczykm Apr 22, 2024
b085657
finish attributes
maciaszczykm Apr 22, 2024
6ae5561
update from
maciaszczykm Apr 22, 2024
1b8489c
finish mappings
maciaszczykm Apr 22, 2024
68d32be
update docs
maciaszczykm Apr 22, 2024
9234b42
update validators
maciaszczykm Apr 22, 2024
90e8371
fix files model
maciaszczykm Apr 22, 2024
449bddf
fix files model
maciaszczykm Apr 22, 2024
806aad3
update example
maciaszczykm Apr 22, 2024
6feba72
randomize example stack names
maciaszczykm Apr 23, 2024
e679f11
fix bindings
maciaszczykm Apr 23, 2024
34120ef
fix environment
maciaszczykm Apr 23, 2024
a62a6ea
refactor
maciaszczykm Apr 23, 2024
625fda3
bug fixes
maciaszczykm Apr 23, 2024
33c832d
update examples
maciaszczykm Apr 23, 2024
f6d8835
update examples
maciaszczykm Apr 23, 2024
369c2bd
update client
maciaszczykm Apr 23, 2024
a2701ad
allow stack detach
maciaszczykm Apr 23, 2024
5e1e283
mark detach as computed
maciaszczykm Apr 23, 2024
0b826b8
rename var
maciaszczykm Apr 23, 2024
fc938fa
use detach in examples
maciaszczykm Apr 23, 2024
020f0a5
mark some attributes as computed
maciaszczykm Apr 23, 2024
83b2c2d
mark some more attributes as computed
maciaszczykm Apr 23, 2024
a7cb32f
mark some more attributes as computed
maciaszczykm Apr 23, 2024
703df07
require at least one container if set
maciaszczykm Apr 23, 2024
2e782fc
update examples
maciaszczykm Apr 23, 2024
f135960
prevent from using empty raw job spec
maciaszczykm Apr 23, 2024
80d048a
update example
maciaszczykm Apr 23, 2024
2812314
update description
maciaszczykm Apr 23, 2024
1317e52
add plan modifiers for labels and annotations
maciaszczykm Apr 24, 2024
183c8f8
default map and annotations
maciaszczykm Apr 24, 2024
6014ae2
unset computed for files attribute
maciaszczykm Apr 24, 2024
11d3079
fix mapping issues
maciaszczykm Apr 24, 2024
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
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
paths-ignore:
- 'README.md'
push:
branches:
- "main"
paths-ignore:
- 'README.md'
permissions:
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ Required:
Optional:

- `args` (List of String) Arguments to pass to the command when executing it.
- `env` (Map of String) Defines environment variables to expose to the process.
- `env` (Map of String) Defines environment variables to expose to the process.



Expand Down Expand Up @@ -186,7 +186,7 @@ Required:
Optional:

- `args` (List of String) Arguments to pass to the command when executing it.
- `env` (Map of String) Defines environment variables to expose to the process.
- `env` (Map of String) Defines environment variables to expose to the process.



Expand Down
137 changes: 137 additions & 0 deletions docs/resources/infrastructure_stack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "plural_infrastructure_stack Resource - terraform-provider-plural"
subcategory: ""
description: |-

---

# plural_infrastructure_stack (Resource)





<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `cluster_id` (String) The cluster on which the stack will be applied.
- `configuration` (Attributes) Stack configuration. (see [below for nested schema](#nestedatt--configuration))
- `name` (String) Human-readable name of this stack.
- `repository` (Attributes) Repository information used to pull stack. (see [below for nested schema](#nestedatt--repository))
- `type` (String) A type for the stack, specifies the tool to use to apply it. Allowed values include `ANSIBLE` and `TERRAFORM`.

### Optional

- `approval` (Boolean) Determines whether to require approval.
- `bindings` (Attributes) Read and write policies of this stack. (see [below for nested schema](#nestedatt--bindings))
- `detach` (Boolean) Determines behavior during resource destruction, if true it will detach resource instead of deleting it.
- `environment` (Attributes Set) Defines environment variables for the stack. (see [below for nested schema](#nestedatt--environment))
- `files` (Map of String) File path-content map.
- `job_spec` (Attributes) Repository information used to pull stack. (see [below for nested schema](#nestedatt--job_spec))

### Read-Only

- `id` (String) Internal identifier of this stack.

<a id="nestedatt--configuration"></a>
### Nested Schema for `configuration`

Required:

- `version` (String) The semver of the tool you wish to use.

Optional:

- `image` (String) Optional custom image you might want to use.


<a id="nestedatt--repository"></a>
### Nested Schema for `repository`

Required:

- `folder` (String) The folder where manifests live.
- `id` (String) ID of the repository to pull from.
- `ref` (String) A general git ref, either a branch name or commit sha understandable by "git checkout <ref>".


<a id="nestedatt--bindings"></a>
### Nested Schema for `bindings`

Optional:

- `read` (Attributes Set) Read policies of this stack. (see [below for nested schema](#nestedatt--bindings--read))
- `write` (Attributes Set) Write policies of this stack. (see [below for nested schema](#nestedatt--bindings--write))

<a id="nestedatt--bindings--read"></a>
### Nested Schema for `bindings.read`

Optional:

- `group_id` (String)
- `id` (String)
- `user_id` (String)


<a id="nestedatt--bindings--write"></a>
### Nested Schema for `bindings.write`

Optional:

- `group_id` (String)
- `id` (String)
- `user_id` (String)



<a id="nestedatt--environment"></a>
### Nested Schema for `environment`

Required:

- `name` (String) Environment variable name.
- `value` (String) Environment variable value.

Optional:

- `secret` (Boolean) Indicates if environment variable is secret.


<a id="nestedatt--job_spec"></a>
### Nested Schema for `job_spec`

Required:

- `namespace` (String) Namespace where job will be deployed.

Optional:

- `annotations` (Map of String) Kubernetes annotations applied to the job.
- `containers` (Attributes Set) (see [below for nested schema](#nestedatt--job_spec--containers))
- `labels` (Map of String) Kubernetes labels applied to the job.
- `raw` (String) If you'd rather define the job spec via straight Kubernetes YAML.
- `service_account` (String) Kubernetes service account for this job.

<a id="nestedatt--job_spec--containers"></a>
### Nested Schema for `job_spec.containers`

Required:

- `image` (String)

Optional:

- `args` (List of String) Arguments to pass to the command when executing it.
- `env` (Map of String) Defines environment variables to expose to the process.
- `env_from` (Attributes Set) (see [below for nested schema](#nestedatt--job_spec--containers--env_from))

<a id="nestedatt--job_spec--containers--env_from"></a>
### Nested Schema for `job_spec.containers.env_from`

Required:

- `config_map` (String)
- `secret` (String)
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions example/byok/main.tf → example/cluster/byok/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ resource "plural_cluster" "byok" {
metadata = jsonencode({
test1 = "test"
test2 = false
test3 = jsonencode({
test3 = {
abc = false
})
}
})
helm_repo_url = "https://pluralsh.github.io/deployment-operator"
tags = {
Expand Down
File renamed without changes.
16 changes: 0 additions & 16 deletions example/cluster_data/main.tf

This file was deleted.

162 changes: 162 additions & 0 deletions example/stack/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
terraform {
required_providers {
plural = {
source = "pluralsh/plural"
version = "0.0.1"
}
}
}

provider "plural" {
use_cli = true
}

data "plural_cluster" "cluster" {
handle = "mgmt"
}

data "plural_git_repository" "repository" {
url = "https://github.com/zreigz/tf-hello.git"
}

resource "random_string" "random" {
length = 5
upper = false
special = false
}

resource "plural_infrastructure_stack" "stack-full" {
name = "stack-tf-full-${random_string.random.result}"
type = "TERRAFORM"
approval = true
detach = true
cluster_id = data.plural_cluster.cluster.id
repository = {
id = data.plural_git_repository.repository.id
ref = "main"
folder = "terraform"
}
configuration = {
image = "hashicorp/terraform:1.8.1"
version = "1.8.1"
}
files = {
"test.yml" = "value: 123"
}
environment = [
{
name = "USERNAME"
value = "joe"
},
{
name = "PASSWORD"
value = "test"
secret = true
}
]
job_spec = {
namespace = "default"
labels = {
test = "123"
}
service_account = "default"
containers = [
{
image = "perl:5.34.0"
args = ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
env = {}
env_from = []
}
]
}
bindings = {
read = []
write = []
}
}

resource "plural_infrastructure_stack" "stack-raw" {
name = "stack-tf-raw-${random_string.random.result}"
type = "TERRAFORM"
approval = true
detach = true
cluster_id = data.plural_cluster.cluster.id
repository = {
id = data.plural_git_repository.repository.id
ref = "main"
folder = "terraform"
}
configuration = {
image = "hashicorp/terraform:1.8.1"
version = "1.8.1"
}
files = {
"test.yml" = "value: 123"
}
environment = [
{
name = "USERNAME"
value = "joe"
},
{
name = "PASSWORD"
value = "test"
secret = true
}
]
job_spec = {
namespace = "default"
raw = yamlencode({
containers = [
{
name = "pi"
image = "perl:5.34.0"
command = ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
}
]
restartPolicy = "Never"
})
}
bindings = {
read = []
write = []
}
}

resource "plural_infrastructure_stack" "stack-empty" {
name = "stack-tf-empty-${random_string.random.result}"
type = "TERRAFORM"
approval = true
detach = true
cluster_id = data.plural_cluster.cluster.id
repository = {
id = data.plural_git_repository.repository.id
ref = "main"
folder = "terraform"
}
configuration = {
version = "1.8.1"
}
files = {}
environment = []
job_spec = {
namespace = "default"
raw = yamlencode({ test = true })
}
bindings = {}
}

resource "plural_infrastructure_stack" "stack-minimal" {
name = "stack-tf-minimal-${random_string.random.result}"
type = "TERRAFORM"
detach = true
cluster_id = data.plural_cluster.cluster.id
repository = {
id = data.plural_git_repository.repository.id
ref = "main"
folder = "terraform"
}
configuration = {
version = "1.8.1"
}
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ require (
github.com/hashicorp/terraform-plugin-framework-validators v0.12.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/mitchellh/go-homedir v1.1.0
github.com/pluralsh/console-client-go v0.1.17
github.com/pluralsh/console-client-go v0.4.0
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37
github.com/pluralsh/polly v0.1.7
github.com/samber/lo v1.38.1
github.com/sirupsen/logrus v1.9.3
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.11.2
k8s.io/api v0.26.4
k8s.io/apimachinery v0.26.4
k8s.io/client-go v0.26.4
sigs.k8s.io/yaml v1.3.0
Expand Down Expand Up @@ -335,7 +336,6 @@ require (
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
honnef.co/go/tools v0.4.6 // indirect
k8s.io/api v0.26.4 // indirect
k8s.io/apiextensions-apiserver v0.26.1 // indirect
k8s.io/apiserver v0.26.1 // indirect
k8s.io/cli-runtime v0.26.1 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -856,8 +856,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/pluralsh/console-client-go v0.1.17 h1:QMtnWdRvV13/sND/CFjFBUR8nyg3JJgwXReSyM6bK7A=
github.com/pluralsh/console-client-go v0.1.17/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/console-client-go v0.4.0 h1:lgKaVGi8jB7S8wFF6L3P6H/4Xc88e4FozhyW58O1w3Q=
github.com/pluralsh/console-client-go v0.4.0/go.mod h1:eyCiLA44YbXiYyJh8303jk5JdPkt9McgCo5kBjk4lKo=
github.com/pluralsh/gqlclient v1.11.0 h1:FfXW7FiEJLHOfTAa7NxDb8jb3aMZNIpCAcG+bg8uHYA=
github.com/pluralsh/gqlclient v1.11.0/go.mod h1:qSXKUlio1F2DRPy8el4oFYsmpKbkUYspgPB87T4it5I=
github.com/pluralsh/plural-cli v0.8.5-0.20240216094552-efc34ee6de37 h1:DBnaKvKmbTbKwbkrh/2gJBwyHYfaXdxeT3UGh+94K4g=
Expand Down
Loading
Loading