-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the feature of resource-level region[1/2] #616
Conversation
@qzyu92 Thanks for your effort. I suggest you can also update the docs along with the patch. |
projectID, ok := RegionProjectIDMap.Load(region) | ||
if !ok { | ||
// Not find in the map, then try to query and store. | ||
err := c.loadUserProjects(client, region) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as resources are created in parallel, we must have a mutex here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'm working on it. Will fix it in the following patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a mutex
around here, and there is no more duplicate http request in my local test, please review about it.
huaweicloud/config.go
Outdated
Name: region, | ||
} | ||
sc := new(golangsdk.ServiceClient) | ||
sc.Endpoint = fmt.Sprintf("https://iam.%s/v3/", c.Cloud) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to set Endpoint by c.IdentityEndpoint
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, and I have modified about this.
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
ForceNew: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForceNew
is useless in data source
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got, I will fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix compeleted.
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ForceNew
must be true when region
has changed for resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it, I will push a patch and fix this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix compeleted.
|
@ShiChangkuo The docs have been modified, and will push another request for it. |
@ShiChangkuo The modification of docs refs #622 |
resource "huaweicloud_vpc" "test2" { | ||
name = "%s" | ||
region = "%s" | ||
cidr = "192.168.0.0/16" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please format the resource with HCL style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed this by modifing it’s indentation into two blanks.
huaweicloud/config.go
Outdated
} | ||
|
||
func (c *Config) newServiceClientByName(client *golangsdk.ProviderClient, catalog ServiceCatalog, region string) (*golangsdk.ServiceClient, error) { | ||
if catalog.Name == "" || catalog.Version == "" { | ||
return nil, fmt.Errorf("must specify the service name and api version") | ||
} | ||
|
||
// Resource-level region only supports AK/SK authentication. | ||
if region != c.Region && (c.AccessKey == "" || c.SecretKey == "") { | ||
return nil, fmt.Errorf("Resource-level region must be same as Provider-level region when not AK/SK authentication if Resource-level region setted") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/setted/set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Resource-level region must be same as Provider-level region when using non AK/SK authentication" seems better :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, that seems better truly.
Add region to datasource Add region to resource Add resource-level region test case for `resource_huaweicloud_vpc`
Intro
Based on provider-level region, this commit add an optional param named
region
in each resource and datasource.User can manage cloud-resources in different regions just in a single
tf
file by confingregion
param in resource or datasource.But, plase read the following attentions:
region
in resource or datasource but authed by user-name/pwd or token, then the resource-level region must be the same with the provider-level region. Or you will get an error.Test
Have commited a test case in
resource_huaweicloud_vpc_test.go
, namedTestAccVpcV1_WithCustomRegion
, and there is the test script and result.