From 1bb9d1005d3f9e9e6288388d27a5bf544cb96d1d Mon Sep 17 00:00:00 2001 From: Pauline Espalieu Date: Tue, 27 Aug 2024 09:09:06 +0200 Subject: [PATCH] set url in environment instead of variables (#23) * set url in environment instead of variables * fix linter --------- Co-authored-by: Pauline ESPALIEU --- README.md | 63 ++++++++++++++++++++++++- docs/index.md | 4 -- examples/autonomi/terraform.auto.tfvars | 3 +- examples/autonomi/variable.tf | 12 ----- examples/provider/provider.tf | 2 - internal/provider/provider.go | 20 +------- 6 files changed, 65 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 1a45220..266f6b7 100644 --- a/README.md +++ b/README.md @@ -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= +export AUTONOMI_HOST_URL= +export AUTONOMI_CATALOG_URL= +terraform plan +``` diff --git a/docs/index.md b/docs/index.md index 9abd2c2..36bc382 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 } ``` @@ -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 diff --git a/examples/autonomi/terraform.auto.tfvars b/examples/autonomi/terraform.auto.tfvars index 2d2ee64..8b13789 100644 --- a/examples/autonomi/terraform.auto.tfvars +++ b/examples/autonomi/terraform.auto.tfvars @@ -1,2 +1 @@ -host_url = "https://api.autonomi.io" -catalog_url = "https://catalog.autonomi.io" + diff --git a/examples/autonomi/variable.tf b/examples/autonomi/variable.tf index 3568909..cc810c9 100644 --- a/examples/autonomi/variable.tf +++ b/examples/autonomi/variable.tf @@ -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 diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 9a41e4e..b3f9cb1 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -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 } \ No newline at end of file diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 416b501..49eafad 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -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. @@ -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", - }, }, } } @@ -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.