From c70c54bd7eba05c7195b4ba11194407ee32ac6ad Mon Sep 17 00:00:00 2001 From: He Guimin Date: Mon, 5 Jun 2017 05:06:58 +0800 Subject: [PATCH] fix access_key NOT FOUND bug and nat_gateway diff bug (#15050) --- builtin/providers/alicloud/provider.go | 23 ++++++++++++++++--- .../alicloud/resource_alicloud_nat_gateway.go | 1 + 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/builtin/providers/alicloud/provider.go b/builtin/providers/alicloud/provider.go index fe3613014..d7f92da64 100644 --- a/builtin/providers/alicloud/provider.go +++ b/builtin/providers/alicloud/provider.go @@ -5,6 +5,7 @@ import ( "github.com/hashicorp/terraform/helper/mutexkv" "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" + "os" ) // Provider returns a schema.Provider for alicloud @@ -67,10 +68,26 @@ func Provider() terraform.ResourceProvider { } func providerConfigure(d *schema.ResourceData) (interface{}, error) { + accesskey, ok := d.GetOk("access_key") + if !ok { + accesskey = os.Getenv("ALICLOUD_ACCESS_KEY") + } + secretkey, ok := d.GetOk("secret_key") + if !ok { + secretkey = os.Getenv("ALICLOUD_SECRET_KEY") + } + region, ok := d.GetOk("region") + if !ok { + region = os.Getenv("ALICLOUD_REGION") + if region == "" { + region = DEFAULT_REGION + } + } + config := Config{ - AccessKey: d.Get("access_key").(string), - SecretKey: d.Get("secret_key").(string), - Region: common.Region(d.Get("region").(string)), + AccessKey: accesskey.(string), + SecretKey: secretkey.(string), + Region: common.Region(region.(string)), } client, err := config.Client() diff --git a/builtin/providers/alicloud/resource_alicloud_nat_gateway.go b/builtin/providers/alicloud/resource_alicloud_nat_gateway.go index 7851e661c..b078ee0a2 100644 --- a/builtin/providers/alicloud/resource_alicloud_nat_gateway.go +++ b/builtin/providers/alicloud/resource_alicloud_nat_gateway.go @@ -70,6 +70,7 @@ func resourceAliyunNatGateway() *schema.Resource { "zone": &schema.Schema{ Type: schema.TypeString, Optional: true, + Computed: true, }, "public_ip_addresses": &schema.Schema{ Type: schema.TypeString,