Skip to content

Commit

Permalink
feat: prepare v1
Browse files Browse the repository at this point in the history
  • Loading branch information
johanneswuerbach committed Feb 16, 2024
1 parent 0c104fc commit d6045cb
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 1,080 deletions.
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
# Terraform Provider Humanitec

---

:construction: __This provider is experimental and currently not recommended for production usage.__ :construction:

---

* [Usage](https://registry.terraform.io/providers/humanitec/humanitec/latest)
* [Documentation](https://registry.terraform.io/providers/humanitec/humanitec/latest/docs)

## Requirements

- [Terraform](https://www.terraform.io/downloads.html) >= 1.0
- [Go](https://golang.org/doc/install) >= 1.18
* [Terraform](https://www.terraform.io/downloads.html) >= 1.0
* [Go](https://golang.org/doc/install) >= 1.18

## Building The Provider

Expand Down
38 changes: 0 additions & 38 deletions docs/resources/resource_application_user.md

This file was deleted.

35 changes: 0 additions & 35 deletions docs/resources/resource_definition.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ resource "humanitec_resource_definition" "postgres" {
"password" = "test"
})
}
criteria = [
{
app_id = "test-app"
}
]
}
resource "humanitec_resource_definition" "gke" {
Expand All @@ -69,17 +63,6 @@ resource "humanitec_resource_definition" "gke" {
"credentials" = "{}"
})
}
criteria = [
{
app_id = "test-app"
env_type = "development"
},
{
app_id = "test-app"
env_type = "staging"
}
]
}
```

Expand All @@ -95,37 +78,19 @@ resource "humanitec_resource_definition" "gke" {

### Optional

- `criteria` (Attributes Set, Deprecated) The criteria to use when looking for a Resource Definition during the deployment. (see [below for nested schema](#nestedatt--criteria))
- `driver_account` (String) Security account required by the driver.
- `driver_inputs` (Attributes) Data that should be passed around split by sensitivity. (see [below for nested schema](#nestedatt--driver_inputs))
- `force_delete` (Boolean) If set to `true`, will mark the Resource Definition for deletion, even if it affects existing Active Resources.
- `provision` (Attributes Map) ProvisionDependencies defines resources which are needed to be co-provisioned with the current resource. (see [below for nested schema](#nestedatt--provision))
- `timeouts` (Attributes) (see [below for nested schema](#nestedatt--timeouts))

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

Optional:

- `app_id` (String) The ID of the Application that the Resources should belong to.
- `env_id` (String) The ID of the Environment that the Resources should belong to. If `env_type` is also set, it must match the Type of the Environment for the Criteria to match.
- `env_type` (String) The Type of the Environment that the Resources should belong to. If `env_id` is also set, it must have an Environment Type that matches this parameter for the Criteria to match.
- `res_id` (String) The ID of the Resource in the Deployment Set. The ID is normally a `.` separated path to the definition in the set, e.g. `modules.my-module.externals.my-database`.

Read-Only:

- `id` (String) Matching Criteria ID


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

Optional:

- `secret_refs` (String) JSON encoded secrets section of the data set. They can hold sensitive information that will be stored in the primary organization secret store and replaced with the secret store paths when sent outside, or secret references stored in a defined secret store. Can't be used together with secrets.
- `secrets` (Map of String, Sensitive, Deprecated) Secrets section of the data set. Deprecated in favour of secrets_string. Can't be used together with secret_refs.
- `secrets_string` (String) JSON encoded secret data set. Passed around as-is. Can't be used together with secret_refs.
- `values` (Map of String, Deprecated) Values section of the data set. Passed around as-is. Deprecated in favour of values_string.
- `values_string` (String) JSON encoded input data set. Passed around as-is.


Expand Down
38 changes: 0 additions & 38 deletions docs/resources/resource_environment_type_user.md

This file was deleted.

17 changes: 0 additions & 17 deletions examples/resources/humanitec_resource_definition/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ resource "humanitec_resource_definition" "postgres" {
"password" = "test"
})
}

criteria = [
{
app_id = "test-app"
}
]
}

resource "humanitec_resource_definition" "gke" {
Expand All @@ -54,15 +48,4 @@ resource "humanitec_resource_definition" "gke" {
"credentials" = "{}"
})
}

criteria = [
{
app_id = "test-app"
env_type = "development"
},
{
app_id = "test-app"
env_type = "staging"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ resource "humanitec_resource_definition" "example" {

driver_type = "humanitec/s3"
driver_inputs = {
values = {
values_string = jsonencode({
region = "us-east-1"
}
})
}

lifecycle {
Expand Down
15 changes: 2 additions & 13 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ func (p *HumanitecProvider) Configure(ctx context.Context, req provider.Configur
}

orgID := os.Getenv("HUMANITEC_ORG")
if orgID == "" {
if orgIDOld := os.Getenv("HUMANITEC_ORG_ID"); orgIDOld != "" {
orgID = orgIDOld
resp.Diagnostics.AddWarning(
"Environment variable HUMANITEC_ORG_ID has been deprecated",
"Environment variable HUMANITEC_ORG_ID has been deprecated "+
"please use HUMANITEC_ORG instead to set your org_id to the terraform driver ")
}
}
token := os.Getenv("HUMANITEC_TOKEN")

var data HumanitecProviderModel
Expand Down Expand Up @@ -164,14 +155,12 @@ func (p *HumanitecProvider) Resources(ctx context.Context) []func() resource.Res
NewResourceAccountResource,
NewResourceAgent,
NewResourceApplication,
NewResourceApplicationUser(true),
NewResourceApplicationUser(false),
NewResourceApplicationUser,
NewResourceArtefactVersion,
NewResourceDefinitionCriteriaResource,
NewResourceDefinitionResource,
NewResourceEnvironmentType,
NewResourceEnvironmentTypeUser(true),
NewResourceEnvironmentTypeUser(false),
NewResourceEnvironmentTypeUser,
NewResourcePipeline,
NewResourcePipelineCriteria,
NewResourceRegistry,
Expand Down
22 changes: 5 additions & 17 deletions internal/provider/resource_application_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@ var (
defaultApplicationUserReadTimeout = 30 * time.Second
)

func NewResourceApplicationUser(deprecatedVersion bool) func() resource.Resource {
return func() resource.Resource {
return &ResourceApplicationUser{
deprecatedVersion: deprecatedVersion,
}
}
func NewResourceApplicationUser() resource.Resource {
return &ResourceApplicationUser{}
}

// ResourceDefinitionResource defines the resource implementation.
type ResourceApplicationUser struct {
client *humanitec.Client
orgId string
deprecatedVersion bool
client *humanitec.Client
orgId string
}

// DefinitionResourceModel describes the resource data model.
Expand All @@ -55,11 +50,7 @@ type ResourceApplicationUserModel struct {
}

func (r *ResourceApplicationUser) Metadata(ctx context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
if r.deprecatedVersion {
resp.TypeName = req.ProviderTypeName + "_resource_application_user"
} else {
resp.TypeName = req.ProviderTypeName + "_application_user"
}
resp.TypeName = req.ProviderTypeName + "_application_user"
}

func (r *ResourceApplicationUser) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
Expand Down Expand Up @@ -97,9 +88,6 @@ func (r *ResourceApplicationUser) Schema(ctx context.Context, req resource.Schem
}),
},
}
if r.deprecatedVersion {
resp.Schema.DeprecationMessage = "This resource is deprecated. Please use `humanitec_application_user` instead."
}
}

func (r *ResourceApplicationUser) Configure(ctx context.Context, req resource.ConfigureRequest, resp *resource.ConfigureResponse) {
Expand Down
89 changes: 33 additions & 56 deletions internal/provider/resource_application_user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,73 +13,50 @@ func TestAccResourceApplicationUser(t *testing.T) {
id := fmt.Sprintf("app-user-test-%d", time.Now().UnixNano())
testUserID := "1b305f15-f18f-4357-8311-01f88ed99d1b"

tests := []struct {
name string
deprecatedResource bool
}{
{
name: "regular",
deprecatedResource: false,
},
{
name: "deprecated",
deprecatedResource: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
resourceName := "humanitec_application_user"
if tt.deprecatedResource {
resourceName = "humanitec_resource_application_user"
}

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccResourceApplicationUser(id, testUserID, "owner", resourceName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName+".another_user", "id", fmt.Sprintf("%s/%s", id, testUserID)),
resource.TestCheckResourceAttr(resourceName+".another_user", "role", "owner"),
),
},
// ImportState testing
{
ResourceName: resourceName + ".another_user",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: func(s *terraform.State) (string, error) {
return fmt.Sprintf("%s/%s", id, testUserID), nil
},
},
// Update and Read testing
{
Config: testAccResourceApplicationUser(id, testUserID, "developer", resourceName),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr(resourceName+".another_user", "role", "developer"),
),
},
// Delete testing automatically occurs in TestCase
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
Steps: []resource.TestStep{
// Create and Read testing
{
Config: testAccResourceApplicationUser(id, testUserID, "owner"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_application_user.another_user", "id", fmt.Sprintf("%s/%s", id, testUserID)),
resource.TestCheckResourceAttr("humanitec_application_user.another_user", "role", "owner"),
),
},
// ImportState testing
{
ResourceName: "humanitec_application_user.another_user",
ImportState: true,
ImportStateVerify: true,
ImportStateIdFunc: func(s *terraform.State) (string, error) {
return fmt.Sprintf("%s/%s", id, testUserID), nil
},
})
})
}
},
// Update and Read testing
{
Config: testAccResourceApplicationUser(id, testUserID, "developer"),
Check: resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("humanitec_application_user.another_user", "role", "developer"),
),
},
// Delete testing automatically occurs in TestCase
},
})
}

func testAccResourceApplicationUser(id, userID, role, resourceName string) string {
func testAccResourceApplicationUser(id, userID, role string) string {
return fmt.Sprintf(`
resource "humanitec_application" "app_user_test" {
id = "%s"
name = "%s"
}
resource "%s" "another_user" {
resource "humanitec_application_user" "another_user" {
app_id = humanitec_application.app_user_test.id
user_id = "%s"
role = "%s"
}
`, id, id, resourceName, userID, role)
`, id, id, userID, role)
}
Loading

0 comments on commit d6045cb

Please sign in to comment.