provider/aws: FIxed the api_gw_domain_name replace operation (#10179)
This commit is contained in:
parent
7297be8e05
commit
4b25837dd0
|
@ -21,43 +21,43 @@ func resourceAwsApiGatewayDomainName() *schema.Resource {
|
||||||
|
|
||||||
Schema: map[string]*schema.Schema{
|
Schema: map[string]*schema.Schema{
|
||||||
|
|
||||||
"certificate_body": &schema.Schema{
|
"certificate_body": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"certificate_chain": &schema.Schema{
|
"certificate_chain": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"certificate_name": &schema.Schema{
|
"certificate_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"certificate_private_key": &schema.Schema{
|
"certificate_private_key": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"domain_name": &schema.Schema{
|
"domain_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Required: true,
|
Required: true,
|
||||||
ForceNew: true,
|
ForceNew: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"cloudfront_domain_name": &schema.Schema{
|
"cloudfront_domain_name": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"certificate_upload_date": &schema.Schema{
|
"certificate_upload_date": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
"cloudfront_zone_id": &schema.Schema{
|
"cloudfront_zone_id": {
|
||||||
Type: schema.TypeString,
|
Type: schema.TypeString,
|
||||||
Computed: true,
|
Computed: true,
|
||||||
},
|
},
|
||||||
|
@ -120,7 +120,7 @@ func resourceAwsApiGatewayDomainNameUpdateOperations(d *schema.ResourceData) []*
|
||||||
if d.HasChange("certificate_body") {
|
if d.HasChange("certificate_body") {
|
||||||
operations = append(operations, &apigateway.PatchOperation{
|
operations = append(operations, &apigateway.PatchOperation{
|
||||||
Op: aws.String("replace"),
|
Op: aws.String("replace"),
|
||||||
Path: aws.String("/certificate_body"),
|
Path: aws.String("/certificateBody"),
|
||||||
Value: aws.String(d.Get("certificate_body").(string)),
|
Value: aws.String(d.Get("certificate_body").(string)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func resourceAwsApiGatewayDomainNameUpdateOperations(d *schema.ResourceData) []*
|
||||||
if d.HasChange("certificate_chain") {
|
if d.HasChange("certificate_chain") {
|
||||||
operations = append(operations, &apigateway.PatchOperation{
|
operations = append(operations, &apigateway.PatchOperation{
|
||||||
Op: aws.String("replace"),
|
Op: aws.String("replace"),
|
||||||
Path: aws.String("/certificate_chain"),
|
Path: aws.String("/certificateChain"),
|
||||||
Value: aws.String(d.Get("certificate_chain").(string)),
|
Value: aws.String(d.Get("certificate_chain").(string)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ func resourceAwsApiGatewayDomainNameUpdateOperations(d *schema.ResourceData) []*
|
||||||
if d.HasChange("certificate_name") {
|
if d.HasChange("certificate_name") {
|
||||||
operations = append(operations, &apigateway.PatchOperation{
|
operations = append(operations, &apigateway.PatchOperation{
|
||||||
Op: aws.String("replace"),
|
Op: aws.String("replace"),
|
||||||
Path: aws.String("/certificate_name"),
|
Path: aws.String("/certificateName"),
|
||||||
Value: aws.String(d.Get("certificate_name").(string)),
|
Value: aws.String(d.Get("certificate_name").(string)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ func resourceAwsApiGatewayDomainNameUpdateOperations(d *schema.ResourceData) []*
|
||||||
if d.HasChange("certificate_private_key") {
|
if d.HasChange("certificate_private_key") {
|
||||||
operations = append(operations, &apigateway.PatchOperation{
|
operations = append(operations, &apigateway.PatchOperation{
|
||||||
Op: aws.String("replace"),
|
Op: aws.String("replace"),
|
||||||
Path: aws.String("/certificate_private_key"),
|
Path: aws.String("/certificatePrivateKey"),
|
||||||
Value: aws.String(d.Get("certificate_private_key").(string)),
|
Value: aws.String(d.Get("certificate_private_key").(string)),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,35 +15,37 @@ func TestAccAWSAPIGatewayDomainName_basic(t *testing.T) {
|
||||||
var conf apigateway.DomainName
|
var conf apigateway.DomainName
|
||||||
|
|
||||||
// Our test cert is for a wildcard on this domain
|
// Our test cert is for a wildcard on this domain
|
||||||
name := fmt.Sprintf("%s.tf-acc.invalid", resource.UniqueId())
|
uniqueId := resource.UniqueId()
|
||||||
|
name := fmt.Sprintf("%s.tf-acc.invalid", uniqueId)
|
||||||
|
nameModified := fmt.Sprintf("test-acc.%s.tf-acc.invalid", uniqueId)
|
||||||
|
|
||||||
resource.Test(t, resource.TestCase{
|
resource.Test(t, resource.TestCase{
|
||||||
PreCheck: func() { testAccPreCheck(t) },
|
PreCheck: func() { testAccPreCheck(t) },
|
||||||
Providers: testAccProviders,
|
Providers: testAccProviders,
|
||||||
CheckDestroy: testAccCheckAWSAPIGatewayDomainNameDestroy,
|
CheckDestroy: testAccCheckAWSAPIGatewayDomainNameDestroy,
|
||||||
Steps: []resource.TestStep{
|
Steps: []resource.TestStep{
|
||||||
resource.TestStep{
|
{
|
||||||
Config: testAccAWSAPIGatewayDomainNameConfigCreate(name),
|
Config: testAccAWSAPIGatewayDomainNameConfigCreate(name),
|
||||||
Check: resource.ComposeTestCheckFunc(
|
Check: resource.ComposeTestCheckFunc(
|
||||||
testAccCheckAWSAPIGatewayDomainNameExists("aws_api_gateway_domain_name.test", &conf),
|
testAccCheckAWSAPIGatewayDomainNameExists("aws_api_gateway_domain_name.test", &conf),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_body", testAccAWSAPIGatewayCertBody),
|
||||||
"aws_api_gateway_domain_name.test", "certificate_body", testAccAWSAPIGatewayCertBody,
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_chain", testAccAWSAPIGatewayCertChain),
|
||||||
),
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name"),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_private_key", testAccAWSAPIGatewayCertPrivateKey),
|
||||||
"aws_api_gateway_domain_name.test", "certificate_chain", testAccAWSAPIGatewayCertChain,
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "domain_name", name),
|
||||||
),
|
resource.TestCheckResourceAttrSet("aws_api_gateway_domain_name.test", "certificate_upload_date"),
|
||||||
resource.TestCheckResourceAttr(
|
),
|
||||||
"aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name",
|
},
|
||||||
),
|
{
|
||||||
resource.TestCheckResourceAttr(
|
Config: testAccAWSAPIGatewayDomainNameConfigUpdate(name),
|
||||||
"aws_api_gateway_domain_name.test", "certificate_private_key", testAccAWSAPIGatewayCertPrivateKey,
|
Check: resource.ComposeTestCheckFunc(
|
||||||
),
|
testAccCheckAWSAPIGatewayDomainNameExists("aws_api_gateway_domain_name.test", &conf),
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_body", testAccAWSAPIGatewayCertBody),
|
||||||
"aws_api_gateway_domain_name.test", "domain_name", name,
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_chain", testAccAWSAPIGatewayCertChain),
|
||||||
),
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_name", "tf-acc-apigateway-domain-name"),
|
||||||
resource.TestCheckResourceAttrSet(
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "certificate_private_key", testAccAWSAPIGatewayCertPrivateKey),
|
||||||
"aws_api_gateway_domain_name.test", "certificate_upload_date",
|
resource.TestCheckResourceAttr("aws_api_gateway_domain_name.test", "domain_name", nameModified),
|
||||||
),
|
resource.TestCheckResourceAttrSet("aws_api_gateway_domain_name.test", "certificate_upload_date"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -205,10 +207,28 @@ func testAccAWSAPIGatewayDomainNameConfigCreate(name string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "aws_api_gateway_domain_name" "test" {
|
resource "aws_api_gateway_domain_name" "test" {
|
||||||
domain_name = "%s"
|
domain_name = "%s"
|
||||||
certificate_body = "%v"
|
certificate_body = <<EOF
|
||||||
certificate_chain = "%v"
|
%vEOF
|
||||||
|
certificate_chain = <<EOF
|
||||||
|
%vEOF
|
||||||
certificate_name = "tf-acc-apigateway-domain-name"
|
certificate_name = "tf-acc-apigateway-domain-name"
|
||||||
certificate_private_key = "%v"
|
certificate_private_key = <<EOF
|
||||||
|
%vEOF
|
||||||
|
}
|
||||||
|
`, name, testAccAWSAPIGatewayCertBody, testAccAWSAPIGatewayCertChain, testAccAWSAPIGatewayCertPrivateKey)
|
||||||
|
}
|
||||||
|
|
||||||
|
func testAccAWSAPIGatewayDomainNameConfigUpdate(name string) string {
|
||||||
|
return fmt.Sprintf(`
|
||||||
|
resource "aws_api_gateway_domain_name" "test" {
|
||||||
|
domain_name = "test-acc.%s"
|
||||||
|
certificate_body = <<EOF
|
||||||
|
%vEOF
|
||||||
|
certificate_chain = <<EOF
|
||||||
|
%vEOF
|
||||||
|
certificate_name = "tf-acc-apigateway-domain-name"
|
||||||
|
certificate_private_key = <<EOF
|
||||||
|
%vEOF
|
||||||
}
|
}
|
||||||
`, name, testAccAWSAPIGatewayCertBody, testAccAWSAPIGatewayCertChain, testAccAWSAPIGatewayCertPrivateKey)
|
`, name, testAccAWSAPIGatewayCertBody, testAccAWSAPIGatewayCertChain, testAccAWSAPIGatewayCertPrivateKey)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue