Skip to content

Commit

Permalink
set url in environment instead of variables (#23)
Browse files Browse the repository at this point in the history
* set url in environment instead of variables

* fix linter

---------

Co-authored-by: Pauline ESPALIEU <[email protected]>
  • Loading branch information
Pauline Espalieu and Pauline ESPALIEU authored Aug 27, 2024
1 parent 0b1ca31 commit 1bb9d10
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 39 deletions.
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,64 @@
# Terraform Provider Autonomi

The autonomi provider enables Terraform to manage autonomi resources.
Use the Autonomi provider to interact with the many resources supported by Autonomi. You must configure the provider with the proper credential before you can use it.

## Example Usage

```terraform
terraform {
required_providers {
autonomi = {
source = "hashicorp.com/intercloud/autonomi"
}
}
}
provider "autonomi" {
terms_and_conditions = true
}
resource "autonomi_workspace" "workspace_test" {
name = "Workspace created with Terraform"
description = "from autonomi with <3"
}
```

## Authentication and Configuration

Configuration for the AWS Provider can be derived from several sources, which are applied in the following order:

1. Parameters in the provider configuration
2. Environment variables

### Provider configuration

Access can be allowed by adding a personal access token to the autonomi provider block.
The [terms and conditions](https://docs.autonomi-platform.com/docs/legal) must be accepted to be able to deploy resources.

Usage:

```terraform
provider "autonomi" {
terms_and_conditions = true
personal_access_token = "my-personnal-access-token"
}
```

### Environment Variables

Access can be allowed by using the `AUTONOMI_PAT` environment variables. For a local usage the variables `AUTONOMI_HOST_URL` and `AUTONOMI_CATALOG_URL` must also be set.

For example:

```terraform
provider "autonomi" {
terms_and_conditions = true
}
```

```bash
export AUTONOMI_PAT=<my-personal-access-token>
export AUTONOMI_HOST_URL=<autonomi-api-url>
export AUTONOMI_CATALOG_URL=<autonomi-catalog-url>
terraform plan
```
4 changes: 0 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ description: |-

```terraform
provider "autonomi" {
host_url = var.host_url
terms_and_conditions = true
personal_access_token = var.pat_token
catalog_url = var.catalog_url
}
```

Expand All @@ -24,8 +22,6 @@ provider "autonomi" {

### Required

- `catalog_url` (String, Sensitive) The url to interact with autonomi's catalog
- `host_url` (String, Sensitive) The host url to interact with autonomi API
- `terms_and_conditions` (Boolean) Terms and conditions

### Optional
Expand Down
3 changes: 1 addition & 2 deletions examples/autonomi/terraform.auto.tfvars
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
host_url = "https://api.autonomi.io"
catalog_url = "https://catalog.autonomi.io"

12 changes: 0 additions & 12 deletions examples/autonomi/variable.tf
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
variable "host_url" { // @TODO remove when it will be published
description = "The hostname or base URL of the API endpoint for the Autonomi service. This URL is used by the custom Terraform provider to interact with the Autonomi API."
type = string
sensitive = true
}

variable "catalog_url" { // @TODO remove when it will be published
description = "The hostname or base URL of the API endpoint for the Autonomi's catalog service. This URL is used by the custom Terraform provider to interact with the Autonomi's catalog API."
type = string
sensitive = true
}

variable "pat_token" {
description = "The Personal Access Token (PAT) used to authenticate with the Autonomi API. This token can be obtained from the Autonomi service and is required to access and manage resources via the API."
type = string
Expand Down
2 changes: 0 additions & 2 deletions examples/provider/provider.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
provider "autonomi" {
host_url = var.host_url
terms_and_conditions = true
personal_access_token = var.pat_token
catalog_url = var.catalog_url
}
20 changes: 2 additions & 18 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ type autonomiProvider struct {
type autonomiProviderModel struct {
TermsAndConditions types.Bool `tfsdk:"terms_and_conditions"`
PAT types.String `tfsdk:"personal_access_token"`
HostURL types.String `tfsdk:"host_url"` // @TODO remove when it will be published
CatalogURL types.String `tfsdk:"catalog_url"` // @TODO remove when it will be published
}

// New is a helper function to simplify provider server and testing implementation.
Expand Down Expand Up @@ -69,16 +67,6 @@ func (p *autonomiProvider) Schema(_ context.Context, _ provider.SchemaRequest, r
Sensitive: true,
Description: "The Personal Access Token (PAT) used to authenticate with the Autonomi API. This token can be obtained from the Autonomi service and is required to access and manage resources via the API. Can be set as variable or in environment as AUTONOMI_PAT",
},
"host_url": schema.StringAttribute{
Required: true,
Sensitive: true,
Description: "The host url to interact with autonomi API",
},
"catalog_url": schema.StringAttribute{
Required: true,
Sensitive: true,
Description: "The url to interact with autonomi's catalog",
},
},
}
}
Expand Down Expand Up @@ -106,12 +94,8 @@ func (p *autonomiProvider) Configure(ctx context.Context, req provider.Configure
} else {
personal_access_token = os.Getenv("AUTONOMI_PAT")
}
if !config.HostURL.IsNull() {
host_url = config.HostURL.ValueString()
}
if !config.CatalogURL.IsNull() {
catalog_url = config.CatalogURL.ValueString()
}
host_url = os.Getenv("AUTONOMI_HOST_URL")
catalog_url = os.Getenv("AUTONOMI_CATALOG_URL")

// If any of the expected configurations are missing, return
// errors with provider-specific guidance.
Expand Down

0 comments on commit 1bb9d10

Please sign in to comment.