Skip to content

Commit

Permalink
fix(orgid): fixed humantiec_org_id environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
dharsanb committed Jan 8, 2024
1 parent 467d721 commit fe74806
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 24 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ jobs:
terraform_wrapper: false
- run: make testacc
env:
HUMANITEC_ORG: ${{ secrets.HUMANITEC_ORG }}
HUMANITEC_ORG_ID: ${{ secrets.HUMANITEC_ORG_ID }}
HUMANITEC_TOKEN: ${{ secrets.HUMANITEC_TOKEN }}
unit:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ provider "humanitec" {

- `disable_ssl_certificate_verification` (Boolean) Disables SSL certificate verification
- `host` (String) Humanitec API host (or using the `HUMANITEC_HOST` environment variable)
- `org_id` (String) Humanitec Organization ID (or using the `HUMANITEC_ORG_ID` environment variable)
- `org_id` (String) Humanitec Organization ID (or using the `HUMANITEC_ORG` environment variable)
- `token` (String, Sensitive) Humanitec Token (or using the `HUMANITEC_TOKEN` environment variable)
15 changes: 12 additions & 3 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *HumanitecProvider) Schema(ctx context.Context, req provider.SchemaReque
Optional: true,
},
"org_id": schema.StringAttribute{
MarkdownDescription: "Humanitec Organization ID (or using the `HUMANITEC_ORG_ID` environment variable)",
MarkdownDescription: "Humanitec Organization ID (or using the `HUMANITEC_ORG` environment variable)",
Optional: true,
},
"token": schema.StringAttribute{
Expand All @@ -79,7 +79,16 @@ func (p *HumanitecProvider) Configure(ctx context.Context, req provider.Configur
host = humanitec.DefaultAPIHost
}

orgID := os.Getenv("HUMANITEC_ORG_ID")
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 @@ -116,7 +125,7 @@ func (p *HumanitecProvider) Configure(ctx context.Context, req provider.Configur
resp.Diagnostics.AddError(
"Missing API Org ID Configuration",
"While configuring the provider, the API token was not found in "+
"the HUMANITEC_ORG_ID environment variable or provider "+
"the HUMANITEC_ORG environment variable or provider "+
"configuration block org_id attribute.",
)
// Not returning early allows the logic to collect all errors.
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var testAccProtoV6ProviderFactories = map[string]func() (tfprotov6.ProviderServe
}

func testAccPreCheck(t *testing.T) {
checkEnvVar(t, "HUMANITEC_ORG_ID")
checkEnvVar(t, "HUMANITEC_ORG")
checkEnvVar(t, "HUMANITEC_TOKEN")
}

Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestAccResourceApplicationDeletedOutManually(t *testing.T) {
ctx := context.Background()
id := fmt.Sprintf("test-%d", time.Now().UnixNano())

orgID := os.Getenv("HUMANITEC_ORG_ID")
orgID := os.Getenv("HUMANITEC_ORG")
token := os.Getenv("HUMANITEC_TOKEN")

var client *humanitec.Client
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_definition_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,6 @@ func TestParseMapInput_UnexpectedType(t *testing.T) {
}

func getDefinitionSecretPath(defID string) string {
orgID := os.Getenv("HUMANITEC_ORG_ID")
orgID := os.Getenv("HUMANITEC_ORG")
return fmt.Sprintf("orgs/%s/resources/defs/%s/driver_secrets", orgID, defID)
}
4 changes: 2 additions & 2 deletions internal/provider/resource_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func (r *ResourcePipeline) Schema(ctx context.Context, req resource.SchemaReques
},
"metadata": schema.MapAttribute{
MarkdownDescription: "The map of key value pipeline additional information.",
ElementType: types.StringType,
ElementType: types.StringType,
Computed: true,
},
"trigger_types": schema.SetAttribute{
MarkdownDescription: "The list of trigger types in the current schema.",
ElementType: types.StringType,
ElementType: types.StringType,
Computed: true,
},
},
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_pipeline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
ImportStateVerify: true,
},
{
ResourceName: "humanitec_pipeline.pipeline_test",
ResourceName: "humanitec_pipeline.pipeline_test",
ImportStateIdFunc: func(s *terraform.State) (string, error) {
pipeline, err := testResource("humanitec_pipeline.pipeline_test", s)
if err != nil {
Expand Down
18 changes: 9 additions & 9 deletions internal/provider/resource_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,17 @@ func (r *ResourceRegistry) Configure(ctx context.Context, req resource.Configure
}

type RegistryModel struct {
ID types.String `tfsdk:"id"`
Registry types.String `tfsdk:"registry"`
Type types.String `tfsdk:"type"`
EnableCI types.Bool `tfsdk:"enable_ci"`
Creds types.Object `tfsdk:"creds"`
Secrets *map[string]SecretsModel `tfsdk:"secrets"`
ID types.String `tfsdk:"id"`
Registry types.String `tfsdk:"registry"`
Type types.String `tfsdk:"type"`
EnableCI types.Bool `tfsdk:"enable_ci"`
Creds types.Object `tfsdk:"creds"`
Secrets *map[string]SecretsModel `tfsdk:"secrets"`
}

type SecretsModel struct {
Namespace types.String `tfsdk:"namespace"`
Secret types.String `tfsdk:"secret"`
Secret types.String `tfsdk:"secret"`
}

func (r *ResourceRegistry) Create(ctx context.Context, req resource.CreateRequest, resp *resource.CreateResponse) {
Expand Down Expand Up @@ -374,11 +374,11 @@ func parseRegistryResponse(ctx context.Context, res *client.RegistryResponse, da
data.EnableCI = types.BoolValue(res.EnableCi)

if res.Secrets != nil {
secrets := make(map[string]SecretsModel)
secrets := make(map[string]SecretsModel)
for key, value := range *res.Secrets {
secrets[key] = SecretsModel{
Namespace: types.StringValue(value.Namespace),
Secret: types.StringValue(value.Secret),
Secret: types.StringValue(value.Secret),
}
}
data.Secrets = &secrets
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/resource_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestAccResourceRegistry(t *testing.T) {
// ImportState testing
{
ResourceName: "humanitec_registry.registry_test",
ImportStateId: id,
ImportStateId: id,
ImportState: true,
ImportStateVerify: true,
},
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/resource_value_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestAccResourceValue(t *testing.T) {
func TestAccResourceValueWithSecretValue(t *testing.T) {
appID := fmt.Sprintf("val-test-app-%d", time.Now().UnixNano())
key := "VAL_SECRET_1"
orgID := os.Getenv("HUMANITEC_ORG_ID")
orgID := os.Getenv("HUMANITEC_ORG")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestAccResourceValueWithSecretValue(t *testing.T) {
func TestAccResourceValueWithSecretValueSecretRefValue(t *testing.T) {
appID := fmt.Sprintf("val-test-app-%d", time.Now().UnixNano())
key := "VAL_SECRET_REF_VALUE_1"
orgID := os.Getenv("HUMANITEC_ORG_ID")
orgID := os.Getenv("HUMANITEC_ORG")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -140,7 +140,7 @@ func TestAccResourceValueWithSecretValueSecretRefValue(t *testing.T) {
func TestAccResourceValueWithSecretRef(t *testing.T) {
appID := fmt.Sprintf("val-test-app-%d", time.Now().UnixNano())
key := "VAL_SECRET_REF_1"
orgID := os.Getenv("HUMANITEC_ORG_ID")
orgID := os.Getenv("HUMANITEC_ORG")

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down Expand Up @@ -195,7 +195,7 @@ func TestAccResourceValueDeletedOutManually(t *testing.T) {

key := "VAL_1"

orgID := os.Getenv("HUMANITEC_ORG_ID")
orgID := os.Getenv("HUMANITEC_ORG")
token := os.Getenv("HUMANITEC_TOKEN")

var client *humanitec.Client
Expand Down

0 comments on commit fe74806

Please sign in to comment.