diff --git a/docs/index.md b/docs/index.md index afb9dbe..851b7a5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -15,12 +15,12 @@ description: |- ```terraform # No auth provider "mcma" { - services_url = "https://service-registry-example.mcma.io/api/services" + service_registry_url = "https://service-registry-example.mcma.io/api/" } # AWS auth with profile provider "mcma" { - services_url = "https://service-registry-example.mcma.io/api/services" + service_registry_url = "https://service-registry-example.mcma.io/api/" aws4_auth { region = "us-east-1" profile = "myprofile" @@ -29,7 +29,7 @@ provider "mcma" { # AWS auth with keys provider "mcma" { - services_url = "https://service-registry-example.mcma.io/api/services" + service_registry_url = "https://service-registry-example.mcma.io/api/" aws4_auth { region = "us-east-1" access_key = "accesskey" @@ -43,12 +43,12 @@ provider "mcma" { ### Required -- `services_url` (String) The url to the services endpoint of the MCMA Service Registry +- `service_registry_url` (String) The url to the services endpoint of the MCMA Service Registry ### Optional - `aws4_auth` (Block Set) (see [below for nested schema](#nestedblock--aws4_auth)) -- `services_auth_type` (String) The auth type to use for the services endpoint of the MCMA Service Registry +- `service_registry_auth_type` (String) The auth type to use for the services endpoint of the MCMA Service Registry ### Nested Schema for `aws4_auth` diff --git a/examples/provider/provider.tf b/examples/provider/provider.tf index 4645156..a616301 100644 --- a/examples/provider/provider.tf +++ b/examples/provider/provider.tf @@ -1,11 +1,11 @@ # No auth provider "mcma" { - services_url = "https://service-registry-example.mcma.io/api/services" + service_registry_url = "https://service-registry-example.mcma.io/api/" } # AWS auth with profile provider "mcma" { - services_url = "https://service-registry-example.mcma.io/api/services" + service_registry_url = "https://service-registry-example.mcma.io/api/" aws4_auth { region = "us-east-1" profile = "myprofile" @@ -14,7 +14,7 @@ provider "mcma" { # AWS auth with keys provider "mcma" { - services_url = "https://service-registry-example.mcma.io/api/services" + service_registry_url = "https://service-registry-example.mcma.io/api/" aws4_auth { region = "us-east-1" access_key = "accesskey" diff --git a/go.mod b/go.mod index 4fd0f98..82b7465 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/ebu/terraform-provider-mcma go 1.18 require ( - github.com/ebu/mcma-libraries-go v0.0.13 + github.com/ebu/mcma-libraries-go v0.0.14 github.com/hashicorp/terraform-plugin-docs v0.7.0 github.com/hashicorp/terraform-plugin-sdk/v2 v2.13.0 ) diff --git a/go.sum b/go.sum index 17e924c..7de06e9 100644 --- a/go.sum +++ b/go.sum @@ -49,8 +49,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/ebu/mcma-libraries-go v0.0.13 h1:UgJcM/54947ZllMuqwxsSPqBqSlXfLIvkTucjI0e2Rs= -github.com/ebu/mcma-libraries-go v0.0.13/go.mod h1:RnT/sTbg7ICp6NHDxyj/xX9xI+bqbcm9SUkPTIJnqs4= +github.com/ebu/mcma-libraries-go v0.0.14 h1:ZIsQ2f+COcvsS8gAeAKyFK98qNUw6AI7OmXCa5y0uts= +github.com/ebu/mcma-libraries-go v0.0.14/go.mod h1:RnT/sTbg7ICp6NHDxyj/xX9xI+bqbcm9SUkPTIJnqs4= github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg= github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= diff --git a/mcma/auth_helper.go b/mcma/auth_helper.go index 850353b..fec25fe 100644 --- a/mcma/auth_helper.go +++ b/mcma/auth_helper.go @@ -2,8 +2,9 @@ package mcma import ( "fmt" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "reflect" + + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" ) func GetAuthDataString(authData map[string]interface{}, key string, required bool) (string, diag.Diagnostics) { diff --git a/mcma/aws_auth.go b/mcma/aws_auth.go index aba56ff..0e540dc 100644 --- a/mcma/aws_auth.go +++ b/mcma/aws_auth.go @@ -1,13 +1,14 @@ package mcma import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "os" - mcma "github.com/ebu/mcma-libraries-go/client" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + + mcmaclient "github.com/ebu/mcma-libraries-go/client" ) -func GetAWS4Authenticator(authData map[string]interface{}) (mcma.Authenticator, diag.Diagnostics) { +func GetAWS4Authenticator(authData map[string]interface{}) (mcmaclient.Authenticator, diag.Diagnostics) { region, d := GetAuthDataString(authData, "region", false) if d != nil { return nil, d @@ -34,7 +35,7 @@ func GetAWS4Authenticator(authData map[string]interface{}) (mcma.Authenticator, if d != nil { return nil, d } - return mcma.NewAWS4AuthenticatorFromKeys(accessKey, secretKey, sessionToken, region), nil + return mcmaclient.NewAWS4AuthenticatorFromKeys(accessKey, secretKey, sessionToken, region), nil } profile, d := GetAuthDataString(authData, "profile", false) @@ -42,8 +43,8 @@ func GetAWS4Authenticator(authData map[string]interface{}) (mcma.Authenticator, return nil, d } if len(profile) > 0 { - return mcma.NewAWS4AuthenticatorFromProfile(profile, region), nil + return mcmaclient.NewAWS4AuthenticatorFromProfile(profile, region), nil } - return mcma.NewAWS4AuthenticatorFromEnvVars(), nil + return mcmaclient.NewAWS4AuthenticatorFromEnvVars(), nil } diff --git a/mcma/provider.go b/mcma/provider.go index fa6379e..645adcd 100644 --- a/mcma/provider.go +++ b/mcma/provider.go @@ -3,9 +3,10 @@ package mcma import ( "context" - mcmaclient "github.com/ebu/mcma-libraries-go/client" "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + + mcmaclient "github.com/ebu/mcma-libraries-go/client" ) func init() { @@ -15,12 +16,12 @@ func init() { func Provider() *schema.Provider { return &schema.Provider{ Schema: map[string]*schema.Schema{ - "services_url": { + "service_registry_url": { Type: schema.TypeString, Description: "The url to the services endpoint of the MCMA Service Registry", Required: true, }, - "services_auth_type": { + "service_registry_auth_type": { Type: schema.TypeString, Description: "The auth type to use for the services endpoint of the MCMA Service Registry", Optional: true, @@ -89,26 +90,26 @@ func addAuthToMap( } func configure(d *schema.ResourceData) (interface{}, diag.Diagnostics) { - servicesUrl := d.Get("services_url").(string) - if servicesUrl == "" { + serviceRegistryUrl := d.Get("service_registry_url").(string) + if serviceRegistryUrl == "" { return nil, nil } - servicesAuthType := d.Get("services_auth_type").(string) + serviceRegistryAuthType := d.Get("service_registry_auth_type").(string) authMap := make(map[string]mcmaclient.Authenticator) addAuthToMap(authMap, d, "aws4", GetAWS4Authenticator) - if len(authMap) == 1 && servicesAuthType == "" { + if len(authMap) == 1 && serviceRegistryAuthType == "" { for s := range authMap { - servicesAuthType = s + serviceRegistryAuthType = s } } var resourceManager mcmaclient.ResourceManager - if len(servicesAuthType) != 0 { - resourceManager = mcmaclient.NewResourceManager(servicesUrl, servicesAuthType) + if len(serviceRegistryAuthType) != 0 { + resourceManager = mcmaclient.NewResourceManager(serviceRegistryUrl, serviceRegistryAuthType) } else { - resourceManager = mcmaclient.NewResourceManagerNoAuth(servicesUrl) + resourceManager = mcmaclient.NewResourceManagerNoAuth(serviceRegistryUrl) } for key, a := range authMap { @@ -124,7 +125,7 @@ func getResourceManager(m interface{}) (*mcmaclient.ResourceManager, diag.Diagno diag.Diagnostic{ Severity: diag.Error, Summary: "ResourceManager not initialized.", - Detail: "Url for MCMA service registry was not provided, and the MCMA_SERVICES_URL environment variable is not set.", + Detail: "Url for MCMA service registry was not provided, and the MCMA_SERVICE_REGISTRY_URL environment variable is not set.", }, } } diff --git a/mcma/provider_test.go b/mcma/provider_test.go index 24e57ed..b4b5f58 100644 --- a/mcma/provider_test.go +++ b/mcma/provider_test.go @@ -1,8 +1,9 @@ package mcma import ( - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "os" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) var testAccProvider *schema.Provider @@ -22,11 +23,11 @@ type aws4AuthBlock struct { secretKey string } -func getProviderConfig(servicesUrl string, servicesAuthType string, authBlocks []aws4AuthBlock) string { +func getProviderConfig(serviceRegistryUrl string, serviceRegistryAuthType string, authBlocks []aws4AuthBlock) string { providerConfig := "provider \"mcma\" {\n" - providerConfig += " services_url = \"" + servicesUrl + "\"\n" - if servicesAuthType != "" { - providerConfig += " services_auth_type = \"" + servicesAuthType + "\"\n" + providerConfig += " service_registry_url = \"" + serviceRegistryUrl + "\"\n" + if serviceRegistryAuthType != "" { + serviceRegistryAuthType += " service_registry_auth_type = \"" + serviceRegistryAuthType + "\"\n" } if authBlocks != nil && len(authBlocks) > 0 { for _, authBlock := range authBlocks { @@ -50,19 +51,19 @@ func getProviderConfig(servicesUrl string, servicesAuthType string, authBlocks [ return providerConfig } -func getAwsProfileProviderConfig(servicesUrl string, region string, profile string) string { +func getAwsProfileProviderConfig(serviceRegistryUrl string, region string, profile string) string { authBlocks := make([]aws4AuthBlock, 1) authBlocks[0] = aws4AuthBlock{ region: region, profile: profile, } - return getProviderConfig(servicesUrl, "", authBlocks) + return getProviderConfig(serviceRegistryUrl, "", authBlocks) } func getAwsProfileProviderConfigFromEnvVars() string { - return getAwsProfileProviderConfig(os.Getenv("MCMA_AWS_SERVICES_URL"), os.Getenv("MCMA_AWS_REGION"), os.Getenv("MCMA_AWS_PROFILE")) + return getAwsProfileProviderConfig(os.Getenv("MCMA_AWS_SERVICE_REGISTRY_URL"), os.Getenv("MCMA_AWS_REGION"), os.Getenv("MCMA_AWS_PROFILE")) } func getKubernetesProviderConfigFromEnvVars() string { - return getProviderConfig(os.Getenv("MCMA_KUBERNETES_SERVICES_URL"), "", nil) + return getProviderConfig(os.Getenv("MCMA_KUBERNETES_SERVICE_REGISTRY_URL"), "", nil) } diff --git a/mcma/resource_job_profile.go b/mcma/resource_job_profile.go index f75683a..f1eb7cd 100644 --- a/mcma/resource_job_profile.go +++ b/mcma/resource_job_profile.go @@ -2,11 +2,12 @@ package mcma import ( "context" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "reflect" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mcmamodel "github.com/ebu/mcma-libraries-go/model" ) diff --git a/mcma/resource_job_profile_test.go b/mcma/resource_job_profile_test.go index 2c6c1bf..632cba5 100644 --- a/mcma/resource_job_profile_test.go +++ b/mcma/resource_job_profile_test.go @@ -2,14 +2,16 @@ package mcma import ( "fmt" - mcmaclient "github.com/ebu/mcma-libraries-go/client" - mcmamodel "github.com/ebu/mcma-libraries-go/model" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "reflect" "testing" "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + mcmaclient "github.com/ebu/mcma-libraries-go/client" + mcmamodel "github.com/ebu/mcma-libraries-go/model" ) func TestAccMcmaJobProfile_basic(t *testing.T) { diff --git a/mcma/resource_mcma_resource.go b/mcma/resource_mcma_resource.go index 4851c63..75eb217 100644 --- a/mcma/resource_mcma_resource.go +++ b/mcma/resource_mcma_resource.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) diff --git a/mcma/resource_mcma_resource_test.go b/mcma/resource_mcma_resource_test.go index d7d5898..00522a8 100644 --- a/mcma/resource_mcma_resource_test.go +++ b/mcma/resource_mcma_resource_test.go @@ -2,12 +2,14 @@ package mcma import ( "fmt" - mcmaclient "github.com/ebu/mcma-libraries-go/client" + "testing" + "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" - "testing" - "time" + + mcmaclient "github.com/ebu/mcma-libraries-go/client" ) func TestAccMcmaResource_basic(t *testing.T) { diff --git a/mcma/resource_service.go b/mcma/resource_service.go index a9e2d23..6509347 100644 --- a/mcma/resource_service.go +++ b/mcma/resource_service.go @@ -2,11 +2,12 @@ package mcma import ( "context" - "github.com/hashicorp/terraform-plugin-sdk/v2/diag" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "reflect" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/diag" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" + mcmamodel "github.com/ebu/mcma-libraries-go/model" ) diff --git a/mcma/resource_service_test.go b/mcma/resource_service_test.go index 2848593..622a0b0 100644 --- a/mcma/resource_service_test.go +++ b/mcma/resource_service_test.go @@ -2,14 +2,16 @@ package mcma import ( "fmt" - mcmaclient "github.com/ebu/mcma-libraries-go/client" - mcmamodel "github.com/ebu/mcma-libraries-go/model" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" - "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" - "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" "reflect" "testing" "time" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" + + mcmaclient "github.com/ebu/mcma-libraries-go/client" + mcmamodel "github.com/ebu/mcma-libraries-go/model" ) func TestAccMcmaService_basic(t *testing.T) {