-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
terraform-boot - Enable async processing of deploy and destroy API me…
…thods
- Loading branch information
1 parent
bf23036
commit 2fc0dc8
Showing
17 changed files
with
680 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/eclipse/xpanse/terraform/boot/config/TerraformVersionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
* | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.config; | ||
|
||
import org.eclipse.xpanse.terraform.boot.models.enums.Csp; | ||
import org.eclipse.xpanse.terraform.boot.models.exceptions.TerraformExecutorException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Version configuration classes for Terraform cloud providers. | ||
*/ | ||
@Configuration | ||
public class TerraformVersionProvider { | ||
|
||
@Value("${terraform.provider.huaweicloud.version}") | ||
private String terraformHuaweiCloudVersion; | ||
|
||
@Value("${terraform.provider.flexibleengine.version}") | ||
private String terraformFlexibleEngineVersion; | ||
|
||
@Value("${terraform.provider.openstack.version}") | ||
private String terraformOpenStackVersion; | ||
|
||
@Value("${terraform.provider.aws.version}") | ||
private String terraformAwsCloudVersion; | ||
|
||
@Value("${terraform.provider.scs.version}") | ||
private String terraformScsVersion; | ||
|
||
/** | ||
* get the Terraform version corresponding to the cloud provider. | ||
*/ | ||
public String getTerraformVersionByCsp(Csp csp) { | ||
if (csp == Csp.HUAWEI) { | ||
return terraformHuaweiCloudVersion; | ||
} else if (csp == Csp.FLEXIBLE_ENGINE) { | ||
return terraformFlexibleEngineVersion; | ||
} else if (csp == Csp.OPENSTACK) { | ||
return terraformOpenStackVersion; | ||
} else if (csp == Csp.AWS) { | ||
return terraformAwsCloudVersion; | ||
} else if (csp == Csp.SCS) { | ||
return terraformScsVersion; | ||
} else { | ||
throw new TerraformExecutorException("Get Terraform Version,Csp does not exist"); | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/org/eclipse/xpanse/terraform/boot/models/enums/Csp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.models.enums; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** | ||
* Cloud service providers. | ||
*/ | ||
public enum Csp { | ||
HUAWEI("huawei"), | ||
FLEXIBLE_ENGINE("flexibleEngine"), | ||
OPENSTACK("openstack"), | ||
ALICLOUD("alicloud"), | ||
AWS("aws"), | ||
AZURE("azure"), | ||
GOOGLE("google"), | ||
SCS("scs"); | ||
|
||
private final String value; | ||
|
||
Csp(String value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* For CSP serialize. | ||
*/ | ||
@JsonCreator | ||
public static Csp getByValue(String name) { | ||
for (Csp csp : values()) { | ||
if (StringUtils.equalsIgnoreCase(csp.value, name)) { | ||
return csp; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* For CSP deserialize. | ||
*/ | ||
@JsonValue | ||
public String toValue() { | ||
return this.value; | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/org/eclipse/xpanse/terraform/boot/models/enums/TerraformProviders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
* | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.models.enums; | ||
|
||
import java.util.Objects; | ||
import org.eclipse.xpanse.terraform.boot.models.exceptions.TerraformProviderNotFoundException; | ||
import org.eclipse.xpanse.terraform.boot.models.providers.Aws; | ||
import org.eclipse.xpanse.terraform.boot.models.providers.FlexibleEngine; | ||
import org.eclipse.xpanse.terraform.boot.models.providers.Huawei; | ||
import org.eclipse.xpanse.terraform.boot.models.providers.Openstack; | ||
import org.eclipse.xpanse.terraform.boot.models.providers.Provider; | ||
import org.eclipse.xpanse.terraform.boot.models.providers.Scs; | ||
|
||
/** | ||
* Terraform providers. | ||
*/ | ||
public enum TerraformProviders { | ||
AWS(Csp.AWS, new Aws()), | ||
HUAWEI(Csp.HUAWEI, new Huawei()), | ||
FLEXIBLE_ENGINE(Csp.FLEXIBLE_ENGINE, new FlexibleEngine()), | ||
OPENSTACK(Csp.OPENSTACK, new Openstack()), | ||
SCS(Csp.SCS, new Scs()); | ||
|
||
final Csp csp; | ||
|
||
final Provider provider; | ||
|
||
/** | ||
* Constructor for TerraformProviders. | ||
* | ||
* @param csp the cloud service provider. | ||
* @param provider the provider for the CSP. | ||
*/ | ||
TerraformProviders(Csp csp, Provider provider) { | ||
this.csp = csp; | ||
this.provider = provider; | ||
} | ||
|
||
/** | ||
* Get the provider by the Csp. | ||
* | ||
* @param csp the cloud service provider. | ||
*/ | ||
public static Provider getProvider(Csp csp) { | ||
for (TerraformProviders provider : values()) { | ||
if (Objects.equals(csp, provider.csp)) { | ||
return provider.provider; | ||
} | ||
} | ||
|
||
throw new TerraformProviderNotFoundException("Cannot find provider " + csp + "."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...g/eclipse/xpanse/terraform/boot/models/exceptions/TerraformProviderNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.models.exceptions; | ||
|
||
/** | ||
* Exception thrown when Terraform Provider configuration for the requested Csp is not available. | ||
*/ | ||
public class TerraformProviderNotFoundException extends RuntimeException { | ||
public TerraformProviderNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
|
||
} | ||
|
44 changes: 44 additions & 0 deletions
44
src/main/java/org/eclipse/xpanse/terraform/boot/models/providers/Aws.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
* | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.models.providers; | ||
|
||
|
||
import org.eclipse.xpanse.terraform.boot.models.enums.Csp; | ||
|
||
/** | ||
* Terraform provider information for AWS. | ||
*/ | ||
public class Aws implements Provider { | ||
|
||
public static final String PROVIDER = """ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "%s" | ||
} | ||
} | ||
} | ||
provider "aws" { | ||
region = "%s" | ||
} | ||
"""; | ||
|
||
@Override | ||
public String getProvider(String version, String region) { | ||
return String.format(PROVIDER, version, region); | ||
} | ||
|
||
@Override | ||
public Csp getCsp() { | ||
return Csp.AWS; | ||
} | ||
|
||
} | ||
|
||
|
41 changes: 41 additions & 0 deletions
41
src/main/java/org/eclipse/xpanse/terraform/boot/models/providers/FlexibleEngine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
* | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.models.providers; | ||
|
||
import org.eclipse.xpanse.terraform.boot.models.enums.Csp; | ||
|
||
/** | ||
* Terraform provider information for Huawei. | ||
*/ | ||
public class FlexibleEngine implements Provider { | ||
|
||
public static final String PROVIDER = """ | ||
terraform { | ||
required_providers { | ||
flexibleengine = { | ||
source = "FlexibleEngineCloud/flexibleengine" | ||
version = "%s" | ||
} | ||
} | ||
} | ||
provider "flexibleengine" { | ||
region = "%s" | ||
} | ||
"""; | ||
|
||
@Override | ||
public String getProvider(String version, String region) { | ||
return String.format(PROVIDER, version, region); | ||
} | ||
|
||
@Override | ||
public Csp getCsp() { | ||
return Csp.FLEXIBLE_ENGINE; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/org/eclipse/xpanse/terraform/boot/models/providers/Huawei.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
* | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.models.providers; | ||
|
||
import org.eclipse.xpanse.terraform.boot.models.enums.Csp; | ||
|
||
/** | ||
* Terraform provider information for Huawei. | ||
*/ | ||
public class Huawei implements Provider { | ||
|
||
public static final String PROVIDER = """ | ||
terraform { | ||
required_providers { | ||
huaweicloud = { | ||
source = "huaweicloud/huaweicloud" | ||
version = "%s" | ||
} | ||
} | ||
} | ||
provider "huaweicloud" { | ||
region = "%s" | ||
} | ||
"""; | ||
|
||
@Override | ||
public String getProvider(String version, String region) { | ||
return String.format(PROVIDER, version, region); | ||
} | ||
|
||
@Override | ||
public Csp getCsp() { | ||
return Csp.HUAWEI; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/org/eclipse/xpanse/terraform/boot/models/providers/Openstack.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* SPDX-FileCopyrightText: Huawei Inc. | ||
*/ | ||
|
||
package org.eclipse.xpanse.terraform.boot.models.providers; | ||
|
||
import org.eclipse.xpanse.terraform.boot.models.enums.Csp; | ||
|
||
/** | ||
* Terraform provider information for Openstack. | ||
*/ | ||
public class Openstack implements Provider { | ||
|
||
public static final String PROVIDER = """ | ||
terraform { | ||
required_providers { | ||
openstack = { | ||
source = "terraform-provider-openstack/openstack" | ||
version = "%s" | ||
} | ||
} | ||
} | ||
provider "openstack" { | ||
region = "%s" | ||
} | ||
"""; | ||
|
||
@Override | ||
public String getProvider(String version, String region) { | ||
return String.format(PROVIDER, version, region); | ||
} | ||
|
||
@Override | ||
public Csp getCsp() { | ||
return Csp.OPENSTACK; | ||
} | ||
|
||
} |
Oops, something went wrong.